From 950ab581668ed5c5cdb6c60ad27393e6c11fdef3 Mon Sep 17 00:00:00 2001 From: Chris Hegarty Date: Fri, 7 Mar 2008 07:25:17 -0800 Subject: [PATCH] 6628661: NTLM-authentication doesn't work with non-ASCII letters Use JNU_GetStringPlatformChars to convert jstrings to the locale specific native C strings Reviewed-by: michaelm --- .../net/www/protocol/http/NTLMAuthSequence.c | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/jdk/src/windows/native/sun/net/www/protocol/http/NTLMAuthSequence.c b/jdk/src/windows/native/sun/net/www/protocol/http/NTLMAuthSequence.c index 4d4e56ee80..580e2fabad 100644 --- a/jdk/src/windows/native/sun/net/www/protocol/http/NTLMAuthSequence.c +++ b/jdk/src/windows/native/sun/net/www/protocol/http/NTLMAuthSequence.c @@ -36,6 +36,8 @@ #include #include +#include "jni_util.h" + #define SECURITY_WIN32 #include "sspi.h" #include "issperr.h" @@ -117,22 +119,36 @@ JNIEXPORT jlong JNICALL Java_sun_net_www_protocol_http_NTLMAuthSequence_getCrede { SEC_WINNT_AUTH_IDENTITY AuthId; SEC_WINNT_AUTH_IDENTITY * pAuthId; - CHAR *pUser = 0; - CHAR *pDomain = 0; - CHAR *pPassword = 0; + const CHAR *pUser = 0; + const CHAR *pDomain = 0; + const CHAR *pPassword = 0; CredHandle *pCred; TimeStamp ltime; jboolean isCopy; SECURITY_STATUS ss; if (user != 0) { - pUser = (CHAR *)(*env)->GetStringUTFChars(env, user, &isCopy); + pUser = JNU_GetStringPlatformChars(env, user, &isCopy); + if (pUser == NULL) + return 0; // pending Exception } if (domain != 0) { - pDomain = (CHAR *)(*env)->GetStringUTFChars(env, domain, &isCopy); + pDomain = JNU_GetStringPlatformChars(env, domain, &isCopy); + if (pDomain == NULL) { + if (pUser != NULL) + JNU_ReleaseStringPlatformChars(env, user, pUser); + return 0; // pending Exception + } } if (password != 0) { - pPassword = (CHAR *)(*env)->GetStringUTFChars(env, password, &isCopy); + pPassword = JNU_GetStringPlatformChars(env, password, &isCopy); + if (pPassword == NULL) { + if(pUser != NULL) + JNU_ReleaseStringPlatformChars(env, user, pUser); + if(pDomain != NULL) + JNU_ReleaseStringPlatformChars(env, domain, pDomain); + return 0; // pending Exception + } } pCred = (CredHandle *)malloc(sizeof (CredHandle)); @@ -167,6 +183,14 @@ JNIEXPORT jlong JNICALL Java_sun_net_www_protocol_http_NTLMAuthSequence_getCrede pCred, <ime ); + /* Release resources held by JNU_GetStringPlatformChars */ + if (pUser != NULL) + JNU_ReleaseStringPlatformChars(env, user, pUser); + if (pPassword != NULL) + JNU_ReleaseStringPlatformChars(env, password, pPassword); + if (pDomain != NULL) + JNU_ReleaseStringPlatformChars(env, domain, pDomain); + if (ss == 0) { return (jlong) pCred; } else { @@ -181,7 +205,6 @@ JNIEXPORT jbyteArray JNICALL Java_sun_net_www_protocol_http_NTLMAuthSequence_get VOID *pInput = 0; DWORD inputLen; CHAR buffOut[512]; - DWORD pcbBuffOut; jboolean isCopy; SECURITY_STATUS ss; SecBufferDesc OutBuffDesc;