]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
scsi_id: use safe_atoi() instead of plain atoi()
authorFrantisek Sumsal <frantisek@sumsal.cz>
Thu, 16 Apr 2026 13:55:10 +0000 (15:55 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 22 May 2026 12:32:04 +0000 (13:32 +0100)
(cherry picked from commit 5853d0a53378ed973d8c006531846717ae55090a)

src/udev/scsi_id/scsi_id.c

index 6a31f9c4c8ebd6b773966e251d639e32080e5413..ba7a7fe5f522def1bbefcffd5f910ba7d629d0cd 100644 (file)
@@ -15,6 +15,7 @@
 #include "extract-word.h"
 #include "fd-util.h"
 #include "fileio.h"
+#include "parse-util.h"
 #include "scsi_id.h"
 #include "string-util.h"
 #include "strv.h"
@@ -234,7 +235,7 @@ static void help(void) {
 
 static int set_options(int argc, char **argv,
                        char *maj_min_dev) {
-        int option;
+        int option, r;
 
         /*
          * optind is a global extern used by getopt. Since we can call
@@ -279,7 +280,11 @@ static int set_options(int argc, char **argv,
                         break;
 
                 case 's':
-                        sg_version = atoi(optarg);
+                        r = safe_atoi(optarg, &sg_version);
+                        if (r < 0)
+                                return log_error_errno(r,
+                                                       "Invalid SG version '%s'",
+                                                       optarg);
                         if (sg_version < 3 || sg_version > 4)
                                 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
                                                        "Unknown SG version '%s'",