Skip to content

Commit

Permalink
lib-http: harden payload tests against dodgy filenames
Browse files Browse the repository at this point in the history
Tests use files from readdir() as input, but do no sanitation of the
names, and therefore things like editor temp files can cause havoc
with the HTTP request parser.

The solution is to trap dodgy characters in the filenames, and ignore
those files. Initially, trap HTTP's "unsafe" and "reserved" characters.

Signed-off-by: Phil Carmody <phil@dovecot.fi>
  • Loading branch information
Phil Carmody committed Aug 30, 2018
1 parent 0ad7ac2 commit 9a5b493
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib-http/test-http-payload.c
Expand Up @@ -67,6 +67,7 @@ static unsigned ioloop_nested_depth = 0;
/*
* Test files
*/
static const char unsafe_characters[] = "\"<>#%{}|\\^~[]` ;/?:@=&";

static ARRAY_TYPE(const_string) files;
static pool_t files_pool;
Expand All @@ -92,7 +93,8 @@ static void test_files_read_dir(const char *path)
errno = 0;
if ((dp=readdir(dirp)) == NULL)
break;
if (*dp->d_name == '.')
if (*dp->d_name == '.' ||
dp->d_name[strcspn(dp->d_name, unsafe_characters)] != '\0')
continue;

file = t_abspath_to(dp->d_name, path);
Expand Down

0 comments on commit 9a5b493

Please sign in to comment.