* src/cookies.c (cookie_handle_set_cookie): Remove use of alloca

This commit is contained in:
Tim Rühsen 2020-02-14 12:32:22 +01:00
parent 36ccb62e92
commit f071030659

View File

@ -750,11 +750,20 @@ cookie_handle_set_cookie (struct cookie_jar *jar,
{ {
struct cookie *cookie; struct cookie *cookie;
cookies_now = time (NULL); cookies_now = time (NULL);
char buf[1024], *tmp;
size_t pathlen = strlen(path);
/* Wget's paths don't begin with '/' (blame rfc1808), but cookie /* Wget's paths don't begin with '/' (blame rfc1808), but cookie
usage assumes /-prefixed paths. Until the rest of Wget is fixed, usage assumes /-prefixed paths. Until the rest of Wget is fixed,
simply prepend slash to PATH. */ simply prepend slash to PATH. */
PREPEND_SLASH (path); if (pathlen < sizeof (buf) - 1)
tmp = buf;
else
tmp = xmalloc (pathlen + 2);
*tmp = '/';
memcpy (tmp + 1, path, pathlen + 1);
path = tmp;
cookie = parse_set_cookie (set_cookie, false); cookie = parse_set_cookie (set_cookie, false);
if (!cookie) if (!cookie)
@ -816,11 +825,15 @@ cookie_handle_set_cookie (struct cookie_jar *jar,
} }
store_cookie (jar, cookie); store_cookie (jar, cookie);
if (tmp != buf)
xfree (tmp);
return; return;
out: out:
if (cookie) if (cookie)
delete_cookie (cookie); delete_cookie (cookie);
if (tmp != buf)
xfree (tmp);
} }
/* Support for sending out cookies in HTTP requests, based on /* Support for sending out cookies in HTTP requests, based on