1
0
mirror of https://git.sr.ht/~sircmpwn/gmni synced 2024-11-23 09:02:04 +01:00

Fix segfault on connection refused

This commit is contained in:
Drew DeVault 2020-09-26 16:59:06 -04:00
parent 0eaf9cc109
commit b298fadb21

@ -94,8 +94,7 @@ gemini_request(const char *url, struct gemini_options *options,
{ {
assert(url); assert(url);
assert(resp); assert(resp);
resp->meta = NULL; memset(resp, 0, sizeof(*resp));
resp->bio = NULL;
if (strlen(url) > 1024) { if (strlen(url) > 1024) {
return GEMINI_ERR_INVALID_URL; return GEMINI_ERR_INVALID_URL;
} }
@ -206,6 +205,7 @@ gemini_request(const char *url, struct gemini_options *options,
} }
if (r < 3 || strcmp(&buf[r - 2], "\r\n") != 0) { if (r < 3 || strcmp(&buf[r - 2], "\r\n") != 0) {
fprintf(stderr, "invalid line %d '%s'\n", r, buf);
res = GEMINI_ERR_PROTOCOL; res = GEMINI_ERR_PROTOCOL;
goto cleanup; goto cleanup;
} }
@ -213,6 +213,7 @@ gemini_request(const char *url, struct gemini_options *options,
char *endptr; char *endptr;
resp->status = (enum gemini_status)strtol(buf, &endptr, 10); resp->status = (enum gemini_status)strtol(buf, &endptr, 10);
if (*endptr != ' ' || resp->status < 10 || resp->status >= 70) { if (*endptr != ' ' || resp->status < 10 || resp->status >= 70) {
fprintf(stderr, "invalid status\n");
res = GEMINI_ERR_PROTOCOL; res = GEMINI_ERR_PROTOCOL;
goto cleanup; goto cleanup;
} }