From 50376926a7356c25da12f1d2e66cacf2d3e9bbcb Mon Sep 17 00:00:00 2001 From: Janos Follath Date: Wed, 21 Jan 2026 17:29:07 +0000 Subject: [PATCH] inet_pton: simplify IPv4 walkback loop Signed-off-by: Janos Follath --- library/x509_crt.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/library/x509_crt.c b/library/x509_crt.c index 25a4bbaf68..028ae8bf14 100644 --- a/library/x509_crt.c +++ b/library/x509_crt.c @@ -2729,16 +2729,15 @@ static int x509_inet_pton_ipv6(const char *src, void *dst) break; } - /* Walk back to prior ':', then parse as IPv4-mapped */ - int steps = 4; + /* Walk back to prior ':', then parse as IPv4-mapped. + * At this point nonzero_groups == 6 or zero_group_start >= 0. Either way we have a + * ':' before the current position and still inside the buffer. Thus it is safe to + * search back for that ':' without any further checks. + */ do { p--; - steps--; - } while (*p != ':' && steps > 0); + } while (*p != ':'); - if (*p != ':') { - break; - } p++; nonzero_groups--; if (x509_inet_pton_ipv4((const char *) p,