From ea39049f995fb01987a3556520639fefb3bb79a7 Mon Sep 17 00:00:00 2001 From: dequis Date: Thu, 17 Dec 2015 13:56:25 -0300 Subject: ini: Null check file parameter before passing it to open() The test suite does this. It's harmless in practice but open() is declared as nonnull. Thanks to clang's ubsan. --- lib/ini.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ini.c b/lib/ini.c index 4dbdec64..be2de974 100644 --- a/lib/ini.c +++ b/lib/ini.c @@ -27,11 +27,11 @@ ini_t *ini_open(char *file) { - int fd; + int fd = -1; ini_t *ini = NULL; struct stat fi; - if ((fd = open(file, O_RDONLY)) != -1 && + if (file && (fd = open(file, O_RDONLY)) != -1 && fstat(fd, &fi) == 0 && fi.st_size <= 16384 && (ini = g_malloc(sizeof(ini_t) + fi.st_size + 1)) && -- cgit v1.2.3