Skip to content

Commit 8c56f73

Browse files
authored
Fix regression (#119)
* Fix regression with symlink paths
1 parent e5f1516 commit 8c56f73

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

check_smart.pl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,15 @@
6868
# Dec 15, 2025: Philippe Beaumont - Add areca devices (6.17.0)
6969
# Apr 21, 2026: Claudio Kuenzler - Fix sys path for sudo command. Detect NVME input/output error (6.18.0)
7070
# Apr 24, 2026: Claudio Kuenzler - Fix command injection vulnerability in interface parameter (6.18.1)
71+
# May 9, 2026: Claudio Kuenzler - Fix regression with symlink paths (6.18.2)
7172

7273
use strict;
7374
use Getopt::Long;
7475
use File::Basename qw(basename);
76+
use Cwd qw(abs_path);
7577

7678
my $basename = basename($0);
77-
my $revision = '6.18.1';
79+
my $revision = '6.18.2';
7880

7981
# Standard Nagios return codes
8082
my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
@@ -160,7 +162,14 @@
160162
foreach my $opt_dl (@dev){
161163
warn "(debug) Found $opt_dl\n" if $opt_debug;
162164
if (-l $opt_dl) {
163-
warn "(debug) $opt_dl is a symlink, skipping for security reasons\n" if $opt_debug;
165+
# Resolve symlink and use the real path to prevent command injection
166+
my $real_path = abs_path($opt_dl);
167+
if (defined($real_path) && (-b $real_path || -c $real_path)) {
168+
warn "(debug) $opt_dl is a symlink to block device $real_path, using resolved path\n" if $opt_debug;
169+
$device .= $real_path."|";
170+
} else {
171+
warn "(debug) $opt_dl is a symlink not pointing to a valid block device, skipping\n" if $opt_debug;
172+
}
164173
} elsif (-b $opt_dl || -c $opt_dl || $opt_dl =~ m/^\/dev\/bus\/\d$/) {
165174
$device .= $opt_dl."|";
166175
} else {

0 commit comments

Comments
 (0)