mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 10:58:49 +08:00
Merged in x_qin/nuttx/null_check_for_open_and_write (pull request #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>
This commit is contained in:
parent
c4d03d81e2
commit
e5c79ba1a6
2 changed files with 19 additions and 5 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -202,6 +209,7 @@ ssize_t write(int fd, FAR const void *buf, size_t nbytes)
|
|||
}
|
||||
#endif
|
||||
|
||||
errout:
|
||||
leave_cancellation_point();
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue