From 8539b8cebd825bde8edb4861b3f497912d2da05a Mon Sep 17 00:00:00 2001 From: martijn Date: Tue, 20 Feb 2024 12:41:13 +0000 Subject: [PATCH] strptime() only touches the fields specified in the format string, meaning there could be garbage left in the other fields. Somehow this only caused issues in mktime() when /etc/localtime is set to GMT. Initialize tm to 0. While here fix a type-O in the format string and make the invalid strlen for LAST-UPDATED message more consistent with the other 2 error messages. Found by and OK sthen@ --- usr.sbin/snmpd/mib.y | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/usr.sbin/snmpd/mib.y b/usr.sbin/snmpd/mib.y index 5e18dbecc3b..ae33b64280f 100644 --- a/usr.sbin/snmpd/mib.y +++ b/usr.sbin/snmpd/mib.y @@ -1,4 +1,4 @@ -/* $OpenBSD: mib.y,v 1.1 2024/01/27 09:53:59 martijn Exp $ */ +/* $OpenBSD: mib.y,v 1.2 2024/02/20 12:41:13 martijn Exp $ */ /* * Copyright (c) 2023 Martijn van Duren @@ -496,7 +496,7 @@ moduleidentity : descriptor MODULEIDENTITY lastupdated lastupdated : LASTUPDATED TEXT { char timebuf[14] = ""; - struct tm tm; + struct tm tm = {}; size_t len; if ((len = strlen($2)) == 11) @@ -505,11 +505,11 @@ lastupdated : LASTUPDATED TEXT { else if (len == 13) strlcpy(timebuf, $2, sizeof(timebuf)); else { - yyerror("Invalid LAST-UPDATED"); + yyerror("Invalid LAST-UPDATED: %s", $2); YYERROR; } - if (strptime(timebuf, "%Y%M%d%H%MZ", &tm) == NULL) { + if (strptime(timebuf, "%Y%m%d%H%MZ", &tm) == NULL) { yyerror("Invalid LAST-UPDATED: %s", $2); YYERROR; } -- 2.20.1