mirror of
https://github.com/emikulic/darkhttpd.git
synced 2023-08-10 21:13:08 +03:00
make_safe_uri() improvements.
. Strip out debugging. . Fix (elements == 0) returning an empty string.
This commit is contained in:
parent
b082fa213f
commit
e127c6acda
@ -443,7 +443,6 @@ static char *make_safe_uri(char *uri)
|
|||||||
size_t urilen, i, j, pos;
|
size_t urilen, i, j, pos;
|
||||||
|
|
||||||
assert(uri != NULL);
|
assert(uri != NULL);
|
||||||
debugf("make_safe_uri(`%s')\n", uri);
|
|
||||||
if (uri[0] != '/') return NULL;
|
if (uri[0] != '/') return NULL;
|
||||||
consolidate_slashes(uri);
|
consolidate_slashes(uri);
|
||||||
urilen = strlen(uri);
|
urilen = strlen(uri);
|
||||||
@ -465,15 +464,10 @@ debugf("make_safe_uri(`%s')\n", uri);
|
|||||||
|
|
||||||
/* process uri[i,j) */
|
/* process uri[i,j) */
|
||||||
if ((j == i+1) && (uri[i] == '.'))
|
if ((j == i+1) && (uri[i] == '.'))
|
||||||
{
|
/* "." */;
|
||||||
/* "." */
|
|
||||||
debugf("got `.'\n");
|
|
||||||
}
|
|
||||||
else if ((j == i+2) && (uri[i] == '.') && (uri[i+1] == '.'))
|
else if ((j == i+2) && (uri[i] == '.') && (uri[i+1] == '.'))
|
||||||
{
|
{
|
||||||
/* ".." */
|
/* ".." */
|
||||||
debugf("got `..'\n");
|
|
||||||
|
|
||||||
if (elements == 0)
|
if (elements == 0)
|
||||||
{
|
{
|
||||||
/* unsafe string so free elem[]; all its elements are free at
|
/* unsafe string so free elem[]; all its elements are free at
|
||||||
@ -486,17 +480,9 @@ debugf("make_safe_uri(`%s')\n", uri);
|
|||||||
{
|
{
|
||||||
elements--;
|
elements--;
|
||||||
free(elem[elements]);
|
free(elem[elements]);
|
||||||
elem[elements] = NULL; /* FIXME: not needed */
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else elem[elements++] = split_string(uri, i, j);
|
||||||
{
|
|
||||||
/* token */
|
|
||||||
debugf("splitting [%d,%d): ", i, j);
|
|
||||||
elem[elements++] = split_string(uri, i, j);
|
|
||||||
debugf("splitting [%d,%d): element %d: `%s'\n",
|
|
||||||
i,j,elements,elem[elements-1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
i = j + 1; /* uri[j] is a slash - move along one */
|
i = j + 1; /* uri[j] is a slash - move along one */
|
||||||
}
|
}
|
||||||
@ -518,14 +504,13 @@ debugf("make_safe_uri(`%s')\n", uri);
|
|||||||
}
|
}
|
||||||
free(elem);
|
free(elem);
|
||||||
|
|
||||||
if (uri[urilen-1] == '/') out[pos++] = '/';
|
if ((elements == 0) || (uri[urilen-1] == '/')) out[pos++] = '/';
|
||||||
assert(pos <= urilen);
|
assert(pos <= urilen);
|
||||||
out[pos] = '\0';
|
out[pos] = '\0';
|
||||||
|
|
||||||
if (pos != urilen)
|
/* shorten buffer if necessary */
|
||||||
out = xrealloc(out, strlen(out)+1); /* shorten buffer */
|
if (pos != urilen) out = xrealloc(out, strlen(out)+1);
|
||||||
|
|
||||||
debugf("`%s' -safe-> `%s'\n", uri, out);
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user