Browse Source

autoupdater: uclient: add error handling in connection setup

Avoids a segfault when the connection fails early.
pull/183/head
Matthias Schiffer 4 years ago
parent
commit
fc194bc7c8
No known key found for this signature in database GPG Key ID: 16EF3F64CB201D9C
  1. 22
      admin/autoupdater/src/uclient.c

22
admin/autoupdater/src/uclient.c

@ -162,12 +162,18 @@ int get_url(const char *url, void (*read_cb)(struct uclient *cl), void *cb_data,
struct uclient *cl = uclient_new(url, NULL, &cb);
cl->priv = &d;
uclient_set_timeout(cl, TIMEOUT_MSEC);
uclient_connect(cl);
uclient_http_set_request_type(cl, "GET");
uclient_http_reset_headers(cl);
uclient_http_set_header(cl, "User-Agent", user_agent);
uclient_request(cl);
if (uclient_set_timeout(cl, TIMEOUT_MSEC))
goto err;
if (uclient_connect(cl))
goto err;
if (uclient_http_set_request_type(cl, "GET"))
goto err;
if (uclient_http_reset_headers(cl))
goto err;
if (uclient_http_set_header(cl, "User-Agent", user_agent))
goto err;
if (uclient_request(cl))
goto err;
uloop_run();
uclient_free(cl);
@ -175,4 +181,8 @@ int get_url(const char *url, void (*read_cb)(struct uclient *cl), void *cb_data,
return UCLIENT_ERROR_SIZE_MISMATCH;
return d.err_code;
err:
uclient_free(cl);
return UCLIENT_ERROR_CONNECT;
}

Loading…
Cancel
Save