mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-04 13:14:32 +02:00
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:
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user