diff options
-rw-r--r-- | libsandbox/libsandbox.c | 8 | ||||
-rw-r--r-- | libsandbox/libsandbox.h | 2 | ||||
-rwxr-xr-x | tests/script-5.sh | 1 |
3 files changed, 7 insertions, 4 deletions
diff --git a/libsandbox/libsandbox.c b/libsandbox/libsandbox.c index 6c405aa..03a2069 100644 --- a/libsandbox/libsandbox.c +++ b/libsandbox/libsandbox.c @@ -163,7 +163,7 @@ int canonicalize(const char *path, char *resolved_path) * an absolute path */ - if (ENAMETOOLONG == errno) + if (errno_is_too_long()) return -1; if (NULL == egetcwd(resolved_path, SB_PATH_MAX - 2)) @@ -172,7 +172,7 @@ int canonicalize(const char *path, char *resolved_path) snprintf(resolved_path + len, SB_PATH_MAX - len, "/%s", path); if (NULL == erealpath(resolved_path, resolved_path)) { - if (errno == ENAMETOOLONG) { + if (errno_is_too_long()) { /* The resolved path is too long for the buffer to hold */ return -1; } else { @@ -916,7 +916,7 @@ static int check_syscall(sbcontext_t *sbcontext, int sb_nr, const char *func, /* The path is too long to be canonicalized, so just warn and let the * function handle it (see bugs #21766 #94630 #101728 #227947) */ - if (ENAMETOOLONG == errno) { + if (errno_is_too_long()) { free(absolute_path); free(resolved_path); return 2; @@ -983,7 +983,7 @@ bool before_syscall(int dirfd, int sb_nr, const char *func, const char *file, in ssize_t ret = readlink(at_file_buf, at_file_buf, at_len); if (ret == -1) { /* see comments at end of check_syscall() */ - if (errno == ENAMETOOLONG) { + if (errno_is_too_long()) { restore_errno(); return true; } diff --git a/libsandbox/libsandbox.h b/libsandbox/libsandbox.h index 439e9b2..28154c5 100644 --- a/libsandbox/libsandbox.h +++ b/libsandbox/libsandbox.h @@ -69,6 +69,8 @@ __attribute__((noreturn)) void sb_abort(void); char *erealpath(const char *, char *); char *egetcwd(char *, size_t); int canonicalize(const char *, char *); +/* most linux systems use ENAMETOOLONG, but some (ia64) use ERANGE, as do some BSDs */ +#define errno_is_too_long() (errno == ENAMETOOLONG || errno == ERANGE) #include "sbutil.h" diff --git a/tests/script-5.sh b/tests/script-5.sh index 4b7d4fd..9f3e4bc 100755 --- a/tests/script-5.sh +++ b/tests/script-5.sh @@ -4,6 +4,7 @@ [ "${at_xfail}" = "yes" ] && exit 77 # see script-0 addwrite $PWD +mkdir foo && cd foo || exit 1 getcwd-gnulib_tst case $? in 0|1|2) exit 0;; # test may exit with these values |