From c83faf088df4e30bc568c1d200cbd5ee3e1a1c4c Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Apr 23 2015 21:36:18 +0000 Subject: Try to address a static analysis TOC-TOU warning Open the file before attempting to lstat() its name, for comparison with the fstat() on the open descriptor that we'd do next. --- diff --git a/src/util-n.c b/src/util-n.c index a86a178..c6c946a 100644 --- a/src/util-n.c +++ b/src/util-n.c @@ -153,12 +153,12 @@ util_set_db_owner_perms(const char *dbdir, const char *filename, return; } sprintf(pathname, "%s/%s", dbdir, filename); - if ((lstat(pathname, &before) == -1) || !S_ISREG(before.st_mode)) { + fd = open(pathname, O_RDWR); + if (fd == -1) { free(pathname); return; } - fd = open(pathname, O_RDWR); - if (fd == -1) { + if ((lstat(pathname, &before) == -1) || !S_ISREG(before.st_mode)) { free(pathname); return; }