Fix range checks with -offset and -length in asn1parse
[openssl.git] / apps / asn1pars.c
index 6278b13062e809bae68e105d97f83cee4abb7e2b..062e19644e0b8f9741cfffe42e952c56f9c3ae2c 100644 (file)
@@ -258,14 +258,14 @@ int asn1parse_main(int argc, char **argv)
         num = tmplen;
     }
 
-    if (offset >= num) {
+    if (offset < 0 || offset >= num) {
         BIO_printf(bio_err, "Error: offset too large\n");
         goto end;
     }
 
     num -= offset;
 
-    if ((length == 0) || ((long)length > num))
+    if (length == 0 || length > (unsigned int)num)
         length = (unsigned int)num;
     if (derout != NULL) {
         if (BIO_write(derout, str + offset, length) != (int)length) {