[pipe] Use fstat instead of lstat to fix time-of-check time-of-use warning

Fixes warning from CodeQL. Wasn't really a security issue since the check was
just a service to the user.
This commit is contained in:
ejurgensen 2021-09-02 00:17:22 +02:00
parent de7ab1547f
commit 3f13ab1026

View File

@ -170,27 +170,33 @@ pipe_open(const char *path, bool silent)
DPRINTF(E_DBG, L_PLAYER, "(Re)opening pipe: '%s'\n", path); DPRINTF(E_DBG, L_PLAYER, "(Re)opening pipe: '%s'\n", path);
if (lstat(path, &sb) < 0) fd = open(path, O_RDONLY | O_NONBLOCK);
if (fd < 0)
{
DPRINTF(E_LOG, L_PLAYER, "Could not open pipe for reading '%s': %s\n", path, strerror(errno));
goto error;
}
if (fstat(fd, &sb) < 0)
{ {
if (!silent) if (!silent)
DPRINTF(E_LOG, L_PLAYER, "Could not lstat() '%s': %s\n", path, strerror(errno)); DPRINTF(E_LOG, L_PLAYER, "Could not fstat() '%s': %s\n", path, strerror(errno));
return -1; goto error;
} }
if (!S_ISFIFO(sb.st_mode)) if (!S_ISFIFO(sb.st_mode))
{ {
DPRINTF(E_LOG, L_PLAYER, "Source type is pipe, but path is not a fifo: %s\n", path); DPRINTF(E_LOG, L_PLAYER, "Source type is pipe, but path is not a fifo: %s\n", path);
return -1; goto error;
}
fd = open(path, O_RDONLY | O_NONBLOCK);
if (fd < 0)
{
DPRINTF(E_LOG, L_PLAYER, "Could not open pipe for reading '%s': %s\n", path, strerror(errno));
return -1;
} }
return fd; return fd;
error:
if (fd >= 0)
close(fd);
return -1;
} }
static void static void