-
Notifications
You must be signed in to change notification settings - Fork 24
fix several latent bugs across parsing, OOM handling, and option validation #234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -234,7 +234,11 @@ writer_init(long output_limit, ps_user_t ps_user, bool meta_query) { | |
| exec_sort(p1, p2); | ||
| close(p1[0]); | ||
| writer->sort_stdin = fdopen(p1[1], "w"); | ||
| if (writer->sort_stdin == NULL) | ||
| my_panic(true, "fdopen"); | ||
| writer->sort_stdout = fdopen(p2[0], "r"); | ||
| if (writer->sort_stdout == NULL) | ||
| my_panic(true, "fdopen"); | ||
| close(p2[1]); | ||
| } | ||
|
|
||
|
|
@@ -278,6 +282,7 @@ writer_func(char *ptr, size_t size, size_t nmemb, void *blob) { | |
| writer_t writer = query->writer; | ||
| qparam_ct qp = &query->qp; | ||
| size_t bytes = size * nmemb; | ||
| char *x; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This variable should be factored out. Where it is used, a more straightforward: would be clearer. |
||
| char *nl; | ||
|
|
||
| DEBUG(3, true, "writer_func(%d, %d): %d\n", | ||
|
|
@@ -306,7 +311,15 @@ writer_func(char *ptr, size_t size, size_t nmemb, void *blob) { | |
| } | ||
| } | ||
|
|
||
| fetch->buf = realloc(fetch->buf, fetch->len + bytes); | ||
| if (fetch->len + bytes > MAX_FETCH_BUF) { | ||
| printf("?? very large response\n"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Failure of this check should:
|
||
| return 0; | ||
| } | ||
| x = realloc(fetch->buf, fetch->len + bytes); | ||
| if (x == NULL) | ||
| my_panic(true, "realloc"); | ||
| fetch->buf = x; | ||
| x = NULL; | ||
| memcpy(fetch->buf + fetch->len, ptr, bytes); | ||
| fetch->len += bytes; | ||
|
|
||
|
|
@@ -365,8 +378,11 @@ writer_func(char *ptr, size_t size, size_t nmemb, void *blob) { | |
| fetch->stopped = true; | ||
| } else if (writer->meta_query) { | ||
| /* concatenate this fragment (incl \n) to ps_buf. */ | ||
| writer->ps_buf = realloc(writer->ps_buf, | ||
| writer->ps_len + pre_len + 1); | ||
| x = realloc(writer->ps_buf, writer->ps_len + pre_len + 1); | ||
| if (x == NULL) | ||
| my_panic(true, "realloc"); | ||
| writer->ps_buf = x; | ||
| x = NULL; | ||
| memcpy(writer->ps_buf + writer->ps_len, | ||
| fetch->buf, pre_len + 1); | ||
| writer->ps_len += pre_len + 1; | ||
|
|
@@ -431,11 +447,13 @@ last_fetch(fetch_t fetch) { | |
| writer->active = NULL; | ||
| } | ||
| assert(writer->ps_buf == NULL && writer->ps_len == 0); | ||
| writer->ps_len = (size_t) | ||
| asprintf(&writer->ps_buf, "-- %s (%s)\n", | ||
| int x = asprintf(&writer->ps_buf, "-- %s (%s)\n", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we're retaining the return value of |
||
| or_else(query->status, status_noerror), | ||
| or_else(query->message, | ||
| or_else(fetch->saf_msg, "no error"))); | ||
| if (x < 0) | ||
| my_panic(true, "asprintf"); | ||
| writer->ps_len = (size_t) x; | ||
| if (npaused > 0) { | ||
| query_t unpause; | ||
| fetch_t ufetch; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not immediately clear from context whether this is a tunable resource limit or a "sanity check" guard against possible malformed output from the API server.
I believe it's the latter (and sufficient), based on the limited number of RRs which can fit in a 64KiB DNS message. This might be worth noting in a comment so this isn't confused for a tunable later.