mirror of
https://github.com/emikulic/darkhttpd.git
synced 2023-08-10 21:13:08 +03:00
Don't use strlen() in urlencode_filename()
Also move safe_url variable into for loop that uses it.
This commit is contained in:
parent
ca6a07f714
commit
8eec408691
@ -1715,11 +1715,9 @@ static int needs_urlencoding(unsigned char c)
|
|||||||
static void urlencode_filename(unsigned char *name, unsigned char *safe_url)
|
static void urlencode_filename(unsigned char *name, unsigned char *safe_url)
|
||||||
{
|
{
|
||||||
const static char hex[] = "0123456789ABCDEF";
|
const static char hex[] = "0123456789ABCDEF";
|
||||||
int i, j, len;
|
int i, j;
|
||||||
|
|
||||||
len = strlen(name);
|
for (i = j = 0; name[i] != '\0'; i++)
|
||||||
|
|
||||||
for (i=j=0; i<len; i++)
|
|
||||||
{
|
{
|
||||||
if (needs_urlencoding(name[i]))
|
if (needs_urlencoding(name[i]))
|
||||||
{
|
{
|
||||||
@ -1746,10 +1744,6 @@ static void generate_dir_listing(struct connection *conn, const char *path)
|
|||||||
int i;
|
int i;
|
||||||
struct apbuf *listing = make_apbuf();
|
struct apbuf *listing = make_apbuf();
|
||||||
|
|
||||||
/* If a filename is made up of entirely unsafe chars,
|
|
||||||
the url would be three times its original length. */
|
|
||||||
char safe_url[MAXNAMLEN*3];
|
|
||||||
|
|
||||||
listsize = make_sorted_dirlist(path, &list);
|
listsize = make_sorted_dirlist(path, &list);
|
||||||
if (listsize == -1)
|
if (listsize == -1)
|
||||||
{
|
{
|
||||||
@ -1775,6 +1769,11 @@ static void generate_dir_listing(struct connection *conn, const char *path)
|
|||||||
|
|
||||||
for (i=0; i<listsize; i++)
|
for (i=0; i<listsize; i++)
|
||||||
{
|
{
|
||||||
|
/* If a filename is made up of entirely unsafe chars,
|
||||||
|
* the url would be three times its original length.
|
||||||
|
*/
|
||||||
|
char safe_url[MAXNAMLEN*3];
|
||||||
|
|
||||||
urlencode_filename(list[i]->name, safe_url);
|
urlencode_filename(list[i]->name, safe_url);
|
||||||
|
|
||||||
append(listing, "<a href=\"");
|
append(listing, "<a href=\"");
|
||||||
|
Loading…
Reference in New Issue
Block a user