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>
Signed-off-by: Allan McRae <allan@archlinux.org>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Xavier Chantry 2011-04-02 21:03:03 +02:00 committed by Dan McGee
parent a93e058b68
commit 21a881ec68

View file

@ -92,6 +92,16 @@ static int search_path(char **filename, struct stat *bufptr)
return(-1); return(-1);
} }
static void print_query_fileowner(const char *filename, pmpkg_t *info)
{
if (!config->quiet) {
printf(_("%s is owned by %s %s\n"), filename,
alpm_pkg_get_name(info), alpm_pkg_get_version(info));
} else {
printf("%s\n", alpm_pkg_get_name(info));
}
}
static int query_fileowner(alpm_list_t *targets) static int query_fileowner(alpm_list_t *targets)
{ {
int ret = 0; int ret = 0;
@ -156,17 +166,21 @@ static int query_fileowner(alpm_list_t *targets)
bname = mbasename(filename); bname = mbasename(filename);
dname = mdirname(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) {
if(!rpath && strcmp(dname, "") != 0) { pm_fprintf(stderr, PM_LOG_ERROR, _("cannot determine real path for '%s': %s\n"),
pm_fprintf(stderr, PM_LOG_ERROR, _("cannot determine real path for '%s': %s\n"), filename, strerror(errno));
filename, strerror(errno)); free(filename);
free(filename); free(dname);
free(dname); free(rpath);
free(rpath); ret++;
ret++; continue;
continue; }
} }
free(dname); free(dname);
@ -183,6 +197,13 @@ static int query_fileowner(alpm_list_t *targets)
continue; 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) { if(strlen(pkgfile) > max_length) {
pm_fprintf(stderr, PM_LOG_ERROR, _("path too long: %s%s\n"), root, pkgfile); pm_fprintf(stderr, PM_LOG_ERROR, _("path too long: %s%s\n"), root, pkgfile);
} }
@ -194,12 +215,7 @@ static int query_fileowner(alpm_list_t *targets)
free(pdname); free(pdname);
if(ppath && strcmp(ppath, rpath) == 0) { if(ppath && strcmp(ppath, rpath) == 0) {
if (!config->quiet) { print_query_fileowner(filename, info);
printf(_("%s is owned by %s %s\n"), filename,
alpm_pkg_get_name(info), alpm_pkg_get_version(info));
} else {
printf("%s\n", alpm_pkg_get_name(info));
}
found = 1; found = 1;
} }
free(ppath); free(ppath);