changeset 16229:27ff083d0e07

8170525: Fix minor issues in AWT/ECC/PKCS11 coding Reviewed-by: vinnie, clanger, prr, ssadetsky
author goetz
date Wed, 30 Nov 2016 13:51:41 +0100
parents ed04e8712261
children 7583c87dfe7c
files src/java.desktop/share/native/libawt/awt/image/DataBufferNative.c src/java.desktop/unix/native/common/awt/fontpath.c src/java.desktop/unix/native/libawt_xawt/awt/awt_InputMethod.c src/java.desktop/unix/native/libawt_xawt/awt/gtk3_interface.c src/java.desktop/unix/native/libawt_xawt/xawt/XToolkit.c src/java.desktop/unix/native/libawt_xawt/xawt/XWindow.c src/java.desktop/unix/native/libsplashscreen/splashscreen_sys.c src/jdk.crypto.ec/share/native/libsunec/impl/ec.c src/jdk.crypto.ec/share/native/libsunec/impl/ecdecode.c src/jdk.crypto.ec/share/native/libsunec/impl/ecl_mult.c src/jdk.crypto.ec/share/native/libsunec/impl/mpi.c src/jdk.crypto.pkcs11/share/native/libj2pkcs11/p11_mutex.c
diffstat 12 files changed, 45 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.desktop/share/native/libawt/awt/image/DataBufferNative.c	Thu Dec 08 07:21:50 2016 -0800
+++ b/src/java.desktop/share/native/libawt/awt/image/DataBufferNative.c	Wed Nov 30 13:51:41 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -72,6 +72,7 @@
     unsigned char *pixelPtr;
     SurfaceDataRasInfo lockInfo;
     SurfaceDataOps *ops;
+    lockInfo.rasBase = NULL;
 
     ops = SurfaceData_GetOps(env, sd);
     JNU_CHECK_EXCEPTION_RETURN(env, -1);
@@ -113,7 +114,7 @@
     SurfaceDataRasInfo lockInfo;
     SurfaceDataOps *ops;
     unsigned char *pixelPtr;
-
+    lockInfo.rasBase = NULL;
 
     ops = SurfaceData_GetOps(env, sd);
     JNU_CHECK_EXCEPTION(env);
--- a/src/java.desktop/unix/native/common/awt/fontpath.c	Thu Dec 08 07:21:50 2016 -0800
+++ b/src/java.desktop/unix/native/common/awt/fontpath.c	Wed Nov 30 13:51:41 2016 +0100
@@ -243,8 +243,8 @@
 
         appendDirList[index] = 0;
         if ( doNotAppend == 0 ) {
-            strcpy ( fontDirPath, fDirP->name[index] );
-            strcat ( fontDirPath, "/fonts.dir" );
+            snprintf(fontDirPath, sizeof(fontDirPath), "%s/fonts.dir", fDirP->name[index]);
+            fontDirPath[sizeof(fontDirPath) - 1] = '\0';
             dirFile = open ( fontDirPath, O_RDONLY, 0 );
             if ( dirFile == -1 ) {
                 doNotAppend = 1;
--- a/src/java.desktop/unix/native/libawt_xawt/awt/awt_InputMethod.c	Thu Dec 08 07:21:50 2016 -0800
+++ b/src/java.desktop/unix/native/libawt_xawt/awt/awt_InputMethod.c	Wed Nov 30 13:51:41 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -1235,12 +1235,14 @@
     if (status_draw->type == XIMTextType){
         XIMText *text = (status_draw->data).text;
         if (text != NULL){
-          if (text->string.multi_byte != NULL){
-              strcpy(statusWindow->status, text->string.multi_byte);
+          if (text->string.multi_byte != NULL) {
+              strncpy(statusWindow->status, text->string.multi_byte, MAX_STATUS_LEN);
+              statusWindow->status[MAX_STATUS_LEN - 1] = '\0';
           }
-          else{
+          else {
               char *mbstr = wcstombsdmp(text->string.wide_char, text->length);
-              strcpy(statusWindow->status, mbstr);
+              strncpy(statusWindow->status, mbstr, MAX_STATUS_LEN);
+              statusWindow->status[MAX_STATUS_LEN - 1] = '\0';
           }
           statusWindow->on = True;
           onoffStatusWindow(pX11IMData, statusWindow->parent, True);
--- a/src/java.desktop/unix/native/libawt_xawt/awt/gtk3_interface.c	Thu Dec 08 07:21:50 2016 -0800
+++ b/src/java.desktop/unix/native/libawt_xawt/awt/gtk3_interface.c	Wed Nov 30 13:51:41 2016 +0100
@@ -2014,9 +2014,7 @@
 static guint8 recode_color(gdouble channel)
 {
     guint16 result = (guint16)(channel * 65535);
-    if (result < 0) {
-        result = 0;
-    } else if (result > 65535) {
+    if (result > 65535) {
         result = 65535;
     }
     return (guint8)( result >> 8);
@@ -2218,6 +2216,7 @@
 static GdkRGBA gtk3_get_color_for_flags(GtkStyleContext* context,
                                   GtkStateFlags flags, ColorType color_type) {
     GdkRGBA c, color;
+    color.alpha = 1;
 
     switch (color_type)
     {
@@ -2266,7 +2265,6 @@
 {
 
     gint result = 0;
-    GdkRGBA color;
 
     GtkStateFlags flags = gtk3_get_state_flags(state_type);
 
@@ -2285,7 +2283,7 @@
                   | GTK_STATE_FLAG_INSENSITIVE | GTK_STATE_FLAG_FOCUSED;
     }
 
-    color = gtk3_get_color_for_flags(context, flags, color_type);
+    GdkRGBA color = gtk3_get_color_for_flags(context, flags, color_type);
 
     if (recode_color(color.alpha) == 0) {
         color = gtk3_get_color_for_flags(
--- a/src/java.desktop/unix/native/libawt_xawt/xawt/XToolkit.c	Thu Dec 08 07:21:50 2016 -0800
+++ b/src/java.desktop/unix/native/libawt_xawt/xawt/XToolkit.c	Wed Nov 30 13:51:41 2016 +0100
@@ -567,7 +567,7 @@
  */
 static uint32_t get_poll_timeout(jlong nextTaskTime)
 {
-    uint32_t ret_timeout;
+    uint32_t ret_timeout = 0;
     uint32_t timeout;
     uint32_t taskTimeout;
     uint32_t flushTimeout;
--- a/src/java.desktop/unix/native/libawt_xawt/xawt/XWindow.c	Thu Dec 08 07:21:50 2016 -0800
+++ b/src/java.desktop/unix/native/libawt_xawt/xawt/XWindow.c	Wed Nov 30 13:51:41 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -863,10 +863,10 @@
 }
 static void
 dumpKeysymArray(XEvent *event) {
-    printf("    0x%X\n",keycodeToKeysym(event->xkey.display, event->xkey.keycode, 0));
-    printf("    0x%X\n",keycodeToKeysym(event->xkey.display, event->xkey.keycode, 1));
-    printf("    0x%X\n",keycodeToKeysym(event->xkey.display, event->xkey.keycode, 2));
-    printf("    0x%X\n",keycodeToKeysym(event->xkey.display, event->xkey.keycode, 3));
+    printf("    0x%lX\n", (unsigned long)keycodeToKeysym(event->xkey.display, event->xkey.keycode, 0));
+    printf("    0x%lX\n", (unsigned long)keycodeToKeysym(event->xkey.display, event->xkey.keycode, 1));
+    printf("    0x%lX\n", (unsigned long)keycodeToKeysym(event->xkey.display, event->xkey.keycode, 2));
+    printf("    0x%lX\n", (unsigned long)keycodeToKeysym(event->xkey.display, event->xkey.keycode, 3));
 }
 /*
  * In a next redesign, get rid of this code altogether.
--- a/src/java.desktop/unix/native/libsplashscreen/splashscreen_sys.c	Thu Dec 08 07:21:50 2016 -0800
+++ b/src/java.desktop/unix/native/libsplashscreen/splashscreen_sys.c	Wed Nov 30 13:51:41 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -809,7 +809,7 @@
 #ifndef __linux__
     return JNI_FALSE;
 #endif
-    *scaleFactor = getNativeScaleFactor(NULL);
+    *scaleFactor = (float)getNativeScaleFactor(NULL);
     return GetScaledImageName(fileName, scaledImgName, scaleFactor, scaledImageNameLength);
 }
 
--- a/src/jdk.crypto.ec/share/native/libsunec/impl/ec.c	Thu Dec 08 07:21:50 2016 -0800
+++ b/src/jdk.crypto.ec/share/native/libsunec/impl/ec.c	Wed Nov 30 13:51:41 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
  * This library is free software; you can redistribute it and/or
@@ -34,7 +34,7 @@
  *   Dr Vipul Gupta <vipul.gupta@sun.com> and
  *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
  *
- * Last Modified Date from the Original Code: April 2015
+ * Last Modified Date from the Original Code: Nov 2016
  *********************************************************************** */
 
 #include "mplogic.h"
@@ -258,6 +258,7 @@
 #if EC_DEBUG
     printf("ec_NewKey called\n");
 #endif
+    k.dp = (mp_digit*)NULL;
 
     if (!ecParams || !privKey || !privKeyBytes || (privKeyLen < 0)) {
         PORT_SetError(SEC_ERROR_INVALID_ARGS);
--- a/src/jdk.crypto.ec/share/native/libsunec/impl/ecdecode.c	Thu Dec 08 07:21:50 2016 -0800
+++ b/src/jdk.crypto.ec/share/native/libsunec/impl/ecdecode.c	Wed Nov 30 13:51:41 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
  * This library is free software; you can redistribute it and/or
@@ -34,7 +34,7 @@
  *   Dr Vipul Gupta <vipul.gupta@sun.com> and
  *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
  *
- * Last Modified Date from the Original Code: March 2012
+ * Last Modified Date from the Original Code: Nov 2016
  *********************************************************************** */
 
 #include <sys/types.h>
@@ -119,6 +119,9 @@
     params->name = name;
     curveParams = ecCurve_map[params->name];
     CHECK_OK(curveParams);
+    if ((strlen(curveParams->genx) + strlen(curveParams->geny)) > 2 * 2 * MAX_ECKEY_LEN) {
+        goto cleanup;
+    }
     params->fieldID.size = curveParams->size;
     params->fieldID.type = field_type;
     if (field_type == ec_field_GFp) {
--- a/src/jdk.crypto.ec/share/native/libsunec/impl/ecl_mult.c	Thu Dec 08 07:21:50 2016 -0800
+++ b/src/jdk.crypto.ec/share/native/libsunec/impl/ecl_mult.c	Wed Nov 30 13:51:41 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
  * This library is free software; you can redistribute it and/or
@@ -33,6 +33,7 @@
  * Contributor(s):
  *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
  *
+ * Last Modified Date from the Original Code: Nov 2016
  *********************************************************************** */
 
 #include "mpi.h"
@@ -72,6 +73,7 @@
                 if (group->base_point_mul) {
                         MP_CHECKOK(group->base_point_mul(&kt, rx, ry, group));
                 } else {
+                        kt.flag = (mp_sign)0;
                         MP_CHECKOK(group->
                                            point_mul(&kt, &group->genx, &group->geny, rx, ry,
                                                                  group));
@@ -82,6 +84,7 @@
                         MP_CHECKOK(group->meth->field_enc(py, ry, group->meth));
                         MP_CHECKOK(group->point_mul(&kt, rx, ry, rx, ry, group));
                 } else {
+                        kt.flag = (mp_sign)0;
                         MP_CHECKOK(group->point_mul(&kt, px, py, rx, ry, group));
                 }
         }
--- a/src/jdk.crypto.ec/share/native/libsunec/impl/mpi.c	Thu Dec 08 07:21:50 2016 -0800
+++ b/src/jdk.crypto.ec/share/native/libsunec/impl/mpi.c	Wed Nov 30 13:51:41 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
  * This library is free software; you can redistribute it and/or
@@ -34,7 +34,7 @@
  *   Netscape Communications Corporation
  *   Douglas Stebila <douglas@stebila.ca> of Sun Laboratories.
  *
- * Last Modified Date from the Original Code: June 2014
+ * Last Modified Date from the Original Code: Nov 2016
  *********************************************************************** */
 
 /*  Arbitrary precision integer arithmetic library */
@@ -659,6 +659,7 @@
       goto CLEANUP;
   }
 
+  s.flag = (mp_sign)0;
   s_mp_exch(&s, c);
 
 CLEANUP:
@@ -1609,6 +1610,7 @@
       goto CLEANUP;
   }
 
+  s.flag = (mp_sign)0;
   s_mp_exch(&s, c);
 
 CLEANUP:
@@ -4183,6 +4185,7 @@
 {
   mp_err   res;
   mp_int   tmp;
+  tmp.flag = (mp_sign)0;
 
   if((res = mp_init_size(&tmp, 2 * USED(a), FLAG(a))) != MP_OKAY)
     return res;
@@ -4220,6 +4223,8 @@
   mp_digit div_msd;
   int      ix;
 
+  t.dp = (mp_digit *)NULL;
+
   if(mp_cmp_z(div) == 0)
     return MP_RANGE;
 
--- a/src/jdk.crypto.pkcs11/share/native/libj2pkcs11/p11_mutex.c	Thu Dec 08 07:21:50 2016 -0800
+++ b/src/jdk.crypto.pkcs11/share/native/libj2pkcs11/p11_mutex.c	Wed Nov 30 13:51:41 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
  */
 
 /* Copyright  (c) 2002 Graz University of Technology. All rights reserved.
@@ -95,6 +95,8 @@
         throwOutOfMemoryError(env, 0);
         return NULL_PTR;
     }
+    ckpInitArgs->flags = (CK_FLAGS)0;
+    ckpInitArgs->pReserved = (CK_VOID_PTR)NULL;
 
     /* Set the mutex functions that will call the Java mutex functions, but
      * only set it, if the field is not null.