Skip to content

Commit

Permalink
Fix a crash when fairplay support is not enabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
juhovh committed Aug 24, 2018
1 parent a761c22 commit 096b61a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/lib/fairplay_dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ struct fairplay_s {
fairplay_t *
fairplay_init(logger_t *logger)
{
return NULL;
/* NULL would mean failure so let's use any number */
return (void *) 42;
}

int
Expand Down
24 changes: 18 additions & 6 deletions src/lib/httpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ httpd_destroy(httpd_t *httpd)
}
}

static void
static int
httpd_add_connection(httpd_t *httpd, int fd, unsigned char *local, int local_len, unsigned char *remote, int remote_len)
{
void *user_data;
int i;

for (i=0; i<httpd->max_connections; i++) {
Expand All @@ -110,15 +111,20 @@ httpd_add_connection(httpd_t *httpd, int fd, unsigned char *local, int local_len
if (i == httpd->max_connections) {
/* This code should never be reached, we do not select server_fds when full */
logger_log(httpd->logger, LOGGER_INFO, "Max connections reached");
shutdown(fd, SHUT_RDWR);
closesocket(fd);
return;
return -1;
}

user_data = httpd->callbacks.conn_init(httpd->callbacks.opaque, local, local_len, remote, remote_len);
if (!user_data) {
logger_log(httpd->logger, LOGGER_ERR, "Error initializing HTTP request handler");
return -1;
}

httpd->open_connections++;
httpd->connections[i].socket_fd = fd;
httpd->connections[i].connected = 1;
httpd->connections[i].user_data = httpd->callbacks.conn_init(httpd->callbacks.opaque, local, local_len, remote, remote_len);
httpd->connections[i].user_data = user_data;
return 0;
}

static int
Expand All @@ -142,6 +148,7 @@ httpd_accept_connection(httpd_t *httpd, int server_fd, int is_ipv6)
local_saddrlen = sizeof(local_saddr);
ret = getsockname(fd, (struct sockaddr *)&local_saddr, &local_saddrlen);
if (ret == -1) {
shutdown(fd, SHUT_RDWR);
closesocket(fd);
return 0;
}
Expand All @@ -151,7 +158,12 @@ httpd_accept_connection(httpd_t *httpd, int server_fd, int is_ipv6)
local = netutils_get_address(&local_saddr, &local_len);
remote = netutils_get_address(&remote_saddr, &remote_len);

httpd_add_connection(httpd, fd, local, local_len, remote, remote_len);
ret = httpd_add_connection(httpd, fd, local, local_len, remote, remote_len);
if (ret == -1) {
shutdown(fd, SHUT_RDWR);
closesocket(fd);
return 0;
}
return 1;
}

Expand Down

0 comments on commit 096b61a

Please sign in to comment.