Skip to content

Commit

Permalink
Fixed issues found by Coverity Scan (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
ysyrota authored Oct 22, 2024
1 parent c46ef29 commit 9b26d5a
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions https.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,12 @@ _establish_connection(struct https_request * const req,
if (connected_socket == -1) {
continue;
}
sock_flags = fcntl(connected_socket, F_GETFL, 0);
fcntl(connected_socket, F_SETFL, sock_flags|O_NONBLOCK);
if ((sock_flags = fcntl(connected_socket, F_GETFL, 0)) == -1) {
goto fail;
}
if (fcntl(connected_socket, F_SETFL, sock_flags|O_NONBLOCK) == -1) {
goto fail;
}

if (connect(connected_socket, cur_res->ai_addr, cur_res->ai_addrlen) != 0 &&
errno != EINPROGRESS) {
Expand All @@ -301,12 +305,13 @@ _establish_connection(struct https_request * const req,
}
socket_error = _fd_wait(connected_socket, 10000);
if (socket_error != 1) {
close(connected_socket);
connected_socket = -1;
continue;
goto fail;
}
/* Connected! */
break;
fail:
close(connected_socket);
connected_socket = -1;
}
}
cur_res = NULL;
Expand Down Expand Up @@ -339,8 +344,10 @@ https_init(const char *useragent, const char *cafile, const char *proxy)
BIO *bio;
char *p;

if ((ctx = calloc(1, sizeof(*ctx))) == NULL ||
(ctx->useragent = strdup(useragent)) == NULL) {
if ((ctx = calloc(1, sizeof(*ctx))) == NULL) {
return (HTTPS_ERR_SYSTEM);
}
if ((ctx->useragent = strdup(useragent)) == NULL) {
ctx->errstr = strerror(errno);
return (HTTPS_ERR_SYSTEM);
}
Expand Down

0 comments on commit 9b26d5a

Please sign in to comment.