Skip to content

Commit

Permalink
Fully initialize the struct in the Stat response
Browse files Browse the repository at this point in the history
When providing a successful response to a Stat request, initialize
all the fields inside the struct.  This ensures everything is zeroed
out when it is later used.

(Use of uninitialized data was reported by valgrind)
  • Loading branch information
bbockelm committed Oct 22, 2024
1 parent 9c9652d commit 11f6b31
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/HTTPFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ ssize_t HTTPFile::Read(void *buffer, off_t offset, size_t size) {

int HTTPFile::Fstat(struct stat *buff) {
if (m_stat) {
memset(buff, '\0', sizeof(struct stat));
buff->st_mode = 0600 | S_IFREG;
buff->st_nlink = 1;
buff->st_uid = 1;
Expand Down Expand Up @@ -232,6 +233,7 @@ int HTTPFile::Fstat(struct stat *buff) {
}

if (buff) {
memset(buff, '\0', sizeof(struct stat));
buff->st_mode = 0600 | S_IFREG;
buff->st_nlink = 1;
buff->st_uid = 1;
Expand Down
1 change: 1 addition & 0 deletions src/S3File.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ int S3File::Fstat(struct stat *buff) {
current_newline = next_newline;
}

memset(buff, '\0', sizeof(struct stat));
buff->st_mode = 0600 | S_IFREG;
buff->st_nlink = 1;
buff->st_uid = 1;
Expand Down
3 changes: 3 additions & 0 deletions src/S3FileSystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ int S3FileSystem::Stat(const char *path, struct stat *buff, int opts,
}

if (object.empty()) {
memset(buff, '\0', sizeof(struct stat));
buff->st_mode = 0700 | S_IFDIR;
buff->st_nlink = 0;
buff->st_uid = 1;
Expand All @@ -291,6 +292,7 @@ int S3FileSystem::Stat(const char *path, struct stat *buff, int opts,
}
}
if (foundObj) {
memset(buff, '\0', sizeof(struct stat));
buff->st_mode = 0600 | S_IFREG;
buff->st_nlink = 1;
buff->st_uid = buff->st_gid = 1;
Expand All @@ -313,6 +315,7 @@ int S3FileSystem::Stat(const char *path, struct stat *buff, int opts,
return -ENOENT;
}

memset(buff, '\0', sizeof(struct stat));
buff->st_mode = 0700 | S_IFDIR;
buff->st_nlink = 0;
buff->st_uid = 1;
Expand Down

0 comments on commit 11f6b31

Please sign in to comment.