Skip to contentSkip to conversation

libmount: Save errno if mkostemp() failed

PATCH In review Namhyung Kim 2 participants 2 messages Sep 29, 2013 – Sep 30, 2013 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libmount: Save errno if mkostemp() failed

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.

---
 libmount/src/utils.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
libmount/src/utils.c +3 -1
index 3cab936..7930e29 100644
@@ -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;
 }
 
 /**
Signature · 1 line
1.7.9.2
maintainer
#1 lore raw
Quoted 1 line · Namhyung Kim

After mkostemp() failed, umask() and free() might alter the errno

I don't think umask and free alter errno, but

Quoted 2 lines

to another value. Not sure those calls really changes the errno or not. But let's be more conservative.

ok, it seems more readable then the old version. Applied, thanks.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com