--- a/jdk/src/macosx/native/sun/util/locale/provider/HostLocaleProviderAdapter_md.c Thu Feb 06 11:01:27 2014 -0500
+++ b/jdk/src/macosx/native/sun/util/locale/provider/HostLocaleProviderAdapter_md.c Thu Feb 06 10:06:09 2014 -0800
@@ -24,6 +24,7 @@
*/
#include "sun_util_locale_provider_HostLocaleProviderAdapterImpl.h"
+#include "jni_util.h"
#include <CoreFoundation/CoreFoundation.h>
#include <stdio.h>
@@ -63,6 +64,10 @@
localeString = getMacOSXLocale(posixCat);
if (localeString == NULL) {
localeString = getPosixLocale(posixCat);
+ if (localeString == NULL) {
+ JNU_ThrowOutOfMemoryError(env, NULL);
+ return NULL;
+ }
}
ret = (*env)->NewStringUTF(env, localeString);
free(localeString);
@@ -127,6 +132,7 @@
JNIEXPORT jobjectArray JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getAmPmStrings
(JNIEnv *env, jclass cls, jstring jlangtag, jobjectArray ampms) {
CFLocaleRef cflocale = CFLocaleCopyCurrent();
+ jstring tmp_string;
if (cflocale != NULL) {
CFDateFormatterRef df = CFDateFormatterCreate(kCFAllocatorDefault,
cflocale,
@@ -138,13 +144,18 @@
if (amStr != NULL) {
CFStringGetCString(amStr, buf, BUFLEN, kCFStringEncodingUTF8);
CFRelease(amStr);
- (*env)->SetObjectArrayElement(env, ampms, 0, (*env)->NewStringUTF(env, buf));
+ tmp_string = (*env)->NewStringUTF(env, buf);
+ if (tmp_string != NULL) {
+ (*env)->SetObjectArrayElement(env, ampms, 0, tmp_string);
+ }
}
- CFStringRef pmStr = CFDateFormatterCopyProperty(df, kCFDateFormatterPMSymbol);
- if (pmStr != NULL) {
- CFStringGetCString(pmStr, buf, BUFLEN, kCFStringEncodingUTF8);
- CFRelease(pmStr);
- (*env)->SetObjectArrayElement(env, ampms, 1, (*env)->NewStringUTF(env, buf));
+ if (!(*env)->ExceptionCheck(env)){
+ CFStringRef pmStr = CFDateFormatterCopyProperty(df, kCFDateFormatterPMSymbol);
+ if (pmStr != NULL) {
+ CFStringGetCString(pmStr, buf, BUFLEN, kCFStringEncodingUTF8);
+ CFRelease(pmStr);
+ (*env)->SetObjectArrayElement(env, ampms, 1, (*env)->NewStringUTF(env, buf));
+ }
}
CFRelease(df);
}
@@ -647,10 +658,16 @@
static void copyArrayElements(JNIEnv *env, CFArrayRef cfarray, jobjectArray jarray, CFIndex sindex, int dindex, int count) {
char buf[BUFLEN];
+ jstring tmp_string;
for (; count > 0; sindex++, dindex++, count--) {
CFStringGetCString(CFArrayGetValueAtIndex(cfarray, sindex), buf, BUFLEN, kCFStringEncodingUTF8);
- (*env)->SetObjectArrayElement(env, jarray, dindex, (*env)->NewStringUTF(env, buf));
+ tmp_string = (*env)->NewStringUTF(env, buf);
+ if (tmp_string != NULL) {
+ (*env)->SetObjectArrayElement(env, jarray, dindex, tmp_string);
+ } else {
+ break;
+ }
}
}
--- a/jdk/src/windows/native/java/lang/java_props_md.c Thu Feb 06 11:01:27 2014 -0500
+++ b/jdk/src/windows/native/java/lang/java_props_md.c Thu Feb 06 10:06:09 2014 -0800
@@ -28,6 +28,9 @@
#define _WIN32_WINNT 0x0601
#endif
+#include "jni.h"
+#include "jni_util.h"
+
#include <windows.h>
#include <shlobj.h>
#include <objidl.h>
@@ -51,7 +54,7 @@
#endif
typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
-static void SetupI18nProps(LCID lcid, char** language, char** script, char** country,
+static boolean SetupI18nProps(LCID lcid, char** language, char** script, char** country,
char** variant, char** encoding);
#define PROPSIZE 9 // eight-letter + null terminator
@@ -60,8 +63,11 @@
static char *
getEncodingInternal(LCID lcid)
{
+ int codepage;
char * ret = malloc(16);
- int codepage;
+ if (ret == NULL) {
+ return NULL;
+ }
if (GetLocaleInfo(lcid,
LOCALE_IDEFAULTANSICODEPAGE,
@@ -132,7 +138,11 @@
static char* getConsoleEncoding()
{
char* buf = malloc(16);
- int cp = GetConsoleCP();
+ int cp;
+ if (buf == NULL) {
+ return NULL;
+ }
+ cp = GetConsoleCP();
if (cp >= 874 && cp <= 950)
sprintf(buf, "ms%d", cp);
else
@@ -152,25 +162,33 @@
getJavaIDFromLangID(LANGID langID)
{
char * elems[5]; // lang, script, ctry, variant, encoding
- char * ret = malloc(SNAMESIZE);
+ char * ret;
int index;
- SetupI18nProps(MAKELCID(langID, SORT_DEFAULT),
- &(elems[0]), &(elems[1]), &(elems[2]), &(elems[3]), &(elems[4]));
-
- // there always is the "language" tag
- strcpy(ret, elems[0]);
-
- // append other elements, if any
- for (index = 1; index < 4; index++) {
- if ((elems[index])[0] != '\0') {
- strcat(ret, "-");
- strcat(ret, elems[index]);
- }
+ ret = malloc(SNAMESIZE);
+ if (ret == NULL) {
+ return NULL;
}
- for (index = 0; index < 5; index++) {
- free(elems[index]);
+ if (SetupI18nProps(MAKELCID(langID, SORT_DEFAULT),
+ &(elems[0]), &(elems[1]), &(elems[2]), &(elems[3]), &(elems[4]))) {
+
+ // there always is the "language" tag
+ strcpy(ret, elems[0]);
+
+ // append other elements, if any
+ for (index = 1; index < 4; index++) {
+ if ((elems[index])[0] != '\0') {
+ strcat(ret, "-");
+ strcat(ret, elems[index]);
+ }
+ }
+
+ for (index = 0; index < 5; index++) {
+ free(elems[index]);
+ }
+ } else {
+ ret = NULL;
}
return ret;
@@ -259,12 +277,15 @@
return NULL;
}
-static void
+static boolean
SetupI18nProps(LCID lcid, char** language, char** script, char** country,
char** variant, char** encoding) {
/* script */
char tmp[SNAMESIZE];
*script = malloc(PROPSIZE);
+ if (*script == NULL) {
+ return FALSE;
+ }
if (GetLocaleInfo(lcid,
LOCALE_SNAME, tmp, SNAMESIZE) == 0 ||
sscanf(tmp, "%*[a-z\\-]%1[A-Z]%[a-z]", *script, &((*script)[1])) == 0 ||
@@ -274,6 +295,9 @@
/* country */
*country = malloc(PROPSIZE);
+ if (*country == NULL) {
+ return FALSE;
+ }
if (GetLocaleInfo(lcid,
LOCALE_SISO3166CTRYNAME, *country, PROPSIZE) == 0 &&
GetLocaleInfo(lcid,
@@ -283,6 +307,9 @@
/* language */
*language = malloc(PROPSIZE);
+ if (*language == NULL) {
+ return FALSE;
+ }
if (GetLocaleInfo(lcid,
LOCALE_SISO639LANGNAME, *language, PROPSIZE) == 0 &&
GetLocaleInfo(lcid,
@@ -294,6 +321,9 @@
/* variant */
*variant = malloc(PROPSIZE);
+ if (*variant == NULL) {
+ return FALSE;
+ }
(*variant)[0] = '\0';
/* handling for Norwegian */
@@ -308,6 +338,10 @@
/* encoding */
*encoding = getEncodingInternal(lcid);
+ if (*encoding == NULL) {
+ return FALSE;
+ }
+ return TRUE;
}
java_props_t *
--- a/jdk/src/windows/native/sun/util/locale/provider/HostLocaleProviderAdapter_md.c Thu Feb 06 11:01:27 2014 -0500
+++ b/jdk/src/windows/native/sun/util/locale/provider/HostLocaleProviderAdapter_md.c Thu Feb 06 10:06:09 2014 -0800
@@ -24,6 +24,7 @@
*/
#include "sun_util_locale_provider_HostLocaleProviderAdapterImpl.h"
+#include "jni_util.h"
#include <windows.h>
#include <gdefs.h>
#include <stdlib.h>
@@ -197,8 +198,13 @@
}
localeString = (char *)getJavaIDFromLangID(langid);
- ret = (*env)->NewStringUTF(env, localeString);
- free(localeString);
+ if (localeString != NULL) {
+ ret = (*env)->NewStringUTF(env, localeString);
+ free(localeString);
+ } else {
+ JNU_ThrowOutOfMemoryError(env, "memory allocation error");
+ ret = NULL;
+ }
return ret;
}
@@ -211,6 +217,7 @@
(JNIEnv *env, jclass cls, jint dateStyle, jint timeStyle, jstring jlangtag) {
WCHAR pattern[BUFLEN];
const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
+ CHECK_NULL_RETURN(langtag, NULL);
pattern[0] = L'\0';
@@ -238,8 +245,11 @@
*/
JNIEXPORT jint JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getCalendarID
(JNIEnv *env, jclass cls, jstring jlangtag) {
- const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
- jint ret = getCalendarID(langtag);
+ const jchar *langtag;
+ jint ret;
+ langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
+ CHECK_NULL_RETURN(langtag, 0);
+ ret = getCalendarID(langtag);
(*env)->ReleaseStringChars(env, jlangtag, langtag);
return ret;
}
@@ -252,10 +262,13 @@
JNIEXPORT jobjectArray JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getAmPmStrings
(JNIEnv *env, jclass cls, jstring jlangtag, jobjectArray ampms) {
WCHAR buf[BUFLEN];
- const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
+ const jchar *langtag;
// AM
- int got = getLocaleInfoWrapper(langtag, LOCALE_S1159, buf, BUFLEN);
+ int got;
+ langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
+ CHECK_NULL_RETURN(langtag, NULL);
+ got = getLocaleInfoWrapper(langtag, LOCALE_S1159, buf, BUFLEN);
if (got) {
(*env)->SetObjectArrayElement(env, ampms, 0, (*env)->NewString(env, buf, wcslen(buf)));
}
@@ -280,6 +293,7 @@
(JNIEnv *env, jclass cls, jstring jlangtag, jobjectArray eras) {
WCHAR ad[BUFLEN];
const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
+ CHECK_NULL_RETURN(langtag, eras);
getCalendarInfoWrapper(langtag, getCalendarID(langtag), NULL,
CAL_SERASTRING, ad, BUFLEN, NULL);
@@ -347,10 +361,14 @@
*/
JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getNumberPattern
(JNIEnv *env, jclass cls, jint numberStyle, jstring jlangtag) {
- const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
+ const jchar *langtag;
jstring ret;
+ WCHAR * pattern;
- WCHAR * pattern = getNumberPattern(langtag, numberStyle);
+ langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
+ CHECK_NULL_RETURN(langtag, NULL);
+ pattern = getNumberPattern(langtag, numberStyle);
+ CHECK_NULL_RETURN(pattern, NULL);
(*env)->ReleaseStringChars(env, jlangtag, langtag);
ret = (*env)->NewString(env, pattern, wcslen(pattern));
@@ -367,8 +385,10 @@
JNIEXPORT jboolean JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_isNativeDigit
(JNIEnv *env, jclass cls, jstring jlangtag) {
DWORD num;
+ int got;
const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
- int got = getLocaleInfoWrapper(langtag,
+ CHECK_NULL_RETURN(langtag, JNI_FALSE);
+ got = getLocaleInfoWrapper(langtag,
LOCALE_IDIGITSUBSTITUTION | LOCALE_RETURN_NUMBER,
(LPWSTR)&num, sizeof(num));
(*env)->ReleaseStringChars(env, jlangtag, langtag);
@@ -384,8 +404,10 @@
JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getCurrencySymbol
(JNIEnv *env, jclass cls, jstring jlangtag, jstring currencySymbol) {
WCHAR buf[BUFLEN];
+ int got;
const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
- int got = getLocaleInfoWrapper(langtag, LOCALE_SCURRENCY, buf, BUFLEN);
+ CHECK_NULL_RETURN(langtag, currencySymbol);
+ got = getLocaleInfoWrapper(langtag, LOCALE_SCURRENCY, buf, BUFLEN);
(*env)->ReleaseStringChars(env, jlangtag, langtag);
if (got) {
@@ -403,8 +425,10 @@
JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getDecimalSeparator
(JNIEnv *env, jclass cls, jstring jlangtag, jchar decimalSeparator) {
WCHAR buf[BUFLEN];
+ int got;
const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
- int got = getLocaleInfoWrapper(langtag, LOCALE_SDECIMAL, buf, BUFLEN);
+ CHECK_NULL_RETURN(langtag, decimalSeparator);
+ got = getLocaleInfoWrapper(langtag, LOCALE_SDECIMAL, buf, BUFLEN);
(*env)->ReleaseStringChars(env, jlangtag, langtag);
if (got) {
@@ -422,8 +446,10 @@
JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getGroupingSeparator
(JNIEnv *env, jclass cls, jstring jlangtag, jchar groupingSeparator) {
WCHAR buf[BUFLEN];
+ int got;
const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
- int got = getLocaleInfoWrapper(langtag, LOCALE_STHOUSAND, buf, BUFLEN);
+ CHECK_NULL_RETURN(langtag, groupingSeparator);
+ got = getLocaleInfoWrapper(langtag, LOCALE_STHOUSAND, buf, BUFLEN);
(*env)->ReleaseStringChars(env, jlangtag, langtag);
if (got) {
@@ -441,8 +467,10 @@
JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getInfinity
(JNIEnv *env, jclass cls, jstring jlangtag, jstring infinity) {
WCHAR buf[BUFLEN];
+ int got;
const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
- int got = getLocaleInfoWrapper(langtag, LOCALE_SPOSINFINITY, buf, BUFLEN);
+ CHECK_NULL_RETURN(langtag, infinity);
+ got = getLocaleInfoWrapper(langtag, LOCALE_SPOSINFINITY, buf, BUFLEN);
(*env)->ReleaseStringChars(env, jlangtag, langtag);
if (got) {
@@ -460,8 +488,10 @@
JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getInternationalCurrencySymbol
(JNIEnv *env, jclass cls, jstring jlangtag, jstring internationalCurrencySymbol) {
WCHAR buf[BUFLEN];
+ int got;
const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
- int got = getLocaleInfoWrapper(langtag, LOCALE_SINTLSYMBOL, buf, BUFLEN);
+ CHECK_NULL_RETURN(langtag, internationalCurrencySymbol);
+ got = getLocaleInfoWrapper(langtag, LOCALE_SINTLSYMBOL, buf, BUFLEN);
(*env)->ReleaseStringChars(env, jlangtag, langtag);
if (got) {
@@ -479,8 +509,10 @@
JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getMinusSign
(JNIEnv *env, jclass cls, jstring jlangtag, jchar minusSign) {
WCHAR buf[BUFLEN];
+ int got;
const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
- int got = getLocaleInfoWrapper(langtag, LOCALE_SNEGATIVESIGN, buf, BUFLEN);
+ CHECK_NULL_RETURN(langtag, minusSign);
+ got = getLocaleInfoWrapper(langtag, LOCALE_SNEGATIVESIGN, buf, BUFLEN);
(*env)->ReleaseStringChars(env, jlangtag, langtag);
if (got) {
@@ -498,8 +530,10 @@
JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getMonetaryDecimalSeparator
(JNIEnv *env, jclass cls, jstring jlangtag, jchar monetaryDecimalSeparator) {
WCHAR buf[BUFLEN];
+ int got;
const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
- int got = getLocaleInfoWrapper(langtag, LOCALE_SMONDECIMALSEP, buf, BUFLEN);
+ CHECK_NULL_RETURN(langtag, monetaryDecimalSeparator);
+ got = getLocaleInfoWrapper(langtag, LOCALE_SMONDECIMALSEP, buf, BUFLEN);
(*env)->ReleaseStringChars(env, jlangtag, langtag);
if (got) {
@@ -517,8 +551,10 @@
JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getNaN
(JNIEnv *env, jclass cls, jstring jlangtag, jstring nan) {
WCHAR buf[BUFLEN];
+ int got;
const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
- int got = getLocaleInfoWrapper(langtag, LOCALE_SNAN, buf, BUFLEN);
+ CHECK_NULL_RETURN(langtag, nan);
+ got = getLocaleInfoWrapper(langtag, LOCALE_SNAN, buf, BUFLEN);
(*env)->ReleaseStringChars(env, jlangtag, langtag);
if (got) {
@@ -536,8 +572,10 @@
JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getPercent
(JNIEnv *env, jclass cls, jstring jlangtag, jchar percent) {
WCHAR buf[BUFLEN];
+ int got;
const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
- int got = getLocaleInfoWrapper(langtag, LOCALE_SPERCENT, buf, BUFLEN);
+ CHECK_NULL_RETURN(langtag, percent);
+ got = getLocaleInfoWrapper(langtag, LOCALE_SPERCENT, buf, BUFLEN);
(*env)->ReleaseStringChars(env, jlangtag, langtag);
if (got) {
@@ -555,8 +593,12 @@
JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getPerMill
(JNIEnv *env, jclass cls, jstring jlangtag, jchar perMill) {
WCHAR buf[BUFLEN];
- const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
- int got = getLocaleInfoWrapper(langtag, LOCALE_SPERMILLE, buf, BUFLEN);
+ const jchar *langtag;
+ int got;
+ langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
+ CHECK_NULL_RETURN(langtag, perMill);
+ got = getLocaleInfoWrapper(langtag, LOCALE_SPERMILLE, buf, BUFLEN);
+
(*env)->ReleaseStringChars(env, jlangtag, langtag);
if (got) {
@@ -574,8 +616,12 @@
JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getZeroDigit
(JNIEnv *env, jclass cls, jstring jlangtag, jchar zeroDigit) {
WCHAR buf[BUFLEN];
- const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
- int got = getLocaleInfoWrapper(langtag, LOCALE_SNATIVEDIGITS, buf, BUFLEN);
+ const jchar *langtag;
+ int got;
+ langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
+ CHECK_NULL_RETURN(langtag, zeroDigit);
+ got = getLocaleInfoWrapper(langtag, LOCALE_SNATIVEDIGITS, buf, BUFLEN);
+
(*env)->ReleaseStringChars(env, jlangtag, langtag);
if (got) {
@@ -593,9 +639,11 @@
JNIEXPORT jint JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getCalendarDataValue
(JNIEnv *env, jclass cls, jstring jlangtag, jint type) {
DWORD num;
- const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
+ const jchar *langtag;
int got = 0;
+ langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
+ CHECK_NULL_RETURN(langtag, -1);
switch (type) {
case sun_util_locale_provider_HostLocaleProviderAdapterImpl_CD_FIRSTDAYOFWEEK:
got = getLocaleInfoWrapper(langtag,
@@ -648,6 +696,7 @@
}
pjChar = (*env)->GetStringChars(env, jStr, JNI_FALSE);
+ CHECK_NULL_RETURN(pjChar, NULL);
got = getLocaleInfoWrapper(pjChar, lcType, buf, BUFLEN);
(*env)->ReleaseStringChars(env, jStr, pjChar);
@@ -705,8 +754,11 @@
void replaceCalendarArrayElems(JNIEnv *env, jstring jlangtag, jobjectArray jarray, CALTYPE* pCalTypes, int offset, int length) {
WCHAR name[BUFLEN];
- const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
- int calid = getCalendarID(langtag);
+ const jchar *langtag;
+ int calid;
+ langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
+ CHECK_NULL(langtag);
+ calid = getCalendarID(langtag);
if (calid != -1) {
int i;