[parted-devel] [PATCH 4/5] fdasd: Make sure data set name is positive

Brian C. Lane bcl at redhat.com
Mon Sep 14 19:10:03 BST 2026


Passing a negative value, eg. PART-999, to atoi could result in passing
a negative value to the setpos call when it writes f1_counter.

This adds an exception check to ensure the result of the atoi is always
positive, and it preserves the rest of the logic which depends on n being
1 less than the value.
---
 libparted/labels/fdasd.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libparted/labels/fdasd.c b/libparted/labels/fdasd.c
index cee4d461..ea00e664 100644
--- a/libparted/labels/fdasd.c
+++ b/libparted/labels/fdasd.c
@@ -18,6 +18,7 @@
 
 #include <config.h>
 #include <arch/linux.h>
+#include <parted/debug.h>
 #include <parted/vtoc.h>
 #include <parted/device.h>
 #include <parted/fdasd.h>
@@ -697,7 +698,9 @@ fdasd_process_valid_vtoc (fdasd_anchor_t * anc, unsigned long b, int fd)
 				if (ch != NULL) {
 					strncpy (s, ch + 4, 4);
 					s[4] = '\0';
-					n = atoi (s) - 1;
+					n = atoi (s);
+                                        PED_ASSERT (n >= 0);
+                                        n = n - 1;
 				}
 
 				vtoc_ebcdic_enc (p->f1->DS1DSNAM, p->f1->DS1DSNAM, 44);
-- 
2.55.0




More information about the parted-devel mailing list