upstream commit

properly restore umask
This commit is contained in:
djm@openbsd.org 2015-01-26 13:36:53 +00:00 committed by Damien Miller
parent d411d39555
commit 3076ee7d53

View File

@ -1,4 +1,4 @@
/* $OpenBSD: hostfile.c,v 1.62 2015/01/26 03:04:45 djm Exp $ */ /* $OpenBSD: hostfile.c,v 1.63 2015/01/26 13:36:53 djm Exp $ */
/* /*
* Author: Tatu Ylonen <ylo@cs.hut.fi> * Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@ -551,6 +551,8 @@ hostfile_replace_entries(const char *filename, const char *host,
mode_t omask; mode_t omask;
size_t i; size_t i;
omask = umask(077);
memset(&ctx, 0, sizeof(ctx)); memset(&ctx, 0, sizeof(ctx));
ctx.host = host; ctx.host = host;
ctx.quiet = quiet; ctx.quiet = quiet;
@ -568,7 +570,6 @@ hostfile_replace_entries(const char *filename, const char *host,
goto fail; goto fail;
} }
omask = umask(077);
if ((fd = mkstemp(temp)) == -1) { if ((fd = mkstemp(temp)) == -1) {
oerrno = errno; oerrno = errno;
error("%s: mkstemp: %s", __func__, strerror(oerrno)); error("%s: mkstemp: %s", __func__, strerror(oerrno));
@ -636,6 +637,7 @@ hostfile_replace_entries(const char *filename, const char *host,
if (ctx.out != NULL) if (ctx.out != NULL)
fclose(ctx.out); fclose(ctx.out);
free(ctx.skip_keys); free(ctx.skip_keys);
umask(omask);
if (r == SSH_ERR_SYSTEM_ERROR) if (r == SSH_ERR_SYSTEM_ERROR)
errno = oerrno; errno = oerrno;
return r; return r;