Skip to content

Commit 7dd4432

Browse files
glommerantirez
authored andcommitted
fix null pointer access with no file pointer
I happen to be working on a system that lacks urandom. While the code does try to handle this case and artificially create some bytes if the file pointer is empty, it does try to close it unconditionally, leading to a segfault.
1 parent e0918a3 commit 7dd4432

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ void getRandomHexChars(char *p, unsigned int len) {
402402
/* Turn it into hex digits taking just 4 bits out of 8 for every byte. */
403403
for (j = 0; j < len; j++)
404404
p[j] = charset[p[j] & 0x0F];
405-
fclose(fp);
405+
if (fp) fclose(fp);
406406
}
407407

408408
/* Given the filename, return the absolute path as an SDS string, or NULL

0 commit comments

Comments
 (0)