From: Karel Zak Date: Tue, 19 May 2026 07:49:32 +0000 (+0200) Subject: libblkid: (dasd) use rtrim_whitespace() for EBCDIC string trimming X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=77d06080d94ffd7e9c1154a43cd888cafe52e535;p=thirdparty%2Futil-linux.git libblkid: (dasd) use rtrim_whitespace() for EBCDIC string trimming Replace hand-rolled trailing-space trim loops in dasd_get_volser() and dasd_get_dsnam() with rtrim_whitespace() from strutils.h. The original dasd_get_volser() loop had no lower-bound guard and would read out-of-bounds if all VOLSER bytes were spaces. Addresses: https://github.com/util-linux/util-linux/pull/4096 Signed-off-by: Karel Zak --- diff --git a/libblkid/src/partitions/dasd.c b/libblkid/src/partitions/dasd.c index 501a603f7..969944d2c 100644 --- a/libblkid/src/partitions/dasd.c +++ b/libblkid/src/partitions/dasd.c @@ -17,32 +17,29 @@ #include #include "pt-dasd.h" +#include "strutils.h" #include "partitions.h" static void dasd_get_volser(const char *volid, char *volser) { - int i = 0; + int i; for (i = 0; i < DASD_VOLSER_LENGTH; i++) volser[i] = dasd_ebcdic_to_ascii[(unsigned char) volid[i]]; volser[DASD_VOLSER_LENGTH] = '\0'; - /* trim trailing spaces */ - for (i = DASD_VOLSER_LENGTH - 1; volser[i] == ' '; i--) - volser[i] = '\0'; + rtrim_whitespace((unsigned char *) volser); } static void dasd_get_dsnam(const struct dasd_format1_label *f1, char *dsnam) { - size_t i = 0; + size_t i; for (i = 0; i < sizeof(f1->DS1DSNAM); i++) dsnam[i] = dasd_ebcdic_to_ascii[(unsigned char) f1->DS1DSNAM[i]]; dsnam[sizeof(f1->DS1DSNAM)] = '\0'; - /* trim trailing spaces */ - for (i = sizeof(f1->DS1DSNAM) - 1; i != 0 && dsnam[i] == ' '; i--) - dsnam[i] = '\0'; + rtrim_whitespace((unsigned char *) dsnam); } /*