mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 11:26:12 +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:
+10
-4
@@ -99,15 +99,21 @@ int open(const char *path, int oflags, ...)
|
|||||||
int ret;
|
int ret;
|
||||||
int fd;
|
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_FILE_MODE
|
||||||
# ifdef CONFIG_CPP_HAVE_WARNING
|
# ifdef CONFIG_CPP_HAVE_WARNING
|
||||||
# warning "File creation not implemented"
|
# warning "File creation not implemented"
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
/* open() is a cancellation point */
|
|
||||||
|
|
||||||
(void)enter_cancellation_point();
|
|
||||||
|
|
||||||
/* If the file is opened for creation, then get the mode bits */
|
/* If the file is opened for creation, then get the mode bits */
|
||||||
|
|
||||||
if ((oflags & (O_WRONLY | O_CREAT)) != 0)
|
if ((oflags & (O_WRONLY | O_CREAT)) != 0)
|
||||||
|
|||||||
+9
-1
@@ -153,6 +153,13 @@ ssize_t write(int fd, FAR const void *buf, size_t nbytes)
|
|||||||
|
|
||||||
(void)enter_cancellation_point();
|
(void)enter_cancellation_point();
|
||||||
|
|
||||||
|
if (buf == NULL)
|
||||||
|
{
|
||||||
|
set_errno(EINVAL);
|
||||||
|
ret = ERROR;
|
||||||
|
goto errout;
|
||||||
|
}
|
||||||
|
|
||||||
/* Did we get a valid file descriptor? */
|
/* Did we get a valid file descriptor? */
|
||||||
|
|
||||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
#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);
|
ret = send(fd, buf, nbytes, 0);
|
||||||
#else
|
#else
|
||||||
set_errno(EBADF);
|
set_errno(EBADF);
|
||||||
ret = ERROR ERROR;
|
ret = ERROR;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,6 +209,7 @@ ssize_t write(int fd, FAR const void *buf, size_t nbytes)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
errout:
|
||||||
leave_cancellation_point();
|
leave_cancellation_point();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user