Fix Coverity Scan 1491166.

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

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

Loading…
Cancel
Save