mirror of
https://github.com/mirror/wget.git
synced 2025-01-31 23:00:38 +08:00
* src/cookies.c (cookie_header): Remove use of alloca
This commit is contained in:
parent
f071030659
commit
d61d82c43c
@ -1071,9 +1071,9 @@ cookie_header (struct cookie_jar *jar, const char *host,
|
|||||||
struct cookie *cookie;
|
struct cookie *cookie;
|
||||||
struct weighed_cookie *outgoing;
|
struct weighed_cookie *outgoing;
|
||||||
size_t count, i, ocnt;
|
size_t count, i, ocnt;
|
||||||
char *result;
|
char *result = NULL;
|
||||||
int result_size, pos;
|
int result_size, pos;
|
||||||
PREPEND_SLASH (path); /* see cookie_handle_set_cookie */
|
char pathbuf[1024];
|
||||||
|
|
||||||
/* First, find the cookie chains whose domains match HOST. */
|
/* First, find the cookie chains whose domains match HOST. */
|
||||||
|
|
||||||
@ -1087,6 +1087,23 @@ cookie_header (struct cookie_jar *jar, const char *host,
|
|||||||
if (chain_count <= 0)
|
if (chain_count <= 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
/* Wget's paths don't begin with '/' (blame rfc1808), but cookie
|
||||||
|
usage assumes /-prefixed paths. Until the rest of Wget is fixed,
|
||||||
|
simply prepend slash to PATH. */
|
||||||
|
{
|
||||||
|
char *tmp;
|
||||||
|
size_t pathlen = strlen(path);
|
||||||
|
|
||||||
|
if (pathlen < sizeof (pathbuf) - 1)
|
||||||
|
tmp = pathbuf;
|
||||||
|
else
|
||||||
|
tmp = xmalloc (pathlen + 2);
|
||||||
|
|
||||||
|
*tmp = '/';
|
||||||
|
memcpy (tmp + 1, path, pathlen + 1);
|
||||||
|
path = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
cookies_now = time (NULL);
|
cookies_now = time (NULL);
|
||||||
|
|
||||||
/* Now extract from the chains those cookies that match our host
|
/* Now extract from the chains those cookies that match our host
|
||||||
@ -1100,11 +1117,11 @@ cookie_header (struct cookie_jar *jar, const char *host,
|
|||||||
if (cookie_matches_url (cookie, host, port, path, secflag, NULL))
|
if (cookie_matches_url (cookie, host, port, path, secflag, NULL))
|
||||||
++count;
|
++count;
|
||||||
if (!count)
|
if (!count)
|
||||||
return NULL; /* no cookies matched */
|
goto out; /* no cookies matched */
|
||||||
|
|
||||||
/* Allocate the array. */
|
/* Allocate the array. */
|
||||||
if (count > SIZE_MAX / sizeof (struct weighed_cookie))
|
if (count > SIZE_MAX / sizeof (struct weighed_cookie))
|
||||||
return NULL; /* unable to process so many cookies */
|
goto out; /* unable to process so many cookies */
|
||||||
outgoing = xmalloc (count * sizeof (struct weighed_cookie));
|
outgoing = xmalloc (count * sizeof (struct weighed_cookie));
|
||||||
|
|
||||||
/* Fill the array with all the matching cookies from the chains that
|
/* Fill the array with all the matching cookies from the chains that
|
||||||
@ -1167,7 +1184,12 @@ cookie_header (struct cookie_jar *jar, const char *host,
|
|||||||
result[pos++] = '\0';
|
result[pos++] = '\0';
|
||||||
xfree (outgoing);
|
xfree (outgoing);
|
||||||
assert (pos == result_size);
|
assert (pos == result_size);
|
||||||
return result;
|
|
||||||
|
out:
|
||||||
|
if (path != pathbuf)
|
||||||
|
xfree (path);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Support for loading and saving cookies. The format used for
|
/* Support for loading and saving cookies. The format used for
|
||||||
|
Loading…
Reference in New Issue
Block a user