Skip to content

Commit cb4636f

Browse files
committed
improve uwsgi_expand_path() to sanitize input, avoiding stack corruption and potential security issue
1 parent ac03a53 commit cb4636f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

core/utils.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3674,18 +3674,23 @@ void uwsgi_write_pidfile_explicit(char *pidfile_name, pid_t pid) {
36743674
}
36753675

36763676
char *uwsgi_expand_path(char *dir, int dir_len, char *ptr) {
3677-
char src[PATH_MAX + 1];
3678-
memcpy(src, dir, dir_len);
3679-
src[dir_len] = 0;
3677+
if (dir_len > PATH_MAX)
3678+
{
3679+
uwsgi_log("invalid path size: %d (max %d)\n", dir_len, PATH_MAX);
3680+
return NULL;
3681+
}
3682+
char *src = uwsgi_concat2n(dir, dir_len, "", 0);
36803683
char *dst = ptr;
36813684
if (!dst)
36823685
dst = uwsgi_malloc(PATH_MAX + 1);
36833686
if (!realpath(src, dst)) {
36843687
uwsgi_error_realpath(src);
36853688
if (!ptr)
36863689
free(dst);
3690+
free(src);
36873691
return NULL;
36883692
}
3693+
free(src);
36893694
return dst;
36903695
}
36913696

0 commit comments

Comments
 (0)