提交 c203e727 编写于 作者: M mullan

8038908: Make Signature more robust

Reviewed-by: valeriep, skoivu, asmotrak
上级 ccc284e5
/* /*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -590,6 +590,9 @@ public abstract class Signature extends SignatureSpi { ...@@ -590,6 +590,9 @@ public abstract class Signature extends SignatureSpi {
if (outbuf == null) { if (outbuf == null) {
throw new IllegalArgumentException("No output buffer given"); throw new IllegalArgumentException("No output buffer given");
} }
if (offset < 0 || len < 0) {
throw new IllegalArgumentException("offset or len is less than 0");
}
if (outbuf.length - offset < len) { if (outbuf.length - offset < len) {
throw new IllegalArgumentException throw new IllegalArgumentException
("Output buffer too small for specified offset and length"); ("Output buffer too small for specified offset and length");
...@@ -658,9 +661,16 @@ public abstract class Signature extends SignatureSpi { ...@@ -658,9 +661,16 @@ public abstract class Signature extends SignatureSpi {
public final boolean verify(byte[] signature, int offset, int length) public final boolean verify(byte[] signature, int offset, int length)
throws SignatureException { throws SignatureException {
if (state == VERIFY) { if (state == VERIFY) {
if ((signature == null) || (offset < 0) || (length < 0) || if (signature == null) {
(length > signature.length - offset)) { throw new IllegalArgumentException("signature is null");
throw new IllegalArgumentException("Bad arguments"); }
if (offset < 0 || length < 0) {
throw new IllegalArgumentException
("offset or length is less than 0");
}
if (signature.length - offset < length) {
throw new IllegalArgumentException
("signature too small for specified offset and length");
} }
return engineVerify(signature, offset, length); return engineVerify(signature, offset, length);
...@@ -713,6 +723,16 @@ public abstract class Signature extends SignatureSpi { ...@@ -713,6 +723,16 @@ public abstract class Signature extends SignatureSpi {
public final void update(byte[] data, int off, int len) public final void update(byte[] data, int off, int len)
throws SignatureException { throws SignatureException {
if (state == SIGN || state == VERIFY) { if (state == SIGN || state == VERIFY) {
if (data == null) {
throw new IllegalArgumentException("data is null");
}
if (off < 0 || len < 0) {
throw new IllegalArgumentException("off or len is less than 0");
}
if (data.length - off < len) {
throw new IllegalArgumentException
("data too small for specified offset and length");
}
engineUpdate(data, off, len); engineUpdate(data, off, len);
} else { } else {
throw new SignatureException("object not initialized for " throw new SignatureException("object not initialized for "
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册