7064312: Cleanup: avoid using unsafe string function
authorbagiras
Thu, 12 Sep 2013 15:50:25 +0400
changeset 20124 ad00860443b0
parent 20123 e12d9acdc289
child 20125 65a1e01378a2
7064312: Cleanup: avoid using unsafe string function Reviewed-by: serb, pchelko
jdk/src/windows/native/sun/windows/awt_FileDialog.cpp
jdk/src/windows/native/sun/windows/awt_Font.cpp
jdk/src/windows/native/sun/windows/awt_PrintControl.cpp
jdk/src/windows/native/sun/windows/awt_Toolkit.cpp
jdk/src/windows/native/sun/windows/awt_TrayIcon.cpp
jdk/src/windows/native/sun/windows/awt_ole.cpp
--- a/jdk/src/windows/native/sun/windows/awt_FileDialog.cpp	Thu Sep 12 14:56:20 2013 +0400
+++ b/jdk/src/windows/native/sun/windows/awt_FileDialog.cpp	Thu Sep 12 15:50:25 2013 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2013, 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
@@ -73,7 +73,7 @@
     int length = env->GetStringLength(filterDescription);
     DASSERT(length + 1 < MAX_FILTER_STRING);
     LPCTSTR tmp = JNU_GetStringPlatformChars(env, filterDescription, NULL);
-    _tcscpy(s_fileFilterString, tmp);
+    _tcscpy_s(s_fileFilterString, MAX_FILTER_STRING, tmp);
     JNU_ReleaseStringPlatformChars(env, filterDescription, tmp);
 
     //AdditionalString should be terminated by two NULL characters (Windows
@@ -353,7 +353,7 @@
         if (!result) {
             dlgerr = ::CommDlgExtendedError();
             if (dlgerr == FNERR_INVALIDFILENAME) {
-                _tcscpy(fileBuffer, TEXT(""));
+                _tcscpy_s(fileBuffer, bufferLimit, TEXT(""));
                 if (mode == java_awt_FileDialog_LOAD) {
                     result = AwtFileDialog::GetOpenFileName(&ofn);
                 } else {
--- a/jdk/src/windows/native/sun/windows/awt_Font.cpp	Thu Sep 12 14:56:20 2013 +0400
+++ b/jdk/src/windows/native/sun/windows/awt_Font.cpp	Thu Sep 12 15:50:25 2013 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2013, 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
@@ -366,17 +366,6 @@
     return awtFont;
 }
 
-int CALLBACK FindFamilyName (ENUMLOGFONTEX *lpelfe,
-          NEWTEXTMETRICEX *lpntme, int FontType, LPARAM lParam)
-{
-    if(_tcsstr((LPTSTR)lParam, lpelfe->elfLogFont.lfFaceName)) {
-        _tcscpy((LPTSTR)lParam, lpelfe->elfLogFont.lfFaceName);
-        return 0;
-    } else {
-        return 1;
-    }
-}
-
 static void strip_tail(wchar_t* text, wchar_t* tail) { // strips tail and any possible whitespace before it from the end of text
     if (wcslen(text)<=wcslen(tail)) {
         return;
--- a/jdk/src/windows/native/sun/windows/awt_PrintControl.cpp	Thu Sep 12 14:56:20 2013 +0400
+++ b/jdk/src/windows/native/sun/windows/awt_PrintControl.cpp	Thu Sep 12 15:50:25 2013 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2013, 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
@@ -422,17 +422,17 @@
         devnames->wOutputOffset =
             static_cast<WORD>(sizeof(DEVNAMES)/sizeof(TCHAR) + lenDriverName + lenPrinterName);
         if (info2->pDriverName != NULL) {
-            _tcscpy(lpcDevnames + devnames->wDriverOffset, info2->pDriverName);
+            _tcscpy_s(lpcDevnames + devnames->wDriverOffset, devnameSize - devnames->wDriverOffset, info2->pDriverName);
         } else {
             *(lpcDevnames + devnames->wDriverOffset) = _T('\0');
         }
         if (pPrinterName != NULL) {
-            _tcscpy(lpcDevnames + devnames->wDeviceOffset, pPrinterName);
+            _tcscpy_s(lpcDevnames + devnames->wDeviceOffset, devnameSize - devnames->wDeviceOffset, pPrinterName);
         } else {
             *(lpcDevnames + devnames->wDeviceOffset) = _T('\0');
         }
         if (info2->pPortName != NULL) {
-            _tcscpy(lpcDevnames + devnames->wOutputOffset, info2->pPortName);
+            _tcscpy_s(lpcDevnames + devnames->wOutputOffset, devnameSize - devnames->wOutputOffset, info2->pPortName);
         } else {
             *(lpcDevnames + devnames->wOutputOffset) = _T('\0');
         }
--- a/jdk/src/windows/native/sun/windows/awt_Toolkit.cpp	Thu Sep 12 14:56:20 2013 +0400
+++ b/jdk/src/windows/native/sun/windows/awt_Toolkit.cpp	Thu Sep 12 15:50:25 2013 +0400
@@ -228,7 +228,7 @@
         // create input locale string, e.g., "00000409", from hkl.
         TCHAR inputLocale[9];
         TCHAR buf[9];
-        _tcscpy(inputLocale, TEXT("00000000"));
+        _tcscpy_s(inputLocale, 9, TEXT("00000000"));
 
     // 64-bit: ::LoadKeyboardLayout() is such a weird API - a string of
     // the hex value you want?!  Here we're converting our HKL value to
--- a/jdk/src/windows/native/sun/windows/awt_TrayIcon.cpp	Thu Sep 12 14:56:20 2013 +0400
+++ b/jdk/src/windows/native/sun/windows/awt_TrayIcon.cpp	Thu Sep 12 15:50:25 2013 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2013, 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
@@ -711,7 +711,7 @@
         _tcsncpy(m_nid.szTip, tooltip, TRAY_ICON_TOOLTIP_MAX_SIZE);
         m_nid.szTip[TRAY_ICON_TOOLTIP_MAX_SIZE - 1] = '\0';
     } else {
-        _tcscpy(m_nid.szTip, tooltip);
+        _tcscpy_s(m_nid.szTip, TRAY_ICON_TOOLTIP_MAX_SIZE, tooltip);
     }
 
     SendTrayMessage(NIM_MODIFY);
@@ -817,7 +817,7 @@
         m_nid.szInfoTitle[TRAY_ICON_BALLOON_TITLE_MAX_SIZE - 1] = '\0';
 
     } else {
-        _tcscpy(m_nid.szInfoTitle, caption);
+        _tcscpy_s(m_nid.szInfoTitle, TRAY_ICON_BALLOON_TITLE_MAX_SIZE, caption);
     }
 
     if (text[0] == '\0') {
@@ -830,7 +830,7 @@
         m_nid.szInfo[TRAY_ICON_BALLOON_INFO_MAX_SIZE - 1] = '\0';
 
     } else {
-        _tcscpy(m_nid.szInfo, text);
+        _tcscpy_s(m_nid.szInfo, TRAY_ICON_BALLOON_INFO_MAX_SIZE, text);
     }
 
     SendTrayMessage(NIM_MODIFY);
--- a/jdk/src/windows/native/sun/windows/awt_ole.cpp	Thu Sep 12 14:56:20 2013 +0400
+++ b/jdk/src/windows/native/sun/windows/awt_ole.cpp	Thu Sep 12 15:50:25 2013 +0400
@@ -70,7 +70,7 @@
             bErrorReport?_T("Error:"):_T(""),
             szBuffer) < 0)
         {
-            _tcscpy(szBuffer1 + DTRACE_BUF_LEN - 5, _T("...")); //reserver for \n
+            _tcscpy_s(szBuffer1 + DTRACE_BUF_LEN - 5, 5, _T("...")); //reserver for \n
         }
         memcpy(szBuffer1, szTime, iTimeLen*sizeof(TCHAR));
         _tcscat(szBuffer1, _T("\n"));