diff mbox

[pacman-dev] Handle empty string passed to query_owner

Message ID 20170509054631.6604-1-allan@archlinux.org
State Superseded, archived
Delegated to: Andrew Gregory
Headers show

Commit Message

Allan McRae May 9, 2017, 5:46 a.m. UTC
Passing an empty string to pacman -Qo results in:
error: No package owns <first directory in $PATH>

Treat an empty string being passed the same as recieving a NULL value
and exit searching for an owner.

Signed-off-by: Allan McRae <allan@archlinux.org>
---

Running 'pacman -Qo ""' will now just exit pacman. I'm not sure if we
need an error/warning message for this case.

 src/pacman/query.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Andrew Gregory May 10, 2017, 10:18 p.m. UTC | #1
On 05/09/17 at 03:46pm, Allan McRae wrote:
> Passing an empty string to pacman -Qo results in:
> error: No package owns <first directory in $PATH>
> 
> Treat an empty string being passed the same as recieving a NULL value
> and exit searching for an owner.
> 
> Signed-off-by: Allan McRae <allan@archlinux.org>
> ---
> 
> Running 'pacman -Qo ""' will now just exit pacman. I'm not sure if we
> need an error/warning message for this case.

I don't think we should ever fail silently.  I would include an error
the same as any other path we can't resolve.

>  src/pacman/query.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/src/pacman/query.c b/src/pacman/query.c
> index a8417570..119764bc 100644
> --- a/src/pacman/query.c
> +++ b/src/pacman/query.c
> @@ -161,7 +161,8 @@ static int query_fileowner(alpm_list_t *targets)
>  		size_t len, is_dir;
>  		unsigned int found = 0;
>  
> -		if((filename = strdup(t->data)) == NULL) {
> +		filename = strdup(t->data);
> +		if(filename == NULL || strcmp(filename, "") == 0) {
>  			goto targcleanup;
>  		}
>  
> -- 
> 2.12.2
diff mbox

Patch

diff --git a/src/pacman/query.c b/src/pacman/query.c
index a8417570..119764bc 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -161,7 +161,8 @@  static int query_fileowner(alpm_list_t *targets)
 		size_t len, is_dir;
 		unsigned int found = 0;
 
-		if((filename = strdup(t->data)) == NULL) {
+		filename = strdup(t->data);
+		if(filename == NULL || strcmp(filename, "") == 0) {
 			goto targcleanup;
 		}