[Git][NTPsec/ntpsec][master] ntpd/refclock_nmea.c: reject a malformed time fraction

Matt Selsky (@selsky) gitlab at mg.gitlab.com
Wed Nov 4 04:35:36 UTC 2026



Matt Selsky pushed to branch master at NTPsec / ntpsec


Commits:
bea210db by Matt Selsky at 2026-11-04T04:33:59+00:00
ntpd/refclock_nmea.c: reject a malformed time fraction

parse_time() scaled the fraction of an HHMMSS.sss time field by
weight[p2 - p1 - 1], where p2 - p1 - 1 is the number of characters
sscanf()'s "%3lu" consumed after the '.'. That conversion skips leading
whitespace and accepts a sign, so a field such as "120000. 807" made
the index exceed the four-entry weight[] array, reading up to about
1 KB past it, and a field such as "120000.-5" scaled a wrapped value.
Anything able to write to the NMEA serial input could trigger either.

Reject the time field unless a digit immediately follows the '.'.

Reported by Erica Windisch (Cyberdione Labs).

NTPsec/ntpsec#902, CVE-2026-121504

- - - - -


1 changed file:

- ntpd/refclock_nmea.c


Changes:

=====================================
ntpd/refclock_nmea.c
=====================================
@@ -1547,7 +1547,10 @@ parse_time(
 
         dp = field_parse(rd, idx);
         rc = sscanf(dp, "%2u%2u%2u%n.%3lu%n", &h, &m, &s, &p1, &f, &p2);
-        if (rc < 3 || p1 != 6) {
+        // %3lu skips whitespace and accepts a sign; require a digit
+        // right after the '.' so that p2 - p1 - 1 is 1 to 3
+        if (rc < 3 || p1 != 6 ||
+            (rc == 4 && !isdigit((unsigned char)dp[p1 + 1]))) {
                 DPRINT(1, ("nmea: invalid time code: '%.6s'\n", dp));
                 return false;
         }



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/bea210dba1e05188051872ebb002d9aedc9f7f5f

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/bea210dba1e05188051872ebb002d9aedc9f7f5f
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20261104/ff9da1a5/attachment.htm>


More information about the vc mailing list