aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2020-01-08 14:23:34 -0800
committerRob Landley <rob@landley.net>2020-01-09 17:02:50 -0600
commit3609b31e07dc677ed779e75ca901aa46a7ecc3a5 (patch)
tree3de9850e0b4a232e8da4e7684774b850b3854215
parenta3da7efae55c6e2d3ff66fdc476b35f5bbec09e5 (diff)
downloadtoybox-3609b31e07dc677ed779e75ca901aa46a7ecc3a5.tar.gz
ls.c: just use getxattr()/lgetxattr().
bionic works around the fact that you can't use an O_PATH fd with fgetxattr(2), but glibc doesn't. Fixes https://github.com/landley/toybox/issues/158.
-rw-r--r--toys/posix/ls.c28
1 files changed, 6 insertions, 22 deletions
diff --git a/toys/posix/ls.c b/toys/posix/ls.c
index 8bf9f693..9b382590 100644
--- a/toys/posix/ls.c
+++ b/toys/posix/ls.c
@@ -187,29 +187,13 @@ static int filter(struct dirtree *new)
if (FLAG(Z)) {
if (!CFG_TOYBOX_LSM_NONE) {
+ // Linux doesn't support fgetxattr(2) on O_PATH file descriptors (though
+ // bionic works around that), and there are no *xattrat(2) calls, so we
+ // just use lgetxattr(2).
+ char *path = dirtree_path(new, 0);
- // (Wouldn't it be nice if the lsm functions worked like openat(),
- // fchmodat(), mknodat(), readlinkat() so we could do this without
- // even O_PATH? But no, this is 1990's tech.)
- int fd = openat(dirtree_parentfd(new), new->name,
- O_PATH|(O_NOFOLLOW*!FLAG(L)));
-
- if (fd != -1) {
- if (-1 == lsm_fget_context(fd, (char **)&new->extra) && errno == EBADF)
- {
- char hack[32];
-
- // Work around kernel bug that won't let us read this "metadata" from
- // the filehandle unless we have permission to read the data. (We can
- // query the same data in by path, but can't do it through an O_PATH
- // filehandle, because reasons. But for some reason, THIS is ok? If
- // they ever fix the kernel, this should stop triggering.)
-
- sprintf(hack, "/proc/self/fd/%d", fd);
- lsm_lget_context(hack, (char **)&new->extra);
- }
- close(fd);
- }
+ (FLAG(L) ? lsm_get_context : lsm_lget_context)(path,(char **)&new->extra);
+ free(path);
}
if (CFG_TOYBOX_LSM_NONE || !new->extra) new->extra = (long)xstrdup("?");
}