mirror of
https://github.com/systemd/systemd.git
synced 2025-03-19 22:50:17 +03:00
hostnamed: when parsing day/month of firmware date, force decimal parsing
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.
This commit is contained in:
parent
c65c2f0aa6
commit
7dad6de158
@ -307,20 +307,20 @@ static int get_firmware_date(usec_t *ret) {
|
||||
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)
|
||||
|
@ -119,9 +119,9 @@ EOF
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user