8008759: Do not let internal JDK zlib symbols leak out of fastdebug libzip.so
authormartin
Wed, 06 Mar 2013 17:43:10 -0800
changeset 16059 f0a29ee25e5b
parent 16058 5b8d8cec6280
child 16060 08b9a416a770
8008759: Do not let internal JDK zlib symbols leak out of fastdebug libzip.so Summary: Define FILES_m to force use of linker script Reviewed-by: sherman, alanb, ohair
jdk/make/java/zip/Makefile
jdk/src/share/native/java/util/zip/Inflater.c
--- a/jdk/make/java/zip/Makefile	Wed Mar 06 18:35:51 2013 +0100
+++ b/jdk/make/java/zip/Makefile	Wed Mar 06 17:43:10 2013 -0800
@@ -68,6 +68,16 @@
     FILES_reorder += reorder-$(ARCH)
   endif
 endif
+
+#
+# Use mapfile unconditionally (even with fastdebug).
+# JDK's internal zlib is incompatible with stock zlib, because the
+# size of struct z_stream has been changed, so internal zlib
+# implementation must not be allowed to leak outside of libzip.so,
+# else you get hard to debug failures with fastdebug jdk when user
+# native code includes stock zlib.
+#
+FILES_m = mapfile-vers
 include $(BUILDDIR)/common/Mapfile-vers.gmk
 include $(BUILDDIR)/common/Library.gmk
 
--- a/jdk/src/share/native/java/util/zip/Inflater.c	Wed Mar 06 18:35:51 2013 +0100
+++ b/jdk/src/share/native/java/util/zip/Inflater.c	Wed Mar 06 17:43:10 2013 -0800
@@ -27,6 +27,7 @@
  * Native method support for java.util.zip.Inflater
  */
 
+#include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
@@ -60,12 +61,13 @@
 {
     z_stream *strm = calloc(1, sizeof(z_stream));
 
-    if (strm == 0) {
+    if (strm == NULL) {
         JNU_ThrowOutOfMemoryError(env, 0);
         return jlong_zero;
     } else {
-        char *msg;
-        switch (inflateInit2(strm, nowrap ? -MAX_WBITS : MAX_WBITS)) {
+        const char *msg;
+        int ret = inflateInit2(strm, nowrap ? -MAX_WBITS : MAX_WBITS);
+        switch (ret) {
           case Z_OK:
             return ptr_to_jlong(strm);
           case Z_MEM_ERROR:
@@ -73,7 +75,13 @@
             JNU_ThrowOutOfMemoryError(env, 0);
             return jlong_zero;
           default:
-            msg = strm->msg;
+            msg = ((strm->msg != NULL) ? strm->msg :
+                   (ret == Z_VERSION_ERROR) ?
+                   "zlib returned Z_VERSION_ERROR: "
+                   "compile time and runtime zlib implementations differ" :
+                   (ret == Z_STREAM_ERROR) ?
+                   "inflateInit2 returned Z_STREAM_ERROR" :
+                   "unknown error initializing zlib library");
             free(strm);
             JNU_ThrowInternalError(env, msg);
             return jlong_zero;