strptime() only touches the fields specified in the format string,
authormartijn <martijn@openbsd.org>
Tue, 20 Feb 2024 12:41:13 +0000 (12:41 +0000)
committermartijn <martijn@openbsd.org>
Tue, 20 Feb 2024 12:41:13 +0000 (12:41 +0000)
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

index 5e18dbe..ae33b64 100644 (file)
@@ -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 <martijn@openbsd.org>
@@ -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;
                                }