From 8271e7fb801b2f7d2a5dc89e08b84d835f1376b9 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Mon, 2 Nov 2009 16:11:18 -0700 Subject: [PATCH] stdlib-safer: wrap all mkstemp variants * modules/mkostemp (configure.ac): Set witness. * modules/mkostemps (configure.ac): Likewise. * modules/mkstemps (configure.ac): Likewise. * lib/stdlib-safer.h (mkostemp_safer, mkostemps_safer) (mkstemps_safer): Wrap more functions. * lib/stdlib--.h (mkostemp, mkostemps, mkstemps): Default the wrapping. * lib/mkstemp-safer.c (mkostemp_safer, mkostemps_safer) (mkstemps_safer): Implement the wrappers. Signed-off-by: Eric Blake --- ChangeLog | 11 +++++++++++ lib/mkstemp-safer.c | 31 ++++++++++++++++++++++++++++++- lib/stdlib--.h | 14 +++++++++++++- lib/stdlib-safer.h | 14 +++++++++++++- modules/mkostemp | 1 + modules/mkostemps | 1 + modules/mkstemps | 1 + 7 files changed, 70 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 34952e259..fdfd828a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2009-11-04 Eric Blake + stdlib-safer: wrap all mkstemp variants + * modules/mkostemp (configure.ac): Set witness. + * modules/mkostemps (configure.ac): Likewise. + * modules/mkstemps (configure.ac): Likewise. + * lib/stdlib-safer.h (mkostemp_safer, mkostemps_safer) + (mkstemps_safer): Wrap more functions. + * lib/stdlib--.h (mkostemp, mkostemps, mkstemps): Default the + wrapping. + * lib/mkstemp-safer.c (mkostemp_safer, mkostemps_safer) + (mkstemps_safer): Implement the wrappers. + mkstemps, mkostemps: new modules * modules/mkostemps: New module. * modules/mkstemps: Likewise. diff --git a/lib/mkstemp-safer.c b/lib/mkstemp-safer.c index 4ba97c379..95d315b03 100644 --- a/lib/mkstemp-safer.c +++ b/lib/mkstemp-safer.c @@ -1,6 +1,6 @@ /* Invoke mkstemp, but avoid some glitches. - Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. + Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -32,3 +32,32 @@ mkstemp_safer (char *templ) { return fd_safer (mkstemp (templ)); } + +#if GNULIB_MKOSTEMP +/* Like mkostemp, but do not return STDIN_FILENO, STDOUT_FILENO, or + STDERR_FILENO. */ +int +mkostemp_safer (char *templ, int flags) +{ + return fd_safer (mkostemp (templ, flags)); +} +#endif + +#if GNULIB_MKOSTEMPS +/* Like mkostemps, but do not return STDIN_FILENO, STDOUT_FILENO, or + STDERR_FILENO. */ +int +mkostemps_safer (char *templ, int suffixlen, int flags) +{ + return fd_safer (mkostemps (templ, suffixlen, flags)); +} +#endif + +#if GNULIB_MKSTEMPS +/* Like mkstemps, but do not return STDIN_FILENO, STDOUT_FILENO, or + STDERR_FILENO. */ +int mkstemps_safer (char *templ, int suffixlen) +{ + return fd_safer (mkstemps (templ, suffixlen)); +} +#endif diff --git a/lib/stdlib--.h b/lib/stdlib--.h index 495d0eb8f..91268c920 100644 --- a/lib/stdlib--.h +++ b/lib/stdlib--.h @@ -1,6 +1,6 @@ /* Like stdlib.h, but redefine some names to avoid glitches. - Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. + Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,3 +22,15 @@ #undef mkstemp #define mkstemp mkstemp_safer + +#if GNULIB_MKOSTEMP +# define mkostemp mkostemp_safer +#endif + +#if GNULIB_MKOSTEMPS +# define mkostemps mkostemps_safer +#endif + +#if GNULIB_MKSTEMPS +# define mkstemps mkstemps_safer +#endif diff --git a/lib/stdlib-safer.h b/lib/stdlib-safer.h index a01437296..c28897ca2 100644 --- a/lib/stdlib-safer.h +++ b/lib/stdlib-safer.h @@ -1,6 +1,6 @@ /* Invoke stdlib.h functions, but avoid some glitches. - Copyright (C) 2005 Free Software Foundation, Inc. + Copyright (C) 2005, 2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,3 +18,15 @@ /* Written by Paul Eggert. */ int mkstemp_safer (char *); + +#if GNULIB_MKOSTEMP +int mkostemp_safer (char *, int); +#endif + +#if GNULIB_MKOSTEMPS +int mkostemps_safer (char *, int, int); +#endif + +#if GNULIB_MKSTEMPS +int mkstemps_safer (char *, int); +#endif diff --git a/modules/mkostemp b/modules/mkostemp index e336b9062..8a61dbeb0 100644 --- a/modules/mkostemp +++ b/modules/mkostemp @@ -13,6 +13,7 @@ tempname configure.ac: gl_FUNC_MKOSTEMP +gl_MODULE_INDICATOR([mkostemp]) gl_STDLIB_MODULE_INDICATOR([mkostemp]) Makefile.am: diff --git a/modules/mkostemps b/modules/mkostemps index 54c55e67b..a4175bdb5 100644 --- a/modules/mkostemps +++ b/modules/mkostemps @@ -13,6 +13,7 @@ tempname configure.ac: gl_FUNC_MKOSTEMPS +gl_MODULE_INDICATOR([mkostemps]) gl_STDLIB_MODULE_INDICATOR([mkostemps]) Makefile.am: diff --git a/modules/mkstemps b/modules/mkstemps index 14f469858..2a4977767 100644 --- a/modules/mkstemps +++ b/modules/mkstemps @@ -12,6 +12,7 @@ tempname configure.ac: gl_FUNC_MKSTEMPS +gl_MODULE_INDICATOR([mkstemps]) gl_STDLIB_MODULE_INDICATOR([mkstemps]) Makefile.am: -- 2.11.0