Fix range checks with -offset and -length in asn1parse
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Mon, 2 Apr 2018 07:13:49 +0000 (09:13 +0200)
committerBernd Edlinger <bernd.edlinger@hotmail.de>
Tue, 3 Apr 2018 14:08:25 +0000 (16:08 +0200)
Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/5826)

(cherry picked from commit 16e1eea6a67c85c9d786f3c4448182b1aca101b8)

apps/asn1pars.c

index 34f987d5ce286f64924dc7df51e8ed2a7a0b364c..3b80b77e8ed2b1ae907af6d064d048f8e1619f98 100644 (file)
@@ -244,14 +244,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) {
         if (BIO_write(derout, str + offset, length) != (int)length) {