Fix Coverity Scan 1491166.

pull/2558/merge
Roger A. Light 3 years ago
parent f0d7c27a67
commit 2a95ec73ba

@ -130,32 +130,32 @@ FILE *mosquitto__fopen(const char *path, const char *mode, bool restrict_read)
} }
} }
#else #else
if(mode[0] == 'r'){ FILE *fptr;
struct stat statbuf;
if(stat(path, &statbuf) < 0){
return NULL;
}
if(!S_ISREG(statbuf.st_mode) && !S_ISLNK(statbuf.st_mode)){
#ifdef WITH_BROKER
log__printf(NULL, MOSQ_LOG_ERR, "Error: %s is not a file.", path);
#endif
return NULL;
}
}
if(restrict_read){ if(restrict_read){
FILE *fptr;
mode_t old_mask; mode_t old_mask;
old_mask = umask(0077); old_mask = umask(0077);
fptr = fopen(path, mode); fptr = fopen(path, mode);
umask(old_mask); umask(old_mask);
return fptr;
}else{ }else{
return fopen(path, mode); fptr = fopen(path, mode);
}
struct stat statbuf;
if(fstat(fileno(fptr), &statbuf) < 0){
fclose(fptr);
return NULL;
}
if(!S_ISREG(statbuf.st_mode) && !S_ISLNK(statbuf.st_mode)){
#ifdef WITH_BROKER
log__printf(NULL, MOSQ_LOG_ERR, "Error: %s is not a file.", path);
#endif
fclose(fptr);
return NULL;
} }
return fptr;
#endif #endif
} }

Loading…
Cancel
Save