On Tue, Apr 9, 2019 at 8:25 AM Alexander Vickberg
<[email protected]> wrote:
>
> This revision has changes from Xabier Onecas comments on v3.
Please retain commit text which explains what this change does, and why.
+typedef struct HTTP_Header {
+ struct HTTP_Header *next;
+ char *name;
+ char *value;
+} HTTP_Header;
[also, tab indent, please - keep style consistent with the rest of the source]
+ cur->name = xasprintf("HTTP_%s", iobuf);
+ cur->value =
xstrdup(skip_whitespace(after_colon));
+
+ /* Insert new header into header list */
+ if (!G.hdr_list) {
+ G.hdr_list = cur;
+ } else {
+ last->next = cur;
+ }
...
+ if (G.hdr_list) {
+ HTTP_Header *cur = G.hdr_list;
+ do {
+ setenv1(cur->name, cur->value);
+ cur = cur->next;
+ } while (cur != G.hdr_list);
+ }
This is too much mallocing. setenv() internally mallocs
and concatenates strings anyway, so just do this:
struct HTTP_Header {
struct HTTP_Header *next;
char varval[1];
}
val = skip_whitespace(after_colon);
cur = xmalloc(sizeof(HTTP_Header) + 7 + strlen(iobuf) + strlen(val));
sprintf(cur->varval, "HTTP_%s=%s", iobuf, val);
...
putenv(cur->varval);
Better yet, do not create a list at all - just alloc and putenv()
variables as they come? [Probably want to do it only if CGI
*will* indeed be called, i.e. precalculate whether you will be
calling send_cgi_and_exit() later.]
+ if ((hdr_len += iobuf_len) > MAX_HTTP_HEADER_SIZE)
This is hard to read, use
+ hdr_len += iobuf_len;
+ if (hdr_len > MAX_HTTP_HEADER_SIZE)
instead.
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox