[PATCH] virFindFileInPath: Don't pass NULL to g_canonicalize_filename()

Michal Privoznik posted 1 patch 2 years, 10 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/ad438aa380e31fec220c0cdb383f7f144371b367.1623773149.git.mprivozn@redhat.com
src/util/virfile.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] virFindFileInPath: Don't pass NULL to g_canonicalize_filename()
Posted by Michal Privoznik 2 years, 10 months ago
If given file is not found in $PATH then g_find_program_in_path()
returns NULL. However, g_canonicalize_filename() does not accept
NULL as input.

Fixes: 65c2901906b5e2d707f9184ff3719a5375bab427
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/util/virfile.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/util/virfile.c b/src/util/virfile.c
index c302202573..4f98b011be 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -1667,6 +1667,8 @@ virFindFileInPath(const char *file)
         return NULL;
 
     path = g_find_program_in_path(file);
+    if (!path)
+        return NULL;
 
     /* Workaround for a bug in g_find_program_in_path() not returning absolute
      * path as documented.  This has been fixed in
-- 
2.31.1

Re: [PATCH] virFindFileInPath: Don't pass NULL to g_canonicalize_filename()
Posted by Peter Krempa 2 years, 10 months ago
On Tue, Jun 15, 2021 at 18:05:49 +0200, Michal Privoznik wrote:
> If given file is not found in $PATH then g_find_program_in_path()
> returns NULL. However, g_canonicalize_filename() does not accept
> NULL as input.
> 
> Fixes: 65c2901906b5e2d707f9184ff3719a5375bab427
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/util/virfile.c | 2 ++
>  1 file changed, 2 insertions(+)

Reviewed-by: Peter Krempa <pkrempa@redhat.com>