bug-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[patch] Fix clobbering of errno in filesubr.c::mkdir_if_needed


From: Brian Poole
Subject: [patch] Fix clobbering of errno in filesubr.c::mkdir_if_needed
Date: Wed, 19 Mar 2003 13:36:00 -0500

errno can get clobbered in mkdir_if_needed if isdir() gets
called (as isdir calls stat().) This patch saves the errno for 
use in the error message so that the error message actually makes
sense. I don't believe its valid to print the error from the stat
call as the error message is saying it can't make the directory,
ie the failure is in mkdir(). If the stat()'s error is important
than it should have a separate error call.

The bug can be illustrated by attempting to checkout a module when
in a directory that you do not have write permission to, such as /.

Previous behavior:

cvs [checkout aborted]: cannot make directory amanda: No such file or directory

New behavior:

cvs [checkout aborted]: cannot make directory amanda: Permission denied

Patch looks like this (not against official CVS sources but looking
at the online repo it looks like this should still be correct but may
require hand applying.)

Index: src/filesubr.c
===================================================================
RCS file: /cvs/src/gnu/usr.bin/cvs/src/filesubr.c,v
retrieving revision 1.2
diff -u -r1.2 filesubr.c
--- src/filesubr.c      9 Dec 2002 00:45:34 -0000       1.2
+++ src/filesubr.c      19 Mar 2003 18:34:00 -0000
@@ -331,9 +331,11 @@
 {
     if (mkdir (name, 0777) < 0)
     {
-       if (!(errno == EEXIST
-             || (errno == EACCES && isdir (name))))
-           error (1, errno, "cannot make directory %s", name);
+       int saved_errno = errno; /* isdir clobbers errno */
+
+       if (!(saved_errno == EEXIST
+             || (saved_errno == EACCES && isdir (name))))
+           error (1, saved_errno, "cannot make directory %s", name);
        return 1;
     }
     return 0;


-b

[not on the list, please CC on replies]




reply via email to

[Prev in Thread] Current Thread [Next in Thread]