Skip to content

Commit

Permalink
Merged in x_qin/nuttx/null_check_for_open_and_write (pull request apa…
Browse files Browse the repository at this point in the history
…che#498)

fs/vfs:null check for path on open and buf on write

Null path check is depend on CONFIG_DEBUG_FEATURES and CONFIG_DEBUG_ASSERTIONS, added null checking so it's always performed
Added null checking on buf for write()

Approved-by: Gregory Nutt <gnutt@nuttx.org>
  • Loading branch information
Xiao Qin authored and gregory-nutt committed Sep 29, 2017
1 parent c4d03d8 commit e5c79ba
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
14 changes: 10 additions & 4 deletions fs/vfs/fs_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,21 @@ int open(const char *path, int oflags, ...)
int ret;
int fd;

/* open() is a cancellation point */

(void)enter_cancellation_point();

if (path == NULL)
{
set_errno(EINVAL);
goto errout;
}

#ifdef CONFIG_FILE_MODE
# ifdef CONFIG_CPP_HAVE_WARNING
# warning "File creation not implemented"
# endif

/* open() is a cancellation point */

(void)enter_cancellation_point();

/* If the file is opened for creation, then get the mode bits */

if ((oflags & (O_WRONLY | O_CREAT)) != 0)
Expand Down
10 changes: 9 additions & 1 deletion fs/vfs/fs_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ ssize_t write(int fd, FAR const void *buf, size_t nbytes)

(void)enter_cancellation_point();

if (buf == NULL)
{
set_errno(EINVAL);
ret = ERROR;
goto errout;
}

/* Did we get a valid file descriptor? */

#if CONFIG_NFILE_DESCRIPTORS > 0
Expand All @@ -167,7 +174,7 @@ ssize_t write(int fd, FAR const void *buf, size_t nbytes)
ret = send(fd, buf, nbytes, 0);
#else
set_errno(EBADF);
ret = ERROR ERROR;
ret = ERROR;
#endif
}

Expand Down Expand Up @@ -202,6 +209,7 @@ ssize_t write(int fd, FAR const void *buf, size_t nbytes)
}
#endif

errout:
leave_cancellation_point();
return ret;
}

0 comments on commit e5c79ba

Please sign in to comment.