io: more guards against NULL filename (#7159)

References ac055d677a
References #4370
This commit is contained in:
Justin M. Keyes 2017-08-13 18:46:09 +02:00 committed by GitHub
parent 3c8d063786
commit d258ac8ed2
4 changed files with 8 additions and 1 deletions

View File

@ -1825,6 +1825,7 @@ static int process_env(char *env, bool is_viminit)
/// os_fileinfo_link() respectively for extra security.
static bool file_owned(const char *fname)
{
assert(fname != NULL);
uid_t uid = getuid();
FileInfo file_info;
bool file_owned = os_fileinfo(fname, &file_info)

View File

@ -895,6 +895,7 @@ static bool mf_do_open(memfile_T *mfp, char_u *fname, int flags)
{
// fname cannot be NameBuff, because it must have been allocated.
mf_set_fnames(mfp, fname);
assert(mfp->mf_fname != NULL);
/// Extra security check: When creating a swap file it really shouldn't
/// exist yet. If there is a symbolic link, this is most likely an attack.

View File

@ -1460,6 +1460,7 @@ static int process_still_running;
*/
static time_t swapfile_info(char_u *fname)
{
assert(fname != NULL);
int fd;
struct block0 b0;
time_t x = (time_t)0;
@ -3135,6 +3136,7 @@ attention_message (
char_u *fname /* swap file name */
)
{
assert(buf->b_fname != NULL);
time_t x, sx;
char *p;

View File

@ -859,8 +859,11 @@ bool os_fileinfo(const char *path, FileInfo *file_info)
/// @param[out] file_info Pointer to a FileInfo to put the information in.
/// @return `true` on success, `false` for failure.
bool os_fileinfo_link(const char *path, FileInfo *file_info)
FUNC_ATTR_NONNULL_ALL
FUNC_ATTR_NONNULL_ARG(2)
{
if (path == NULL) {
return false;
}
uv_fs_t request;
int result = uv_fs_lstat(&fs_loop, &request, path, NULL);
file_info->stat = request.statbuf;