]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib: Make signed/unsigned conversion explicit in asn1_peek()
authorVolker Lendecke <vl@samba.org>
Tue, 21 Jul 2026 10:38:17 +0000 (12:38 +0200)
committerAnoop C S <anoopcs@samba.org>
Mon, 3 Aug 2026 09:05:30 +0000 (09:05 +0000)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
lib/util/asn1.c

index 6fb4d9ea812fe40a551f9a50d7726346b1a5b912..64ee4e9e0c92b7a8a97fa56f5ea184cbf266d233 100644 (file)
@@ -524,13 +524,27 @@ bool asn1_load(struct asn1_data *data, DATA_BLOB blob)
 /* Peek into an ASN1 buffer, not advancing the pointer */
 bool asn1_peek(struct asn1_data *data, void *p, int len)
 {
+       size_t ofs, end;
+
        if (data->has_error)
                return false;
 
-       if (len < 0 || data->ofs + len < data->ofs || data->ofs + len < len)
+       if (len < 0) {
+               return false;
+       }
+
+       if (data->ofs < 0) {
+               data->has_error = true;
+               return false;
+       }
+       ofs = data->ofs;
+
+       end = ofs + len;
+       if (end < ofs) {
                return false;
+       }
 
-       if (data->ofs + len > data->length) {
+       if (end > data->length) {
                /* we need to mark the buffer as consumed, so the caller knows
                   this was an out of data error, and not a decode error */
                data->ofs = data->length;