From: Paul Eggert Date: Mon, 30 Jun 2025 05:25:28 +0000 (-0700) Subject: od: more minor fixes for offsets X-Git-Tag: v9.8~261 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9002c04ccc51c753ef801d141810932ca9de41f3;p=thirdparty%2Fcoreutils.git od: more minor fixes for offsets * src/od.c (parse_old_offset): Reject invalid offsets like "++0". Treat overflowing offsets as errors, not as file names. --- diff --git a/src/od.c b/src/od.c index 8acf205e1d..918d56725a 100644 --- a/src/od.c +++ b/src/od.c @@ -1409,18 +1409,20 @@ xstr2nonneg (char const *restrict nptr, int base, intmax_t *val, return s_err != LONGINT_INVALID && *val < 0 ? LONGINT_INVALID : s_err; } -/* If S is a valid traditional offset specification with an optional - leading '+' return true and set *OFFSET to the offset it denotes. - Otherwise return false and possibly set *OFFSET. */ +/* If STR is a valid traditional offset specification with an optional + leading '+', and can be represented in intmax_t, return true and + set *OFFSET to the offset it denotes. If it is valid but cannot be + represented, diagnose the problem and exit. Otherwise return false + and possibly set *OFFSET. */ static bool -parse_old_offset (char *s, intmax_t *offset) +parse_old_offset (char *str, intmax_t *offset) { - if (*s == '\0') - return false; - /* Skip over any leading '+'. */ - s += s[0] == '+'; + char *s = str + (str[0] == '+'); + + if (! c_isdigit (s[0])) + return false; /* Determine the radix for S. If there is a '.', followed first by optional 'b' or (undocumented) 'B' and then by end of string, @@ -1447,6 +1449,8 @@ parse_old_offset (char *s, intmax_t *offset) dot[0] = '.'; } + if (s_err == LONGINT_OVERFLOW) + error (EXIT_FAILURE, ERANGE, "%s", quotearg_colon (str)); return s_err == LONGINT_OK; }