Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   ArchLinux Pacman Development (http://www.linux-archive.org/archlinux-pacman-development/)
-   -   pacman/query: correctly handle root files with -Qo (http://www.linux-archive.org/archlinux-pacman-development/509012-pacman-query-correctly-handle-root-files-qo.html)

Xavier Chantry 04-02-2011 07:03 PM

pacman/query: correctly handle root files with -Qo
 
spotted by clang-analyzer (strcmp with NULL rpath is bad)

Signed-off-by: Xavier Chantry <chantry.xavier@gmail.com>
---
src/pacman/query.c | 50 +++++++++++++++++++++++++++++++++-----------------
1 files changed, 33 insertions(+), 17 deletions(-)

diff --git a/src/pacman/query.c b/src/pacman/query.c
index d2bfe69..d27044e 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -92,6 +92,16 @@ static int search_path(char **filename, struct stat *bufptr)
return -1;
}

+static void print_query_fileowner(const char *filename, pmpkg_t *info)
+{
+ if (!config->quiet) {
+ printf(_("%s is owned by %s %s
"), filename,
+ alpm_pkg_get_name(info), alpm_pkg_get_version(info));
+ } else {
+ printf("%s
", alpm_pkg_get_name(info));
+ }
+}
+
static int query_fileowner(alpm_list_t *targets)
{
int ret = 0;
@@ -156,17 +166,21 @@ static int query_fileowner(alpm_list_t *targets)

bname = mbasename(filename);
dname = mdirname(filename);
- rpath = resolve_path(dname);
+ /* for files in '/', there is no directory name to match */
+ if (strcmp(dname, "") == 0) {
+ rpath = NULL;
+ } else {
+ rpath = resolve_path(dname);

- /* this odd conditional is to ensure files in '/' can be checked */
- if(!rpath && strcmp(dname, "") != 0) {
- pm_fprintf(stderr, PM_LOG_ERROR, _("cannot determine real path for '%s': %s
"),
- filename, strerror(errno));
- free(filename);
- free(dname);
- free(rpath);
- ret++;
- continue;
+ if(!rpath) {
+ pm_fprintf(stderr, PM_LOG_ERROR, _("cannot determine real path for '%s': %s
"),
+ filename, strerror(errno));
+ free(filename);
+ free(dname);
+ free(rpath);
+ ret++;
+ continue;
+ }
}
free(dname);

@@ -183,6 +197,13 @@ static int query_fileowner(alpm_list_t *targets)
continue;
}

+ /* for files in '/', there is no directory name to match */
+ if(!rpath) {
+ print_query_fileowner(filename, info);
+ found = 1;
+ continue;
+ }
+
if(strlen(pkgfile) > max_length) {
pm_fprintf(stderr, PM_LOG_ERROR, _("path too long: %s%s
"), root, pkgfile);
}
@@ -194,12 +215,7 @@ static int query_fileowner(alpm_list_t *targets)
free(pdname);

if(ppath && strcmp(ppath, rpath) == 0) {
- if (!config->quiet) {
- printf(_("%s is owned by %s %s
"), filename,
- alpm_pkg_get_name(info), alpm_pkg_get_version(info));
- } else {
- printf("%s
", alpm_pkg_get_name(info));
- }
+ print_query_fileowner(filename, info);
found = 1;
}
free(ppath);
--
1.7.4.2

Allan McRae 04-10-2011 11:15 AM

pacman/query: correctly handle root files with -Qo
 
On 03/04/11 05:03, Xavier Chantry wrote:

spotted by clang-analyzer (strcmp with NULL rpath is bad)

Signed-off-by: Xavier Chantry<chantry.xavier@gmail.com>


Signed-off-by: Allan


All times are GMT. The time now is 10:14 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.