summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2017-01-31 21:01:14 -0500
committerTavian Barnes <tavianator@tavianator.com>2017-01-31 21:01:14 -0500
commit538e4b2054e9802ebc860943e0a43baf2ee46741 (patch)
tree70993ee6abf4d7cc0642bf55a5ea1d7edda4ce05 /eval.c
parentab64ca5d29147385b099edb8874d6e101b48c1e0 (diff)
downloadbfs-538e4b2054e9802ebc860943e0a43baf2ee46741.tar.xz
Don't trust st_size when reading symlinks
Linux /proc, for example, reports a st_size of 0 for everything. It's nice to be able to use -lname on them anyway.
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c13
1 files changed, 1 insertions, 12 deletions
diff --git a/eval.c b/eval.c
index 6a3da7a..4494cff 100644
--- a/eval.c
+++ b/eval.c
@@ -599,23 +599,12 @@ bool eval_lname(const struct expr *expr, struct eval_state *state) {
goto done;
}
- size_t size = statbuf->st_size + 1;
- name = malloc(size);
+ name = xreadlinkat(ftwbuf->at_fd, ftwbuf->at_path, statbuf->st_size);
if (!name) {
eval_error(state);
goto done;
}
- ssize_t len = readlinkat(ftwbuf->at_fd, ftwbuf->at_path, name, size);
- if (len < 0) {
- eval_error(state);
- goto done;
- } else if (len >= size) {
- goto done;
- }
-
- name[len] = '\0';
-
ret = fnmatch(expr->sdata, name, expr->idata) == 0;
done: