Merge tag 'android-security-11.0.0_r49' into int/11/fp3
Android security 11.0.0 release 49
* tag 'android-security-11.0.0_r49':
Reject non-ASCII hostnames and SANs.
Change-Id: Ib7dada1fd47a6a4909ec933f5a6f0064169c1f54
diff --git a/JavaLibrary.bp b/JavaLibrary.bp
index 0d98122..8b0ab3b 100644
--- a/JavaLibrary.bp
+++ b/JavaLibrary.bp
@@ -406,6 +406,9 @@
":openjdk_lambda_stub_files",
":openjdk_lambda_duplicate_stub_files",
],
+ // This jar is packaged as part of the SDK, use -target 8 so that it works
+ // with old JDKs.
+ java_version: "1.8",
}
// An alternative to core-lambda-stubs that omits openjdk_lambda_duplicate_stub_files
diff --git a/luni/src/test/java/libcore/java/io/RandomAccessFileTest.java b/luni/src/test/java/libcore/java/io/RandomAccessFileTest.java
index 3811cbc..eab558a 100644
--- a/luni/src/test/java/libcore/java/io/RandomAccessFileTest.java
+++ b/luni/src/test/java/libcore/java/io/RandomAccessFileTest.java
@@ -41,16 +41,6 @@
file.delete();
}
- public void testSeekTooLarge() throws Exception {
- try (RandomAccessFile raf = new RandomAccessFile(file, "rw")) {
- try {
- raf.seek(Long.MAX_VALUE);
- fail();
- } catch (IOException expected) {
- }
- }
- }
-
public void testSetLengthTooLarge() throws Exception {
try (RandomAccessFile raf = new RandomAccessFile(file, "rw")) {
try {
diff --git a/luni/src/test/java/libcore/java/net/NetworkInterfaceTest.java b/luni/src/test/java/libcore/java/net/NetworkInterfaceTest.java
index f0f79ad..8375421 100644
--- a/luni/src/test/java/libcore/java/net/NetworkInterfaceTest.java
+++ b/luni/src/test/java/libcore/java/net/NetworkInterfaceTest.java
@@ -17,6 +17,7 @@
package libcore.java.net;
import junit.framework.TestCase;
+import org.mockito.Mockito;
import android.system.StructIfaddrs;
import java.io.BufferedReader;
@@ -39,6 +40,7 @@
import java.util.regex.Pattern;
import libcore.io.IoUtils;
import libcore.io.Libcore;
+import libcore.io.Os;
import static android.system.OsConstants.AF_INET;
import static android.system.OsConstants.IFF_LOOPBACK;
@@ -48,6 +50,7 @@
import static android.system.OsConstants.IFF_UP;
import static android.system.OsConstants.SOCK_DGRAM;
import static java.net.NetworkInterface.getNetworkInterfaces;
+import static org.mockito.ArgumentMatchers.anyString;
public class NetworkInterfaceTest extends TestCase {
// http://code.google.com/p/android/issues/detail?id=13784
@@ -221,6 +224,29 @@
assertEquals(ifaddrsNames, actualNiNames);
}
+ // Validate that we don't fail to enumerate interfaces if there is virtual interface without parent interface present.
+ // b/159277702
+ public void testGetNetworkInterfaces_OrphanInterfaceDoesNotThrow() throws Exception {
+ Os originalOs = Libcore.getOs();
+ Os mockOs = Mockito.mock(Os.class);
+
+ try {
+ Mockito.when(mockOs.getifaddrs()).thenReturn(new StructIfaddrs[] {
+ new StructIfaddrs("dummy0:1", 0, null, null, null, null),
+ });
+
+ Mockito.when(mockOs.if_nametoindex(anyString())).thenReturn(1);
+
+ assertTrue("Failed to swap OS implementation", Libcore.compareAndSetOs(originalOs, mockOs));
+
+ Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
+ assertEquals(1, Collections.list(interfaces).size());
+ }
+ finally {
+ assertTrue("Failed to revert OS implementation", Libcore.compareAndSetOs(mockOs, originalOs));
+ }
+ }
+
// Calling getSubInterfaces on interfaces with no subinterface should not throw NPE.
// http://b/33844501
public void testGetSubInterfaces() throws Exception {
diff --git a/ojluni/src/main/java/java/net/NetworkInterface.java b/ojluni/src/main/java/java/net/NetworkInterface.java
index a30b6bf..e56e0cb 100644
--- a/ojluni/src/main/java/java/net/NetworkInterface.java
+++ b/ojluni/src/main/java/java/net/NetworkInterface.java
@@ -494,8 +494,11 @@
NetworkInterface parent = nis.get(parentName);
ni.virtual = true;
- ni.parent = parent;
- parent.childs.add(ni);
+
+ if (parent != null) {
+ ni.parent = parent;
+ parent.childs.add(ni);
+ }
}
}
diff --git a/ojluni/src/main/java/java/net/URI.java b/ojluni/src/main/java/java/net/URI.java
index ebba41b..6b97d56 100644
--- a/ojluni/src/main/java/java/net/URI.java
+++ b/ojluni/src/main/java/java/net/URI.java
@@ -581,6 +581,7 @@
* by the above deviations
*/
public URI(String str) throws URISyntaxException {
+ java.util.SeempLog.record_str(92, "s:"+str);
new Parser(str).parse(false);
}
diff --git a/ojluni/src/main/java/java/net/URL.java b/ojluni/src/main/java/java/net/URL.java
index 74dec92..c3f5b2e 100644
--- a/ojluni/src/main/java/java/net/URL.java
+++ b/ojluni/src/main/java/java/net/URL.java
@@ -1003,6 +1003,7 @@
* int, java.lang.String)
*/
public URLConnection openConnection() throws java.io.IOException {
+ java.util.SeempLog.record_str(91, "URL:"+query);
return handler.openConnection(this);
}
diff --git a/ojluni/src/main/java/java/util/SeempLog.java b/ojluni/src/main/java/java/util/SeempLog.java
new file mode 100644
index 0000000..f8a72d7
--- /dev/null
+++ b/ojluni/src/main/java/java/util/SeempLog.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2015, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package java.util;
+
+/*
+import com.android.internal.os.RuntimeInit;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.net.UnknownHostException;
+*/
+
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
+
+/**
+ *
+ * @hide
+ */
+public final class SeempLog {
+
+ private static Method seemp_record_method = null;
+ private static boolean seemp_record_method_looked_up = false;
+
+ private SeempLog() {
+ }
+
+ /**
+ * Send a log message to the seemp log.
+ * @param msg The message you would like logged.
+ */
+ public static int record_str(int api, String msg) {
+ if (seemp_record_method == null) {
+ if (!seemp_record_method_looked_up) {
+ try
+ {
+ Class c = Class.forName( "android.util.SeempLog" );
+ if (c!=null) {
+ seemp_record_method = c.getDeclaredMethod( "record_str", int.class, String.class );
+ }
+ } catch (ClassNotFoundException ex) {
+ seemp_record_method = null;
+ } catch (NoSuchMethodException ex) {
+ seemp_record_method = null;
+ }
+
+ }
+ seemp_record_method_looked_up = true;
+ }
+
+ if (seemp_record_method!=null) {
+ try {
+ return ( ( Integer )seemp_record_method.invoke( null, api, msg ) ).intValue();
+ } catch (IllegalAccessException ex) {
+ return 0;
+ } catch (InvocationTargetException ex) {
+ return 0;
+ }
+ }
+
+ return 0;// seemp_println_native("-1|" + msg);
+ }
+
+}
diff --git a/ojluni/src/main/native/zip_util.c b/ojluni/src/main/native/zip_util.c
index 6c02d2b..aa9c5ce 100644
--- a/ojluni/src/main/native/zip_util.c
+++ b/ojluni/src/main/native/zip_util.c
@@ -156,7 +156,7 @@
* JVM_IO_INTR is tricky and could cause undesired side effect. So we decided
* to simply call "read" on Solaris/Linux. See details in bug 6304463.
*/
- return pread(zfd, buf, nbytes, offset);
+ return pread64(zfd, buf, nbytes, offset);
#endif
}
diff --git a/openjdk_java_files.bp b/openjdk_java_files.bp
index 7ba860c..c1ee4ac 100644
--- a/openjdk_java_files.bp
+++ b/openjdk_java_files.bp
@@ -1158,6 +1158,7 @@
"ojluni/src/main/java/java/util/RegularEnumSet.java",
"ojluni/src/main/java/java/util/ResourceBundle.java",
"ojluni/src/main/java/java/util/Scanner.java",
+ "ojluni/src/main/java/java/util/SeempLog.java",
"ojluni/src/main/java/java/util/ServiceConfigurationError.java",
"ojluni/src/main/java/java/util/ServiceLoader.java",
"ojluni/src/main/java/java/util/Set.java",
diff --git a/xml/src/main/java/com/android/org/kxml2/io/KXmlParser.java b/xml/src/main/java/com/android/org/kxml2/io/KXmlParser.java
index 3814e63..8dccf6c 100644
--- a/xml/src/main/java/com/android/org/kxml2/io/KXmlParser.java
+++ b/xml/src/main/java/com/android/org/kxml2/io/KXmlParser.java
@@ -157,6 +157,8 @@
private boolean isWhitespace;
private String namespace;
private String prefix;
+ private String foundPrefix = null;
+ private String foundName = null;
private String name;
private String text;
@@ -268,15 +270,21 @@
}
}
- int cut = name.indexOf(':');
+ if (foundPrefix != null && foundName != null) {
+ prefix = foundPrefix;
+ name = foundName;
+ }
+ else {
+ int cut = name.indexOf(':');
if (cut == 0) {
checkRelaxed("illegal tag name: " + name);
}
- if (cut != -1) {
- prefix = name.substring(0, cut);
- name = name.substring(cut + 1);
+ if (cut != -1) {
+ prefix = name.substring(0, cut);
+ name = name.substring(cut + 1);
+ }
}
this.namespace = getNamespace(prefix);
@@ -962,13 +970,19 @@
}
private void readEndTag() throws IOException, XmlPullParserException {
+ int sp = (depth - 1) * 4;
read('<');
read('/');
- name = readName(); // TODO: pass the expected name in as a hint?
+ if (depth == 0) {
+ name = readName();
+ }
+ else {
+ // Pass the expected name in as a hint.
+ name = readExpectedName(elementStack[sp + 3]);
+ }
skip();
read('>');
- int sp = (depth - 1) * 4;
if (depth == 0) {
checkRelaxed("read end tag " + name + " with no tags open");
@@ -1056,7 +1070,7 @@
if (!xmldecl) {
read('<');
}
- name = readName();
+ name = readName(true);
attributeCount = 0;
while (true) {
@@ -1430,7 +1444,12 @@
}
if (result == null) {
- return stringPool.get(buffer, start, position - start);
+ if (isWhitespace) {
+ return stringPool.get(buffer, start, position - start);
+ }
+ else {
+ return new String(buffer, start, position - start);
+ }
} else {
result.append(buffer, start, position - start);
return result.toString();
@@ -1526,13 +1545,44 @@
* Returns an element or attribute name. This is always non-empty for
* non-relaxed parsers.
*/
+ private String readExpectedName(String expected) throws IOException, XmlPullParserException {
+ int length = expected.length();
+ int end = position + length;
+ if (end < limit) {
+ // Fast path for normal case.
+ boolean match = true;
+ for (int i = 0; i < length; i++) {
+ if (buffer[position+i] != expected.charAt(i)) {
+ match = false;
+ break;
+ }
+ }
+ if (match) {
+ position += length;
+ return expected;
+ }
+ }
+ return readName();
+ }
+
private String readName() throws IOException, XmlPullParserException {
+ return readName(false);
+ }
+
+ /**
+ * Returns an element or attribute name. This is always non-empty for
+ * non-relaxed parsers. findPrefix should only be true for element names
+ */
+ private String readName(boolean findPrefix) throws IOException, XmlPullParserException {
if (position >= limit && !fillBuffer(1)) {
checkRelaxed("name expected");
return "";
}
int start = position;
+ int nameStart = -1;
+ foundPrefix = null;
+ foundName = null;
StringBuilder result = null;
// read the first character
@@ -1576,12 +1626,20 @@
|| c == ':'
|| c == '.'
|| c >= '\u00b7') { // TODO: check the XML spec
+ // Fast path for common case
+ if (c == ':' && findPrefix && foundPrefix == null) {
+ foundPrefix = stringPool.get(buffer, start, position - start);
+ nameStart = position+1;
+ }
position++;
continue;
}
// we encountered a non-name character. done!
if (result == null) {
+ if (foundPrefix != null && position != nameStart) {
+ foundName = stringPool.get(buffer, nameStart, position - nameStart);
+ }
return stringPool.get(buffer, start, position - start);
} else {
result.append(buffer, start, position - start);