From: Simon Josefsson Date: Tue, 20 May 2008 04:59:52 +0000 (+0200) Subject: Restore umask after opening file. X-Git-Tag: gnutls_2_3_11~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=830cdc0796d0cc7055cef987a50052d0ef3d55cf;p=thirdparty%2Fgnutls.git Restore umask after opening file. Suggested by Daniel Kahn Gillmor . --- diff --git a/src/certtool.c b/src/certtool.c index c6aeb2c59a..bf0990f7a7 100644 --- a/src/certtool.c +++ b/src/certtool.c @@ -821,12 +821,22 @@ update_signed_certificate (void) FILE* safe_open_rw(const char* file) { - if (info.privkey_op != 0) - { - umask(S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); - } + mode_t oldmask; + FILE *fh; + + if (info.privkey_op != 0) + { + oldmask = umask (S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); + } + + fh = fopen (file, "wb"); + + if (info.privkey_op != 0) + { + umask (oldmask); + } - return fopen (file, "wb"); + return fh; } void