From: Volker Lendecke Date: Tue, 21 Jul 2026 09:06:53 +0000 (+0200) Subject: lib: Check there's data remaining before calculating how much X-Git-Tag: samba-4.25.0rc1~87 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=be2372888c5cbce0d363a64678a7fe0d0e286447;p=thirdparty%2Fsamba.git lib: Check there's data remaining before calculating how much Better make sure the subtraction does not go negative before we do it. Signed-off-by: Volker Lendecke Reviewed-by: Anoop C S --- diff --git a/lib/util/asn1.c b/lib/util/asn1.c index 3cf872d3bf2..ab9820b26c5 100644 --- a/lib/util/asn1.c +++ b/lib/util/asn1.c @@ -760,11 +760,12 @@ int asn1_tag_remaining(struct asn1_data *data) } consumed = data->ofs - data->nesting->start; - remaining = data->nesting->taglen - consumed; - if (remaining > (data->length - data->ofs)) { + if (data->nesting->taglen < consumed) { goto error; } - if (remaining < 0) { + remaining = data->nesting->taglen - consumed; + + if (remaining > (data->length - data->ofs)) { goto error; } return remaining;