Skip to content

Commit

Permalink
fs: buffer safety stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
hanatos committed Feb 5, 2024
1 parent d2ecdd2 commit d6dcadd
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions src/core/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,19 +280,14 @@ static inline int fs_islnk(const char *dirname, const struct dirent *e)
#warning "port me!"
return 0;
#else
if (e->d_type == DT_LNK) {
return 1;
}
else if (e->d_type == DT_UNKNOWN) {
char buf[512];
strcpy(buf, dirname);
strcat(buf, "/");
strcat(buf, e->d_name);
if (e->d_type == DT_LNK) return 1;
else if (e->d_type == DT_UNKNOWN)
{
char buf[PATH_MAX];
if(sizeof(buf) <= snprintf(buf, sizeof(buf), "%s/%s", dirname, e->d_name)) return 0;
return fs_islnk_file(buf);
}
else {
return 0;
}
return 0;
#endif
}

Expand All @@ -318,19 +313,14 @@ static inline int fs_isreg(const char *dirname, const struct dirent *e)
_stat64(filename, &buf);
return (buf.st_mode & _S_IFREG) != 0;
#else
if (e->d_type == DT_REG) {
return 1;
}
else if (e->d_type == DT_UNKNOWN) {
char buf[512];
strcpy(buf, dirname);
strcat(buf, "/");
strcat(buf, e->d_name);
if (e->d_type == DT_REG) return 1;
else if (e->d_type == DT_UNKNOWN)
{
char buf[PATH_MAX];
if(sizeof(buf) <= snprintf(buf, sizeof(buf), "%s/%s", dirname, e->d_name)) return 0;
return fs_isreg_file(buf);
}
else {
return 0;
}
return 0;
#endif
}

Expand Down

0 comments on commit d6dcadd

Please sign in to comment.