all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [PATCH manager 0/1] pve8to9: fix package lookup empty result check
@ 2026-03-31  0:41 Kefu Chai
  2026-03-31  0:41 ` [PATCH manager 1/1] " Kefu Chai
  0 siblings, 1 reply; 2+ messages in thread
From: Kefu Chai @ 2026-03-31  0:41 UTC (permalink / raw)
  To: pve-devel

I am new to Perl and noticed this while reading the code. I verified the
bug with a small test:

  perl -e '
    my $pkgs = [ grep { 0 } (1,2,3) ];
    print "Defined\n" if defined $pkgs;
    print "Zero\n"    if $pkgs == 0;
  '

Output:
  Defined

'$pkgs == 0' printed nothing -- the array reference is never numerically
zero, so the empty result check silently passed through even when the
grep returned no results.

Kefu Chai (1):
  pve8to9: fix package lookup empty result check

 PVE/CLI/pve8to9.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.47.3





^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH manager 1/1] pve8to9: fix package lookup empty result check
  2026-03-31  0:41 [PATCH manager 0/1] pve8to9: fix package lookup empty result check Kefu Chai
@ 2026-03-31  0:41 ` Kefu Chai
  0 siblings, 0 replies; 2+ messages in thread
From: Kefu Chai @ 2026-03-31  0:41 UTC (permalink / raw)
  To: pve-devel

The empty result guard used two conditions that are always false for an
array reference:

  if (!defined $pkgs || $pkgs == 0) {

'$pkgs' from '[grep {...} @list]' is always defined, and '$pkgs == 0'
numifies the reference (memory address), which is never zero. The
diagnostic log_fail message was therefore never emitted when a package
was not found in the version list.

Replace with '!@$pkgs' to correctly test whether the array is empty.

Signed-off-by: Kefu Chai <k.chai@proxmox.com>
---
 PVE/CLI/pve8to9.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/PVE/CLI/pve8to9.pm b/PVE/CLI/pve8to9.pm
index 0c4b2343..afc4785e 100644
--- a/PVE/CLI/pve8to9.pm
+++ b/PVE/CLI/pve8to9.pm
@@ -175,7 +175,7 @@ my $get_pkg = sub {
     }
 
     my $pkgs = [grep { $_->{Package} eq $pkg } @$versions];
-    if (!defined $pkgs || $pkgs == 0) {
+    if (!@$pkgs) {
         log_fail("unable to determine installed $pkg version.");
         return undef;
     } else {
-- 
2.47.3





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-03-31  0:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-31  0:41 [PATCH manager 0/1] pve8to9: fix package lookup empty result check Kefu Chai
2026-03-31  0:41 ` [PATCH manager 1/1] " Kefu Chai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal