Commit 820fb35a authored by Dr. Stephen Henson's avatar Dr. Stephen Henson
Browse files

Fix handling of -offset and -length in asn1parse tool.

If -offset exceeds -length of data available exit with an error.

Don't read past end of total data available when -offset supplied.

If -length exceeds total available truncate it.
parent b47178f0
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -304,7 +304,15 @@ bad:
		num=tmplen;
		}

	if (length == 0) length=(unsigned int)num;
	if (offset >= num)
		{
		BIO_printf(bio_err, "Error: offset too large\n");
		goto end;
		}

	num -= offset;

	if ((length == 0) || (length > num)) length=(unsigned int)num;
	if(derout) {
		if(BIO_write(derout, str + offset, length) != (int)length) {
			BIO_printf(bio_err, "Error writing output\n");