← Commit list

b8cf04888

Denys Vlasenko
Denys Vlasenko
2025-11-08
SUCCESS Duration: 159s

Subject

dd: fix overflow for very large count/seek/skip values

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0
gcc -Wp,-MD,applets/.usage.d -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer      -Iinclude -Iinclude -o applets/usage applets/usage.c

Build Log

(log yok)

Commit Diff GitHub →

coreutils/dd.c+3 -9
@@ -272,12 +272,6 @@ static bool write_and_stats(const void *buf, size_t len, size_t obs,
return 1;
}
-#if ENABLE_LFS
-# define XATOU_SFX xatoull_sfx
-#else
-# define XATOU_SFX xatoul_sfx
-#endif
-
#if ENABLE_FEATURE_DD_IBS_OBS
static int parse_comma_flags(char *val, const char *words, const char *error_in)
{
@@ -457,15 +451,15 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
/* These can be large: */
if (what == OP_count) {
G.flags |= FLAG_COUNT;
- count = XATOU_SFX(val, cwbkMG_suffixes);
+ count = XATOOFF_SFX(val, cwbkMG_suffixes);
/*continue;*/
}
if (what == OP_seek) {
- seek = XATOU_SFX(val, cwbkMG_suffixes);
+ seek = XATOOFF_SFX(val, cwbkMG_suffixes);
/*continue;*/
}
if (what == OP_skip) {
- skip = XATOU_SFX(val, cwbkMG_suffixes);
+ skip = XATOOFF_SFX(val, cwbkMG_suffixes);
/*continue;*/
}
if (what == OP_if) {
include/libbb.h+4 -0
@@ -290,6 +290,7 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
/* "long" is long enough on this system */
typedef unsigned long uoff_t;
# define XATOOFF(a) xatoul_range((a), 0, LONG_MAX)
+# define XATOOFF_SFX(a, s) xatoul_range_sfx((a), 0, LONG_MAX, s)
/* usage: sz = BB_STRTOOFF(s, NULL, 10); if (errno || sz < 0) die(); */
# define BB_STRTOOFF bb_strtoul
# define STRTOOFF strtoul
@@ -299,6 +300,7 @@ typedef unsigned long uoff_t;
/* "long" is too short, need "long long" */
typedef unsigned long long uoff_t;
# define XATOOFF(a) xatoull_range((a), 0, LLONG_MAX)
+# define XATOOFF_SFX(a, s) xatoull_range_sfx((a), 0, LLONG_MAX, s)
# define BB_STRTOOFF bb_strtoull
# define STRTOOFF strtoull
# define OFF_FMT "ll"
@@ -314,12 +316,14 @@ typedef unsigned long long uoff_t;
# if UINT_MAX == ULONG_MAX
typedef unsigned long uoff_t;
# define XATOOFF(a) xatoi_positive(a)
+# define XATOOFF_SFX(a, s) xatoul_range_sfx((a), 0, INT_MAX, s)
# define BB_STRTOOFF bb_strtou
# define STRTOOFF strtol
# define OFF_FMT "l"
# else
typedef unsigned long uoff_t;
# define XATOOFF(a) xatoul_range((a), 0, LONG_MAX)
+# define XATOOFF_SFX(a, s) xatoul_range_sfx((a), 0, LONG_MAX, s)
# define BB_STRTOOFF bb_strtoul
# define STRTOOFF strtol
# define OFF_FMT "l"