Reinstate the use of $TMPDIR and $TMP in cursor positioning rather than hard-coding "/tmp" (#88).

This commit is contained in:
Andrew Wood
2024-04-20 21:46:23 +01:00
parent d3c59cbff3
commit a5700cc914
2 changed files with 9 additions and 6 deletions
+8 -6
View File
@@ -95,14 +95,16 @@ static void pv_crs_open_lockfile(pvstate_t state, int fd)
return;
}
tmpdir = (char *) getenv("TMPDIR"); /* flawfinder: ignore */
if ((NULL == tmpdir) || ('\0' == tmpdir[0]))
tmpdir = (char *) getenv("TMP"); /* flawfinder: ignore */
if ((NULL == tmpdir) || ('\0' == tmpdir[0]))
tmpdir = "/tmp";
/*
* We used to look at the TMPDIR or TMP environment variables to
* override the temporary directory, but this leads to less
* predictable behaviour, and flawfinder points out that relying on
* environment variables in this way is not safe. So the lock
* directory is hard-coded to "/tmp" now (Sep 2023).
* flawfinder rationale: null and zero-size values of $TMPDIR and
* $TMP are rejected, and the destination buffer is bounded.
*/
tmpdir = "/tmp";
memset(state->cursor.lock_file, 0, PV_SIZEOF_CRS_LOCK_FILE);
(void) pv_snprintf(state->cursor.lock_file,