Skip to content

Commit a0e501b

Browse files
authored
Merge pull request #904 from yosuke-wolfssl/f_1272
Add a bounds check on ff_close, ff_pwrite and ff_pread
2 parents 3075b72 + 96b6724 commit a0e501b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/wolfsftp.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,6 +1977,8 @@ int ff_open(const char *fname, int flag, int perm)
19771977

19781978
int ff_close(int fd)
19791979
{
1980+
if (fd < 0 || fd >= WOLFSSH_FATFS_MAX_FILES)
1981+
return -1;
19801982
f_close(&fd_pool[fd].f);
19811983
if (fd_pool[fd].used)
19821984
fd_pool[fd].used = 0;
@@ -1985,9 +1987,13 @@ int ff_close(int fd)
19851987

19861988
int ff_pwrite(int fd, const byte *buffer, int sz)
19871989
{
1988-
FIL *f = &fd_pool[fd].f;
1990+
FIL *f;
19891991
FRESULT ret;
19901992
unsigned int rsz;
1993+
1994+
if (fd < 0 || fd >= WOLFSSH_FATFS_MAX_FILES)
1995+
return -1;
1996+
f = &fd_pool[fd].f;
19911997
if (fd_pool[fd].used == 0)
19921998
return -1;
19931999
ret = f_write(f, buffer, sz, &rsz);
@@ -1997,9 +2003,13 @@ int ff_pwrite(int fd, const byte *buffer, int sz)
19972003
}
19982004
int ff_pread(int fd, byte *buffer, int sz)
19992005
{
2000-
FIL *f = &fd_pool[fd].f;
2006+
FIL *f;
20012007
FRESULT ret;
20022008
unsigned int rsz;
2009+
2010+
if (fd < 0 || fd >= WOLFSSH_FATFS_MAX_FILES)
2011+
return -1;
2012+
f = &fd_pool[fd].f;
20032013
if (fd_pool[fd].used == 0)
20042014
return -1;
20052015
ret = f_read(f, buffer, sz, &rsz);

0 commit comments

Comments
 (0)