From: Namhyung Kim <namhyung@gmail.com>
To: util-linux@vger.kernel.org
Subject: [PATCH] libmount: Save errno if mkostemp() failed
Date: Sun, 29 Sep 2013 19:11:37 +0900 [thread overview]
Message-ID: <1380449497-3298-1-git-send-email-namhyung@gmail.com> (raw)
After mkostemp() failed, umask() and free() might alter the errno
to another value. Not sure those calls really changes the errno
or not. But let's be more conservative.
Signed-off-by: Namhyung Kim <namhyung@gmail.com>
---
libmount/src/utils.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/libmount/src/utils.c b/libmount/src/utils.c
index 3cab936..7930e29 100644
--- a/libmount/src/utils.c
+++ b/libmount/src/utils.c
@@ -849,6 +849,8 @@ int mnt_open_uniq_filename(const char *filename, char **name)
oldmode = umask(S_IRGRP|S_IWGRP|S_IXGRP|
S_IROTH|S_IWOTH|S_IXOTH);
fd = mkostemp(n, O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC);
+ if (fd < 0)
+ fd = -errno;
umask(oldmode);
if (fd >= 0 && name)
@@ -856,7 +858,7 @@ int mnt_open_uniq_filename(const char *filename, char **name)
else
free(n);
- return fd < 0 ? -errno : fd;
+ return fd;
}
/**
--
1.7.9.2
next reply other threads:[~2013-09-29 10:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-29 10:11 Namhyung Kim [this message]
2013-09-30 12:09 ` [PATCH] libmount: Save errno if mkostemp() failed Karel Zak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1380449497-3298-1-git-send-email-namhyung@gmail.com \
--to=namhyung@gmail.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox