safe_atou() by default determines the base from the prefix 0x, 0b, 0o
and for compat with just 0 for octal. This is not what we want here,
since the date components are padded with zeroes yet still decimal.
Hence force decimal parsing (and while we are at it, prohibit a couple
of unexpected decorations).
WIthout this we'd fail to parse any the 8th and 9th day of each months, as
well aus aug and september of every year, because these look like octal
numbers but cannot actually parsed as such.
Let's change the testcase to check for a date that exposes this
bheaviour.
return -EINVAL;
unsigned m, d, y;
- r = safe_atou(month, &m);
+ r = safe_atou_full(month, 10 | SAFE_ATO_REFUSE_PLUS_MINUS | SAFE_ATO_REFUSE_LEADING_WHITESPACE, &m);
if (r < 0)
return r;
if (m < 1 || m > 12)
return -EINVAL;
m -= 1;
- r = safe_atou(day, &d);
+ r = safe_atou_full(day, 10 | SAFE_ATO_REFUSE_PLUS_MINUS | SAFE_ATO_REFUSE_LEADING_WHITESPACE, &d);
if (r < 0)
return r;
if (d < 1 || d > 31)
return -EINVAL;
- r = safe_atou(year, &y);
+ r = safe_atou_full(year, 10 | SAFE_ATO_REFUSE_PLUS_MINUS | SAFE_ATO_REFUSE_LEADING_WHITESPACE, &y);
if (r < 0)
return r;
if (y < 1970 || y > (unsigned) INT_MAX)
mount -t tmpfs none /sys/class/dmi/id
echo '1' >/sys/class/dmi/id/uevent
- echo '01/01/2000' >/sys/class/dmi/id/bios_date
+ echo '09/08/2000' >/sys/class/dmi/id/bios_date
systemctl stop systemd-hostnamed
- assert_in '2000-01-01' "$(hostnamectl)"
+ assert_in '2000-09-08' "$(hostnamectl)"
echo '2022' >/sys/class/dmi/id/bios_date
systemctl stop systemd-hostnamed