]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib: Check there's data remaining before calculating how much
authorVolker Lendecke <vl@samba.org>
Tue, 21 Jul 2026 09:06:53 +0000 (11:06 +0200)
committerAnoop C S <anoopcs@samba.org>
Mon, 3 Aug 2026 09:05:30 +0000 (09:05 +0000)
Better make sure the subtraction does not go negative before we do it.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
lib/util/asn1.c

index 3cf872d3bf29dbb00a5b1685f56622ccb78e9f7d..ab9820b26c529324021d239dcb532f699448321d 100644 (file)
@@ -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;