Index: b/lib/routines.c =================================================================== --- a/lib/routines.c +++ b/lib/routines.c @@ -242,3 +242,50 @@ /* Don't complain if you can't unlink. Who cares of a tmp file? */ unlink (filename); } + +/* + * Securely generate a temp file, and make sure it gets + * deleted upon exit. + */ +static char ** tempfiles; +static unsigned ntempfiles; + +static void +cleanup_tempfiles() +{ + while (ntempfiles--) + unlink(tempfiles[ntempfiles]); +} + +char * +safe_tempnam(const char *pfx) +{ + char *dirname, *filename; + int fd; + + if (!(dirname = getenv("TMPDIR"))) + dirname = "/tmp"; + + tempfiles = (char **) realloc(tempfiles, + (ntempfiles+1) * sizeof(char *)); + if (tempfiles == NULL) + return NULL; + + filename = malloc(strlen(dirname) + strlen(pfx) + sizeof("/XXXXXX")); + if (!filename) + return NULL; + + sprintf(filename, "%s/%sXXXXXX", dirname, pfx); + + if ((fd = mkstemp(filename)) < 0) { + free(filename); + return NULL; + } + close(fd); + + if (ntempfiles == 0) + atexit(cleanup_tempfiles); + tempfiles[ntempfiles++] = filename; + + return filename; +} Index: b/lib/routines.h =================================================================== --- a/lib/routines.h +++ b/lib/routines.h @@ -255,7 +255,8 @@ /* If _STR_ is not defined, give it a tempname in _TMPDIR_ */ #define tempname_ensure(Str) \ do { \ - (Str) = (Str) ? (Str) : tempnam (NULL, "a2_"); \ + (Str) = (Str) ? (Str) : safe_tempnam("a2_"); \ } while (0) +char * safe_tempnam(const char *); #endif od='get' action='/guix/log/etc/committer.scm.in'>
path: root/etc/committer.scm.in
AgeCommit message (Expand)Author
2022-05-31etc/committer: Teach it how to commit package removal....Maxim Cournoyer
2022-05-31etc/committer: Prefix (sxml xpath) symbols to avoid name conflict....Maxim Cournoyer
2022-01-23etc: committer: Support plain input lists....Ricardo Wurmus
2021-09-21etc: committer: Amend previous commit if a copyright line was added....Xinglu Chen
2021-08-10etc/committer: Pass command-line arguments to main....Sarah Morgensen
2021-08-10etc/committer: Support custom commit messages....Sarah Morgensen
2021-08-07etc: committer: Support reading G-expressions....Maxime Devos
2021-05-04etc: Break long lines in commit messages....Ricardo Wurmus
2021-04-12etc/committer: Add missing newline....Morgan Smith
2021-04-12etc/committer: Use git plumbing instead of porcelain....Morgan Smith
2021-04-08etc/committer: Disable diff colors....Ricardo Wurmus
2021-04-08etc/committer: Recompute hunks before processing changes....Ricardo Wurmus
2021-04-08etc/committer: Record minimal context for hunks to avoid problems....Ricardo Wurmus
2021-04-08etc/committer: Define delay duration as a variable....Ricardo Wurmus
2021-04-08etc/committer: Handle package additions....Ricardo Wurmus
2020-10-06etc: committer: Use EQUAL? instead of EQ? for differences....Ricardo Wurmus
2020-06-16etc: Add committer script....Ricardo Wurmus