vfs: zero-initialize struct stat in *_stat and *_fstat handlers

...otherwise some fields will contain garbage values.
This wasn't noticed until HAVE_BLKSIZE got enabled in newlib builds.
This commit is contained in:
Ivan Grokhotkov
2020-11-05 17:38:22 +01:00
parent 7f3b16a99d
commit b1c4107275
5 changed files with 6 additions and 2 deletions

View File

@@ -552,6 +552,7 @@ static int vfs_fat_fstat(void* ctx, int fd, struct stat * st)
{
vfs_fat_ctx_t* fat_ctx = (vfs_fat_ctx_t*) ctx;
FIL* file = &fat_ctx->files[fd];
memset(st, 0, sizeof(*st));
st->st_size = f_size(file);
st->st_mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFREG;
st->st_mtime = 0;

View File

@@ -536,6 +536,7 @@ static int vfs_spiffs_fstat(void* ctx, int fd, struct stat * st)
SPIFFS_clearerr(efs->fs);
return -1;
}
memset(st, 0, sizeof(*st));
st->st_size = s.size;
st->st_mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFREG;
st->st_mtime = vfs_spiffs_get_mtime(&s);
@@ -558,7 +559,7 @@ static int vfs_spiffs_stat(void* ctx, const char * path, struct stat * st)
SPIFFS_clearerr(efs->fs);
return -1;
}
memset(st, 0, sizeof(*st));
st->st_size = s.size;
st->st_mode = S_IRWXU | S_IRWXG | S_IRWXO;
st->st_mode |= (s.type == SPIFFS_TYPE_DIR)?S_IFDIR:S_IFREG;

View File

@@ -207,6 +207,7 @@ static ssize_t tusb_read(int fd, void *data, size_t size)
static int tusb_fstat(int fd, struct stat *st)
{
FD_CHECK(fd, -1);
memset(st, 0, sizeof(*st));
st->st_mode = S_IFCHR;
return 0;
}

View File

@@ -96,6 +96,7 @@ static int cdcacm_open(const char *path, int flags, int mode)
static int cdcacm_fstat(int fd, struct stat *st)
{
assert(fd == 0);
memset(st, 0, sizeof(*st));
st->st_mode = S_IFCHR;
return 0;
}

View File

@@ -291,7 +291,7 @@ static ssize_t uart_read(int fd, void* data, size_t size)
static int uart_fstat(int fd, struct stat * st)
{
assert(fd >=0 && fd < 3);
st->st_blksize = BUFSIZ;
memset(st, 0, sizeof(*st));
st->st_mode = S_IFCHR;
return 0;
}