aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeebs <seebs@seebs.net>2018-03-31 11:59:20 -0500
committerSeebs <seebs@seebs.net>2018-03-31 11:59:20 -0500
commit4057859ec03ac04a31eb28d2275961f6019c8ae1 (patch)
tree504ba916143f104edff32150372149831596a2b8
parentf0fa9fba3c53bf4f87f33b47a583cb031b962d34 (diff)
downloadpseudo-4057859ec03ac04a31eb28d2275961f6019c8ae1.tar.gz
pseudo-4057859ec03ac04a31eb28d2275961f6019c8ae1.tar.bz2
pseudo-4057859ec03ac04a31eb28d2275961f6019c8ae1.zip
don't change errno in pseudo_fix_path
Two issues: (1) pseudo_fix_path could call lstat("") which generated ENOENT, (2) some people, and I'm totally not staring intently at cross-localedef here, don't know that it is in general *not* valid to check errno unless an operation has failed, and the mere fact that something set errno does not mean that the error indicated actually occurred or has any relevance to you. Nonetheless, pseudo_fix_path now saves and restores errno, and cross-localedef can just go ahead and check it as though it were guaranteed not to sometimes get set even though no error occurred. Signed-off-by: Seebs <seebs@seebs.net>
-rw-r--r--ChangeLog.txt7
-rw-r--r--pseudo_util.c14
2 files changed, 19 insertions, 2 deletions
diff --git a/ChangeLog.txt b/ChangeLog.txt
index e757596..f984820 100644
--- a/ChangeLog.txt
+++ b/ChangeLog.txt
@@ -1,3 +1,10 @@
+2018-03-31:
+ * (seebs) keep pseudo_fix_path from changing errno, because
+ *some* people think they should check errno to find out
+ whether an error occurred, even if no call has returned
+ a status indicating an error, and this is completely wrong
+ but we can't fix them all.
+
2018-03-30:
* (seebs) fix path stuff more thoroughly.
* (seebs) Merge suggested README change from Richard Tollerton
diff --git a/pseudo_util.c b/pseudo_util.c
index e01dfc2..a5e68f1 100644
--- a/pseudo_util.c
+++ b/pseudo_util.c
@@ -755,8 +755,15 @@ pseudo_append_elements(char *newpath, char *root, size_t allocated, char **curre
* then get shared by anything we call.
*/
sbuf = &buf;
- if (!pseudo_real_lstat || (pseudo_real_lstat(newpath, sbuf) == -1)) {
- sbuf->st_mode = (*current > root) ? 0 : S_IFDIR;
+ if (*current > root) {
+ if (!pseudo_real_lstat || (pseudo_real_lstat(newpath, sbuf) == -1)) {
+ sbuf->st_mode = 0;
+ }
+ } else {
+ /* Don't call lstat on an empty path, or at all when we
+ * know that "root" is always directory-like.
+ */
+ sbuf->st_mode = S_IFDIR;
}
}
pseudo_debug(PDBGF_PATH | PDBGF_VERBOSE, "paes: newpath %s, element list <%.*s>\n",
@@ -852,6 +859,7 @@ pseudo_fix_path(const char *base, const char *path, size_t rootlen, size_t basel
* newpathlen is the total allocated length of newpath
* (current - newpath) is the used length of newpath
*/
+ int save_errno = errno;
if (pseudo_append_elements(newpath, effective_root, newpathlen, &current, path, pathlen, leave_last, 0) != -1) {
/* if we are expecting a trailing slash, or the path ended up being completely
* empty (meaning it's pointing at either effective_root or the beginning of
@@ -870,8 +878,10 @@ pseudo_fix_path(const char *base, const char *path, size_t rootlen, size_t basel
if (lenp) {
*lenp = current - newpath;
}
+ errno = save_errno;
return newpath;
} else {
+ errno = save_errno;
return 0;
}
}