From dffc624b37ea29056f6788ac9b424b67c897a980 Mon Sep 17 00:00:00 2001 From: nekral-guest Date: Sun, 5 Sep 2010 15:34:42 +0000 Subject: [PATCH] Integrate review comments from Julien Cristau * libmisc/copydir.c: Missing parenthesis in comment. * libmisc/chowndir.c: Fixed memory leak on failed realloc(). * libmisc/chowndir.c: Make sure the buffer for the path is large enough. * libmisc/remove_tree.c: Remove check for NULL before free(). --- ChangeLog | 9 +++++++++ libmisc/chowndir.c | 11 +++++++---- libmisc/copydir.c | 2 +- libmisc/remove_tree.c | 4 +--- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 24dc6bb4..69acbf19 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-09-05 Nicolas François + + Integrate review comments from Julien Cristau + * libmisc/copydir.c: Missing parenthesis in comment. + * libmisc/chowndir.c: Fixed memory leak on failed realloc(). + * libmisc/chowndir.c: Make sure the buffer for the path is large + enough. + * libmisc/remove_tree.c: Remove check for NULL before free(). + 2010-08-29 Nicolas François * man/po/fr.po: Fix 2 fuzzy strings. diff --git a/libmisc/chowndir.c b/libmisc/chowndir.c index b2973509..e2469af6 100644 --- a/libmisc/chowndir.c +++ b/libmisc/chowndir.c @@ -96,6 +96,7 @@ int chown_tree (const char *root, } while ((ent = readdir (dir))) { + size_t ent_name_len; uid_t tmpuid = (uid_t) -1; gid_t tmpgid = (gid_t) -1; @@ -113,13 +114,15 @@ int chown_tree (const char *root, * destination files. */ - if (strlen (root) + strlen (ent->d_name) + 2 > new_name_len) { - new_name = realloc (new_name, new_name_len + 1024); - if (NULL == new_name) { + ent_name_len = strlen (root) + strlen (ent->d_name) + 2; + if (ent_name_len > new_name_len) { + char *tmp = realloc (new_name, ent_name_len); + if (NULL == tmp) { rc = -1; break; } - new_name_len += 1024; + new_name = tmp; + new_name_len = ent_name_len; } (void) snprintf (new_name, new_name_len, "%s/%s", root, ent->d_name); diff --git a/libmisc/copydir.c b/libmisc/copydir.c index 85155ae4..5c6c0594 100644 --- a/libmisc/copydir.c +++ b/libmisc/copydir.c @@ -273,7 +273,7 @@ static /*@exposed@*/ /*@null@*/struct link_name *check_link (const char *name, c * as it goes. * * When reset_selinux is enabled, extended attributes (and thus - * SELinux attributes are not copied. + * SELinux attributes) are not copied. * * old_uid and new_uid are used to set the ownership of the copied * files. Unless old_uid is set to -1, only the files owned by diff --git a/libmisc/remove_tree.c b/libmisc/remove_tree.c index a1be00eb..b2794ab4 100644 --- a/libmisc/remove_tree.c +++ b/libmisc/remove_tree.c @@ -88,9 +88,7 @@ int remove_tree (const char *root, bool remove_root) * Make the filename for the current entry. */ - if (NULL != new_name) { - free (new_name); - } + free (new_name); new_name = (char *) malloc (new_len); if (NULL == new_name) { err = -1;