diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2016-02-27 12:31:10 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2016-02-27 12:31:10 -0500 |
commit | 388b66eb003d3026945992bd48f9180aff8b4f01 (patch) | |
tree | 196e547260983c37c08ee01ab0edf9d6176c49b1 /eval.c | |
parent | 89408ac96e1e71282716d9a2a51472a54cd01ef1 (diff) | |
download | bfs-388b66eb003d3026945992bd48f9180aff8b4f01.tar.xz |
Fix potential leaks in -lname.
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 29 |
1 files changed, 17 insertions, 12 deletions
@@ -315,36 +315,41 @@ bool eval_links(const struct expr *expr, struct eval_state *state) { * -i?lname test. */ bool eval_lname(const struct expr *expr, struct eval_state *state) { + bool ret = false; + char *name = NULL; + struct BFTW *ftwbuf = state->ftwbuf; if (ftwbuf->typeflag != BFTW_LNK) { - return false; + goto done; } const struct stat *statbuf = fill_statbuf(state); if (!statbuf) { - return false; + goto done; } size_t size = statbuf->st_size + 1; - char *name = malloc(size); + name = malloc(size); if (!name) { eval_error(state); - return false; + goto done; } - ssize_t ret = readlinkat(ftwbuf->at_fd, ftwbuf->at_path, name, size); - if (ret < 0) { + ssize_t len = readlinkat(ftwbuf->at_fd, ftwbuf->at_path, name, size); + if (len < 0) { eval_error(state); - return false; - } else if (ret >= size) { - return false; + goto done; + } else if (len >= size) { + goto done; } - name[ret] = '\0'; + name[len] = '\0'; + + ret = fnmatch(expr->sdata, name, expr->idata) == 0; - bool match = fnmatch(expr->sdata, name, expr->idata) == 0; +done: free(name); - return match; + return ret; } /** |