Skip to content
Snippets Groups Projects
Commit e5c79ba1 authored by Xiao Qin's avatar Xiao Qin Committed by Gregory Nutt
Browse files

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: default avatarGregory Nutt <gnutt@nuttx.org>
parent c4d03d81
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment