From: Volker Lendecke Date: Tue, 21 Jul 2026 10:38:17 +0000 (+0200) Subject: lib: Make signed/unsigned conversion explicit in asn1_peek() X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=16e4e8a9c7470cb31216204c2f57551d8dbd93d2;p=thirdparty%2Fsamba.git lib: Make signed/unsigned conversion explicit in asn1_peek() Signed-off-by: Volker Lendecke Reviewed-by: Anoop C S --- diff --git a/lib/util/asn1.c b/lib/util/asn1.c index 6fb4d9ea812..64ee4e9e0c9 100644 --- a/lib/util/asn1.c +++ b/lib/util/asn1.c @@ -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;