Skip to content

Commit 9cb376e

Browse files
Jesse WilsonAndroid (Google) Code Review
authored andcommitted
Merge "Change NPN to forbid empty lists of protocols." into jb-dev
2 parents 0a95ce9 + 2108ead commit 9cb376e

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

core/java/android/net/SSLCertificateSocketFactory.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ public void setTrustManagers(TrustManager[] trustManager) {
261261
* server then the first protocol in the client's list will be selected.
262262
* The order of the client's protocols is otherwise insignificant.
263263
*
264-
* @param npnProtocols a possibly-empty list of protocol byte arrays. All
265-
* arrays must be non-empty and of length less than 256.
264+
* @param npnProtocols a non-empty list of protocol byte arrays. All arrays
265+
* must be non-empty and of length less than 256.
266266
*/
267267
public void setNpnProtocols(byte[][] npnProtocols) {
268268
this.mNpnProtocols = toNpnProtocolsList(npnProtocols);
@@ -273,6 +273,9 @@ public void setNpnProtocols(byte[][] npnProtocols) {
273273
* strings.
274274
*/
275275
static byte[] toNpnProtocolsList(byte[]... npnProtocols) {
276+
if (npnProtocols.length == 0) {
277+
throw new IllegalArgumentException("npnProtocols.length == 0");
278+
}
276279
int totalLength = 0;
277280
for (byte[] s : npnProtocols) {
278281
if (s.length == 0 || s.length > 255) {

core/tests/coretests/src/android/net/SSLTest.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,20 @@ public void testStringsToNpnBytes() {
5959
new byte[] { 'h', 't', 't', 'p', '/', '1', '.', '1' })));
6060
}
6161

62-
public void testStringsToNpnBytesEmptyByteArray() {
62+
public void testStringsToNpnBytesEmptyArray() {
6363
try {
64-
SSLCertificateSocketFactory.toNpnProtocolsList(new byte[0]);
64+
SSLCertificateSocketFactory.toNpnProtocolsList();
6565
fail();
6666
} catch (IllegalArgumentException expected) {
6767
}
6868
}
6969

70-
public void testStringsToNpnBytesEmptyArray() {
71-
byte[] expected = {};
72-
assertTrue(Arrays.equals(expected, SSLCertificateSocketFactory.toNpnProtocolsList()));
70+
public void testStringsToNpnBytesEmptyByteArray() {
71+
try {
72+
SSLCertificateSocketFactory.toNpnProtocolsList(new byte[0]);
73+
fail();
74+
} catch (IllegalArgumentException expected) {
75+
}
7376
}
7477

7578
public void testStringsToNpnBytesOversizedInput() {

0 commit comments

Comments
 (0)