Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow upload link to work for subdirectory of upload folder. #321

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions server/upload-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,27 @@ static gboolean
is_parent_matched (const char *upload_dir,
const char *parent_dir)
{
// parent_dir must be under upload_dir
gboolean ret = TRUE;
char *upload_dir_canon = NULL;
char *parent_dir_canon = NULL;

upload_dir_canon = get_canonical_path (upload_dir);
parent_dir_canon = get_canonical_path (parent_dir);

if (strcmp (upload_dir_canon,parent_dir_canon) != 0) {
size_t upload_dir_len = strlen (upload_dir_canon);
size_t parent_dir_len = strlen (parent_dir_canon);

// If this were real unix path name, care needs to be taken about `..`
// However, I believe `..` is not handled in any special way on the server
// so it can be ignored for now.
if (parent_dir_len < upload_dir_len ||
strncmp (upload_dir_canon, parent_dir_canon, upload_dir_len) != 0) {
// Prefix mismatches
ret = FALSE;
} else if (parent_dir_canon[upload_dir_len] != '/' &&
parent_dir_canon[upload_dir_len] != 0) {
// `0` is exact match and `'/'` is true subdirectory.
// Anything else is forbidden.
ret = FALSE;
}

Expand Down