aboutsummaryrefslogtreecommitdiffstats
path: root/src/fcopy
diff options
context:
space:
mode:
authorLibravatar Simo Piiroinen <simo.piiroinen@jolla.com>2020-12-10 13:55:25 +0200
committerLibravatar Tomi Leppänen <tomi.leppanen@jolla.com>2021-02-19 09:38:54 +0200
commiteeec209467bbfbf6d6bd138246e1c8d184b4c817 (patch)
treebd153b2e2deb1410bbc169d712fd16da31e000ca /src/fcopy
parentFix symlinks that go though /proc/self (diff)
downloadfirejail-eeec209467bbfbf6d6bd138246e1c8d184b4c817.tar.gz
firejail-eeec209467bbfbf6d6bd138246e1c8d184b4c817.tar.zst
firejail-eeec209467bbfbf6d6bd138246e1c8d184b4c817.zip
fcopy: Fix memory leaks
These have little consequences as the tool exits anyway, but fs_copydir() leaks memory on success path and check() on failure path. Signed-off-by: Simo Piiroinen <simo.piiroinen@jolla.com> Signed-off-by: Tomi Leppänen <tomi.leppanen@jolla.com>
Diffstat (limited to 'src/fcopy')
-rw-r--r--src/fcopy/main.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/fcopy/main.c b/src/fcopy/main.c
index a41df52a1..d863b537b 100644
--- a/src/fcopy/main.c
+++ b/src/fcopy/main.c
@@ -268,16 +268,14 @@ static int fs_copydir(const char *infname, const struct stat *st, int ftype, str
268 first = 0; 268 first = 0;
269 else if (!arg_quiet) 269 else if (!arg_quiet)
270 fprintf(stderr, "Warning fcopy: skipping %s, file already present\n", infname); 270 fprintf(stderr, "Warning fcopy: skipping %s, file already present\n", infname);
271 free(outfname); 271 goto out;
272 return 0;
273 } 272 }
274 273
275 // extract mode and ownership 274 // extract mode and ownership
276 if (stat(infname, &s) != 0) { 275 if (stat(infname, &s) != 0) {
277 if (!arg_quiet) 276 if (!arg_quiet)
278 fprintf(stderr, "Warning fcopy: skipping %s, cannot find inode\n", infname); 277 fprintf(stderr, "Warning fcopy: skipping %s, cannot find inode\n", infname);
279 free(outfname); 278 goto out;
280 return 0;
281 } 279 }
282 uid_t uid = s.st_uid; 280 uid_t uid = s.st_uid;
283 gid_t gid = s.st_gid; 281 gid_t gid = s.st_gid;
@@ -287,8 +285,7 @@ static int fs_copydir(const char *infname, const struct stat *st, int ftype, str
287 if ((s.st_size + size_cnt) > copy_limit) { 285 if ((s.st_size + size_cnt) > copy_limit) {
288 fprintf(stderr, "Error fcopy: size limit of %lu MB reached\n", (copy_limit / 1024) / 1024); 286 fprintf(stderr, "Error fcopy: size limit of %lu MB reached\n", (copy_limit / 1024) / 1024);
289 size_limit_reached = 1; 287 size_limit_reached = 1;
290 free(outfname); 288 goto out;
291 return 0;
292 } 289 }
293 290
294 file_cnt++; 291 file_cnt++;
@@ -303,7 +300,8 @@ static int fs_copydir(const char *infname, const struct stat *st, int ftype, str
303 else if (ftype == FTW_SL) { 300 else if (ftype == FTW_SL) {
304 copy_link(infname, outfname, mode, uid, gid); 301 copy_link(infname, outfname, mode, uid, gid);
305 } 302 }
306 303out:
304 free(outfname);
307 return(0); 305 return(0);
308} 306}
309 307
@@ -336,6 +334,7 @@ static char *check(const char *src) {
336 return rsrc; // normal exit from the function 334 return rsrc; // normal exit from the function
337 335
338errexit: 336errexit:
337 free(rsrc);
339 fprintf(stderr, "Error fcopy: invalid file %s\n", src); 338 fprintf(stderr, "Error fcopy: invalid file %s\n", src);
340 exit(1); 339 exit(1);
341} 340}