diff options
author | Sebastian Benoit <benno@cvs.openbsd.org> | 2019-06-23 10:28:33 +0000 |
---|---|---|
committer | Sebastian Benoit <benno@cvs.openbsd.org> | 2019-06-23 10:28:33 +0000 |
commit | b838cbf5483a3d396af8083aca9d68fec8bf8ee9 (patch) | |
tree | e30c811e58b496fd704f2348caf4430dfa45aa42 /usr.bin | |
parent | c1b90a4a505ad55a599b17f1b18402386ea401a5 (diff) |
fix free() on uninitialized pointer with -rx and same
suggestions and ok naddy@ and ok previois diff florian@.
from Hiltjo Posthuma hiltjo AT codemadness DOT org and
Bjoern Ketelaars bjorn DOT ketelaars AT hydroxide DOT nl,
Thanks.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/rsync/flist.c | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/usr.bin/rsync/flist.c b/usr.bin/rsync/flist.c index e1f41b1a108..4860e20f428 100644 --- a/usr.bin/rsync/flist.c +++ b/usr.bin/rsync/flist.c @@ -1,4 +1,4 @@ -/* $Id: flist.c,v 1.27 2019/06/02 14:29:58 deraadt Exp $ */ +/* $Id: flist.c,v 1.28 2019/06/23 10:28:32 benno Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2019 Florian Obser <florian@openbsd.org> @@ -803,12 +803,12 @@ flist_gen_dirent(struct sess *sess, char *root, struct flist **fl, size_t *sz, size_t *max) { char *cargv[2], *cp; - int rc = 0, nxdev = 0, flag, i; + int rc = 0, flag; FTS *fts; FTSENT *ent; struct flist *f; - size_t flsz = 0, stripdir; - dev_t *xdev; + size_t i, flsz = 0, nxdev = 0, stripdir; + dev_t *newxdev, *xdev = NULL; struct stat st; cargv[0] = root; @@ -931,11 +931,6 @@ flist_gen_dirent(struct sess *sess, char *root, struct flist **fl, size_t *sz, !S_ISDIR(ent->fts_statp->st_mode)) continue; - if ((xdev = malloc(sizeof(dev_t))) == NULL) { - ERRX1("malloc"); - goto out; - } - flag = 0; for (i = 0; i < nxdev; i++) if (xdev[i] == ent->fts_statp->st_dev) { @@ -945,12 +940,12 @@ flist_gen_dirent(struct sess *sess, char *root, struct flist **fl, size_t *sz, if (flag) continue; - if (nxdev) - if ((xdev = realloc(xdev, sizeof(dev_t))) == - NULL) { - ERRX1("realloc"); - goto out; - } + if ((newxdev = reallocarray(xdev, nxdev + 1, + sizeof(dev_t))) == NULL) { + ERRX1("reallocarray"); + goto out; + } + xdev = newxdev; xdev[nxdev] = ent->fts_statp->st_dev; nxdev++; } @@ -1008,8 +1003,7 @@ flist_gen_dirent(struct sess *sess, char *root, struct flist **fl, size_t *sz, rc = 1; out: fts_close(fts); - if (sess->opts->one_file_system) - free(xdev); + free(xdev); return rc; } |