From: Paul Eggert Date: Mon, 31 Jan 2022 18:20:21 +0000 (-0800) Subject: dd: do not access uninitialized X-Git-Tag: v9.1~78 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=604f8a6c4d58a646c8722fdf7cad9ee67479d8f7;p=thirdparty%2Fcoreutils.git dd: do not access uninitialized * src/dd.c (parse_integer): Avoid undefined behavior that accesses an uninitialized ā€˜n’ when e == LONGINT_INVALID. Return more-accurate error code when INTMAX_MAX < n. --- diff --git a/src/dd.c b/src/dd.c index e55f87f149..7360a49738 100644 --- a/src/dd.c +++ b/src/dd.c @@ -1427,8 +1427,10 @@ static intmax_t parse_integer (char const *str, strtol_error *invalid) { /* Call xstrtoumax, not xstrtoimax, since we don't want to - allow strings like " -0". */ - uintmax_t n; + allow strings like " -0". Initialize N to an interminate value; + calling code should not rely on this function returning 0 + when *INVALID represents a non-overflow error. */ + uintmax_t n = 0; char *suffix; strtol_error e = xstrtoumax (str, &suffix, 10, &n, "bcEGkKMPTwYZ0"); @@ -1468,7 +1470,7 @@ parse_integer (char const *str, strtol_error *invalid) if (INTMAX_MAX < n) { - *invalid = LONGINT_OVERFLOW; + *invalid = e | LONGINT_OVERFLOW; return INTMAX_MAX; }