mirror of
https://github.com/emikulic/darkhttpd.git
synced 2023-08-10 21:13:08 +03:00
. Add TODO reminders.
. Optimize string reassembly in make_safe_uri().
This commit is contained in:
parent
8a05f349d8
commit
e70a830c2c
@ -22,6 +22,8 @@
|
|||||||
* x Detect Content-Type from a list of content types.
|
* x Detect Content-Type from a list of content types.
|
||||||
* x Log Referer, User-Agent.
|
* x Log Referer, User-Agent.
|
||||||
* x Ensure URIs requested are safe.
|
* x Ensure URIs requested are safe.
|
||||||
|
* . Is expand_tilde() even needed?
|
||||||
|
* . Import new LIST_macros, use FOREACH
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef __linux
|
#ifdef __linux
|
||||||
@ -382,17 +384,26 @@ static char *make_safe_uri(const char *uri)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* reassemble */
|
/* reassemble */
|
||||||
|
size_t pos = 0;
|
||||||
out = xmalloc(urilen+1); /* it won't expand */
|
out = xmalloc(urilen+1); /* it won't expand */
|
||||||
out[0] = '\0';
|
|
||||||
|
|
||||||
for (i=0; i<reasm; i++)
|
for (i=0; i<reasm; i++)
|
||||||
{
|
{
|
||||||
strcat(out, "/");
|
size_t delta = strlen(reassembly[i]);
|
||||||
strcat(out, reassembly[i]);
|
|
||||||
|
assert(pos <= urilen);
|
||||||
|
out[pos++] = '/';
|
||||||
|
|
||||||
|
assert(pos+delta <= urilen);
|
||||||
|
memcpy(out+pos, reassembly[i], delta);
|
||||||
|
pos += delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uri[urilen-1] == '/') strcat(out, "/");
|
if (uri[urilen-1] == '/') out[pos++] = '/';
|
||||||
|
assert(pos <= urilen);
|
||||||
|
out[pos] = '\0';
|
||||||
|
|
||||||
|
if (pos != urilen)
|
||||||
out = xrealloc(out, strlen(out)+1); /* shorten buffer */
|
out = xrealloc(out, strlen(out)+1); /* shorten buffer */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user