Skip to content

Commit 5e94d44

Browse files
JianyuWang0623xiaoxiang781216
authored andcommitted
fs/vfs: check buffer count and pointer for iovec
There are iovecs provided by user such as readv(). Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
1 parent 89df084 commit 5e94d44

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

fs/vfs/fs_read.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,18 @@ ssize_t file_readv(FAR struct file *filep,
164164
DEBUGASSERT(filep);
165165
inode = filep->f_inode;
166166

167+
/* Check buffer count and pointer for iovec */
168+
169+
if (iovcnt == 0)
170+
{
171+
return 0;
172+
}
173+
174+
if (iov == NULL)
175+
{
176+
return -EFAULT;
177+
}
178+
167179
/* Are all iov_base accessible? */
168180

169181
for (ret = 0; ret < iovcnt; ret++)

fs/vfs/fs_write.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,18 @@ ssize_t file_writev(FAR struct file *filep,
153153
return -EACCES;
154154
}
155155

156+
/* Check buffer count and pointer for iovec */
157+
158+
if (iovcnt == 0)
159+
{
160+
return 0;
161+
}
162+
163+
if (iov == NULL)
164+
{
165+
return -EFAULT;
166+
}
167+
156168
/* Are all iov_base accessible? */
157169

158170
for (ret = 0; ret < iovcnt; ret++)

0 commit comments

Comments
 (0)