diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2017-01-31 21:01:14 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2017-01-31 21:01:14 -0500 |
commit | 538e4b2054e9802ebc860943e0a43baf2ee46741 (patch) | |
tree | 70993ee6abf4d7cc0642bf55a5ea1d7edda4ce05 /eval.c | |
parent | ab64ca5d29147385b099edb8874d6e101b48c1e0 (diff) | |
download | bfs-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.c | 13 |
1 files changed, 1 insertions, 12 deletions
@@ -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: |