Skip to content

Commit

Permalink
Check for file==dir only when reading.
Browse files Browse the repository at this point in the history
  • Loading branch information
ralight committed Aug 23, 2021
1 parent ba2ca33 commit 9526b4c
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/misc_mosq.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,16 @@ FILE *mosquitto__fopen(const char *path, const char *mode, bool restrict_read)
}
}
#else
struct stat statbuf;
if(stat(path, &statbuf) < 0){
return NULL;
}
if(mode[0] == 'r'){
struct stat statbuf;
if(stat(path, &statbuf) < 0){
return NULL;
}

if(!S_ISREG(statbuf.st_mode) && !S_ISLNK(statbuf.st_mode)){
log__printf(NULL, MOSQ_LOG_ERR, "Error: %s is not a file.", path);
return NULL;
if(!S_ISREG(statbuf.st_mode) && !S_ISLNK(statbuf.st_mode)){
log__printf(NULL, MOSQ_LOG_ERR, "Error: %s is not a file.", path);
return NULL;
}
}

if (restrict_read) {
Expand Down

0 comments on commit 9526b4c

Please sign in to comment.