提交 257251a7 编写于 作者: C coffeys

8208585: Make crypto code more robust

Reviewed-by: ascarpino, mschoene
上级 5cb29584
/* /*
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2018, 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
...@@ -329,7 +329,7 @@ public final class RSACipher extends CipherSpi { ...@@ -329,7 +329,7 @@ public final class RSACipher extends CipherSpi {
if ((inLen == 0) || (in == null)) { if ((inLen == 0) || (in == null)) {
return; return;
} }
if (bufOfs + inLen > buffer.length) { if (inLen > (buffer.length - bufOfs)) {
bufOfs = buffer.length + 1; bufOfs = buffer.length + 1;
return; return;
} }
......
/* /*
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2018, 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
...@@ -472,6 +472,10 @@ final class P11Signature extends SignatureSpi { ...@@ -472,6 +472,10 @@ final class P11Signature extends SignatureSpi {
if (len == 0) { if (len == 0) {
return; return;
} }
// check for overflow
if (len + bytesProcessed < 0) {
throw new ProviderException("Processed bytes limits exceeded.");
}
switch (type) { switch (type) {
case T_UPDATE: case T_UPDATE:
try { try {
......
/* /*
* Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2018, 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
...@@ -491,7 +491,7 @@ abstract class DSA extends SignatureSpi { ...@@ -491,7 +491,7 @@ abstract class DSA extends SignatureSpi {
} }
} }
protected void engineUpdate(byte[] input, int offset, int len) { protected void engineUpdate(byte[] input, int offset, int len) {
if (ofs + len > digestBuffer.length) { if (len > (digestBuffer.length - ofs)) {
ofs = Integer.MAX_VALUE; ofs = Integer.MAX_VALUE;
} else { } else {
System.arraycopy(input, offset, digestBuffer, ofs, len); System.arraycopy(input, offset, digestBuffer, ofs, len);
...@@ -500,7 +500,7 @@ abstract class DSA extends SignatureSpi { ...@@ -500,7 +500,7 @@ abstract class DSA extends SignatureSpi {
} }
protected final void engineUpdate(ByteBuffer input) { protected final void engineUpdate(ByteBuffer input) {
int inputLen = input.remaining(); int inputLen = input.remaining();
if (ofs + inputLen > digestBuffer.length) { if (inputLen > (digestBuffer.length - ofs)) {
ofs = Integer.MAX_VALUE; ofs = Integer.MAX_VALUE;
} else { } else {
input.get(digestBuffer, ofs, inputLen); input.get(digestBuffer, ofs, inputLen);
......
/* /*
* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2018, 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
...@@ -132,7 +132,7 @@ abstract class RSASignature extends java.security.SignatureSpi ...@@ -132,7 +132,7 @@ abstract class RSASignature extends java.security.SignatureSpi
@Override @Override
protected void engineUpdate(byte[] b, int off, int len) protected void engineUpdate(byte[] b, int off, int len)
throws SignatureException { throws SignatureException {
if (offset + len > precomputedDigest.length) { if (len > (precomputedDigest.length - offset)) {
offset = RAW_RSA_MAX + 1; offset = RAW_RSA_MAX + 1;
return; return;
} }
...@@ -147,7 +147,7 @@ abstract class RSASignature extends java.security.SignatureSpi ...@@ -147,7 +147,7 @@ abstract class RSASignature extends java.security.SignatureSpi
if (len <= 0) { if (len <= 0) {
return; return;
} }
if (offset + len > precomputedDigest.length) { if (len > (precomputedDigest.length - offset)) {
offset = RAW_RSA_MAX + 1; offset = RAW_RSA_MAX + 1;
return; return;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册