-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Upstream: disallow empty path in proxy_store and friends. #344
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
Conversation
Renaming a temporary file to an empty path ("") returns NGX_ENOPATH with a subsequent ngx_create_full_path() to create the full path. This function skips initial bytes as part of path separator lookup, which causes out of bounds access on short strings. The fix is to avoid renaming a temporary file to an obviously invalid path, as well as explicitly forbid such syntax for literal values. Although Coverity reports about potential type underflow, it is not actually possible because the terminating '\0' is always included. Notably, the run-time check is sufficient enough for Win32 as well. Other short invalid values result either in NGX_ENOENT or NGX_EEXIST and "MoveFile() .. failed" critical log messages, which involves a separate error handling. Prodded by Coverity (CID 1605485).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notably, the run-time check is sufficient enough for Win32 as well. Other short invalid values result either in NGX_ENOENT or NGX_EEXIST and "MoveFile() .. failed" critical log messages, which involves a separate error handling.
Which run-time check do you mean? Seems like ngx_create_full_path()
does not have any protection against empty/short strings.
The newly added one, to mitigate ngx_ext_rename_file() call with invalid dst (empty) path:
FWIW, regarding the ngx_create_full_path() function name: while it may seem that it works with absolute paths only, actually it supports relative paths as well, such as when It seems the only reason why ngx_create_full_path() skips initial char (or three on win32) is because otherwise it may end up trying to rename something to zero-length string due to temporal path separator replacement with '\0'. |
WRT why ngx_create_full_path() should not be fixed instead:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The patch looks good.
Overall, calling ngx_create_full_path()
for something that may not be a full path deserves another look later.
Well, it certainly doesn't work with relative paths on win32 (although it can make you think that it does). |
Renaming a temporary file to an empty path ("") returns NGX_ENOPATH with a subsequent ngx_create_full_path() to create the full path. This function skips initial bytes as part of path separator lookup, which causes out of bounds access on short strings.
The fix is to avoid renaming a temporary file to an obviously invalid path, as well as explicitly forbid such syntax for literal values.
Although Coverity reports about potential type underflow, it is not actually possible because the terminating '\0' is always included.
Notably, the run-time check is sufficient enough for Win32 as well. Other short invalid values result either in NGX_ENOENT or NGX_EEXIST and "MoveFile() .. failed" critical log messages, which involves a separate error handling.
Prodded by Coverity (CID 1605485).