FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 08-11-2012, 09:35 PM
Andrew Gregory
 
Default query_fileowner, mdirname: add error checks

Also consolidates cleanup for query_fileowner.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
---
src/pacman/query.c | 28 ++++++++++++++--------------
src/pacman/util.c | 5 ++++-
2 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/src/pacman/query.c b/src/pacman/query.c
index b1e51a6..9afe680 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -129,14 +129,16 @@ static int query_fileowner(alpm_list_t *targets)
db_local = alpm_get_localdb(config->handle);

for(t = targets; t; t = alpm_list_next(t)) {
- char *filename, *dname, *rpath;
+ char *filename = NULL, *dname = NULL, *rpath = NULL;
const char *bname;
struct stat buf;
alpm_list_t *i;
size_t len;
int found = 0;

- filename = strdup(t->data);
+ if((filename = strdup(t->data)) == NULL) {
+ goto targcleanup;
+ }

/* trailing '/' causes lstat to dereference directory symlinks */
len = strlen(filename) - 1;
@@ -150,25 +152,19 @@ static int query_fileowner(alpm_list_t *targets)
if(search_path(&filename, &buf) == -1) {
pm_printf(ALPM_LOG_ERROR, _("failed to find '%s' in PATH: %s
"),
filename, strerror(errno));
- ret++;
- free(filename);
- continue;
+ goto targcleanup;
}
} else {
pm_printf(ALPM_LOG_ERROR, _("failed to read file '%s': %s
"),
filename, strerror(errno));
- ret++;
- free(filename);
- continue;
+ goto targcleanup;
}
}

if(S_ISDIR(buf.st_mode)) {
pm_printf(ALPM_LOG_ERROR,
_("cannot determine ownership of directory '%s'
"), filename);
- ret++;
- free(filename);
- continue;
+ goto targcleanup;
}

bname = mbasename(filename);
@@ -180,7 +176,6 @@ static int query_fileowner(alpm_list_t *targets)
filename, strerror(errno));
goto targcleanup;
}
- free(dname);

for(i = alpm_db_get_pkgcache(db_local); i && !found; i = alpm_list_next(i)) {
alpm_pkg_t *info = i->data;
@@ -199,6 +194,7 @@ static int query_fileowner(alpm_list_t *targets)

/* concatenate our file and the root path */
if(rootlen + 1 + strlen(pkgfile) > PATH_MAX) {
+ path[rootlen] = ''; /* reset path for error message */
pm_printf(ALPM_LOG_ERROR, _("path too long: %s%s
"), path, pkgfile);
continue;
}
@@ -207,11 +203,10 @@ static int query_fileowner(alpm_list_t *targets)
pdname = mdirname(path);
ppath = realpath(pdname, NULL);
free(pdname);
- path[rootlen] = ''; /* reset path for error messages */

if(!ppath) {
pm_printf(ALPM_LOG_ERROR, _("cannot determine real path for '%s': %s
"),
- pdname, strerror(errno));
+ path, strerror(errno));
continue;
}

@@ -226,10 +221,15 @@ static int query_fileowner(alpm_list_t *targets)
}
if(!found) {
pm_printf(ALPM_LOG_ERROR, _("No package owns %s
"), filename);
+ }
+
+targcleanup:
+ if(!found) {
ret++;
}
free(filename);
free(rpath);
+ free(dname);
}

return ret;
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 2d1b762..ba7a8c0 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -239,7 +239,10 @@ char *mdirname(const char *path)
return strdup(".");
}

- ret = strdup(path);
+ if((ret = strdup(path)) == NULL) {
+ return NULL;
+ }
+
last = strrchr(ret, '/');

if(last != NULL) {
--
1.7.11.4
 
Old 08-27-2012, 07:24 AM
Allan McRae
 
Default query_fileowner, mdirname: add error checks

On 12/08/12 07:35, Andrew Gregory wrote:
> Also consolidates cleanup for query_fileowner.
>
> Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
> ---
> src/pacman/query.c | 28 ++++++++++++++--------------
> src/pacman/util.c | 5 ++++-
> 2 files changed, 18 insertions(+), 15 deletions(-)
>

<snip>

> diff --git a/src/pacman/util.c b/src/pacman/util.c
> index 2d1b762..ba7a8c0 100644
> --- a/src/pacman/util.c
> +++ b/src/pacman/util.c
> @@ -239,7 +239,10 @@ char *mdirname(const char *path)
> return strdup(".");
> }
>
> - ret = strdup(path);
> + if((ret = strdup(path)) == NULL) {
> + return NULL;

Whitespace error. Fixed on my working branch.

> + }
> +
> last = strrchr(ret, '/');
>
> if(last != NULL) {
>
 

Thread Tools




All times are GMT. The time now is 07:23 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org