[PATCH] Handle empty string passed to query_owner

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] Handle empty string passed to query_owner

Allan McRae
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 <[hidden email]>
---

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(-)

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
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Handle empty string passed to query_owner

Andrew Gregory
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 <[hidden email]>
> ---
>
> 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