Skip to content

Commit

Permalink
fix segfault when server is not listening
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkr committed Oct 28, 2023
1 parent 53e5068 commit 9a430c6
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions guppy.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static int do_guppy_download(URL *url, GuppySocket *s, char **mime, int ask) {
struct pollfd pfd = {.events = POLLIN};
char *crlf, *end;
ssize_t j = -1;
int len, timeout, i, n, ret = 1;
int len, timeout, i, n;

if ((len = strlen(url->url)) > (int)sizeof(buffer) - 2) goto fail;

Expand All @@ -82,7 +82,7 @@ static int do_guppy_download(URL *url, GuppySocket *s, char **mime, int ask) {

pfd.revents = 0;
if ((n = poll(&pfd, 1, 1000)) == 0) continue;
if (n < 0 || (n > 0 && !(pfd.revents & POLLIN))) return -1;
if (n < 0 || (n > 0 && !(pfd.revents & POLLIN))) goto fail;

while (1) {
j = (j == sizeof(s->chunks) / sizeof(s->chunks[0]) - 1) ? 0 : j + 1;
Expand Down Expand Up @@ -120,7 +120,7 @@ static int do_guppy_download(URL *url, GuppySocket *s, char **mime, int ask) {
fail:
close(s->fd);
s->fd = -1;
return ret;
return -1;
}


Expand Down

0 comments on commit 9a430c6

Please sign in to comment.