提交 6d78d4d9 编写于 作者: M msheppar

8035870: Check jdk/src/windows/native/java/io/WinNTFileSystem_md.c for JNI pending exceptions

Summary: NI return checks, NULL return checks for malloc added
Reviewed-by: alanb, chegar
上级 4c304bf7
/* /*
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -83,7 +83,7 @@ extern int wcanonicalizeWithPrefix(const WCHAR *canonicalPrefix, const WCHAR *pa ...@@ -83,7 +83,7 @@ extern int wcanonicalizeWithPrefix(const WCHAR *canonicalPrefix, const WCHAR *pa
* Retrieves the fully resolved (final) path for the given path or NULL * Retrieves the fully resolved (final) path for the given path or NULL
* if the function fails. * if the function fails.
*/ */
static WCHAR* getFinalPath(const WCHAR *path) static WCHAR* getFinalPath(JNIEnv *env, const WCHAR *path)
{ {
HANDLE h; HANDLE h;
WCHAR *result; WCHAR *result;
...@@ -119,6 +119,7 @@ static WCHAR* getFinalPath(const WCHAR *path) ...@@ -119,6 +119,7 @@ static WCHAR* getFinalPath(const WCHAR *path)
len = (*GetFinalPathNameByHandle_func)(h, result, len, 0); len = (*GetFinalPathNameByHandle_func)(h, result, len, 0);
} else { } else {
len = 0; len = 0;
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
} }
} }
...@@ -139,6 +140,7 @@ static WCHAR* getFinalPath(const WCHAR *path) ...@@ -139,6 +140,7 @@ static WCHAR* getFinalPath(const WCHAR *path)
/* copy result without prefix into new buffer */ /* copy result without prefix into new buffer */
WCHAR *tmp = (WCHAR*)malloc(resultLen * sizeof(WCHAR)); WCHAR *tmp = (WCHAR*)malloc(resultLen * sizeof(WCHAR));
if (tmp == NULL) { if (tmp == NULL) {
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
len = 0; len = 0;
} else { } else {
WCHAR *p = result; WCHAR *p = result;
...@@ -162,6 +164,8 @@ static WCHAR* getFinalPath(const WCHAR *path) ...@@ -162,6 +164,8 @@ static WCHAR* getFinalPath(const WCHAR *path)
free(result); free(result);
result = NULL; result = NULL;
} }
} else {
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
} }
error = GetLastError(); error = GetLastError();
...@@ -255,6 +259,8 @@ Java_java_io_WinNTFileSystem_canonicalize0(JNIEnv *env, jobject this, ...@@ -255,6 +259,8 @@ Java_java_io_WinNTFileSystem_canonicalize0(JNIEnv *env, jobject this,
rv = (*env)->NewString(env, cp, (jsize)wcslen(cp)); rv = (*env)->NewString(env, cp, (jsize)wcslen(cp));
} }
free(cp); free(cp);
} else {
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
} }
} else } else
if (wcanonicalize(path, canonicalPath, MAX_PATH_LENGTH) >= 0) { if (wcanonicalize(path, canonicalPath, MAX_PATH_LENGTH) >= 0) {
...@@ -287,6 +293,8 @@ Java_java_io_WinNTFileSystem_canonicalizeWithPrefix0(JNIEnv *env, jobject this, ...@@ -287,6 +293,8 @@ Java_java_io_WinNTFileSystem_canonicalizeWithPrefix0(JNIEnv *env, jobject this,
rv = (*env)->NewString(env, cp, (jsize)wcslen(cp)); rv = (*env)->NewString(env, cp, (jsize)wcslen(cp));
} }
free(cp); free(cp);
} else {
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
} }
} else } else
if (wcanonicalizeWithPrefix(canonicalPrefix, if (wcanonicalizeWithPrefix(canonicalPrefix,
...@@ -434,7 +442,7 @@ Java_java_io_WinNTFileSystem_setPermission(JNIEnv *env, jobject this, ...@@ -434,7 +442,7 @@ Java_java_io_WinNTFileSystem_setPermission(JNIEnv *env, jobject this,
if ((a != INVALID_FILE_ATTRIBUTES) && if ((a != INVALID_FILE_ATTRIBUTES) &&
((a & FILE_ATTRIBUTE_REPARSE_POINT) != 0)) ((a & FILE_ATTRIBUTE_REPARSE_POINT) != 0))
{ {
WCHAR *fp = getFinalPath(pathbuf); WCHAR *fp = getFinalPath(env, pathbuf);
if (fp == NULL) { if (fp == NULL) {
a = INVALID_FILE_ATTRIBUTES; a = INVALID_FILE_ATTRIBUTES;
} else { } else {
...@@ -624,6 +632,7 @@ Java_java_io_WinNTFileSystem_list(JNIEnv *env, jobject this, jobject file) ...@@ -624,6 +632,7 @@ Java_java_io_WinNTFileSystem_list(JNIEnv *env, jobject this, jobject file)
if (search_path == 0) { if (search_path == 0) {
free (pathbuf); free (pathbuf);
errno = ENOMEM; errno = ENOMEM;
JNU_ThrowOutOfMemoryError(env, "native memory allocation faiuled");
return NULL; return NULL;
} }
wcscpy(search_path, pathbuf); wcscpy(search_path, pathbuf);
...@@ -801,7 +810,7 @@ Java_java_io_WinNTFileSystem_setReadOnly(JNIEnv *env, jobject this, ...@@ -801,7 +810,7 @@ Java_java_io_WinNTFileSystem_setReadOnly(JNIEnv *env, jobject this,
if ((a != INVALID_FILE_ATTRIBUTES) && if ((a != INVALID_FILE_ATTRIBUTES) &&
((a & FILE_ATTRIBUTE_REPARSE_POINT) != 0)) ((a & FILE_ATTRIBUTE_REPARSE_POINT) != 0))
{ {
WCHAR *fp = getFinalPath(pathbuf); WCHAR *fp = getFinalPath(env, pathbuf);
if (fp == NULL) { if (fp == NULL) {
a = INVALID_FILE_ATTRIBUTES; a = INVALID_FILE_ATTRIBUTES;
} else { } else {
......
/* /*
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -191,9 +191,9 @@ pathToNTPath(JNIEnv *env, jstring path, jboolean throwFNFE) { ...@@ -191,9 +191,9 @@ pathToNTPath(JNIEnv *env, jstring path, jboolean throwFNFE) {
int dirlen = currentDirLength(ps, pathlen); int dirlen = currentDirLength(ps, pathlen);
if (dirlen + pathlen + 1 > max_path - 1) { if (dirlen + pathlen + 1 > max_path - 1) {
pathbuf = prefixAbpath(ps, pathlen, dirlen + pathlen); pathbuf = prefixAbpath(ps, pathlen, dirlen + pathlen);
if( pathbuf == NULL) { if (pathbuf == NULL) {
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed"); JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
return NULL; return NULL;
} }
} else { } else {
pathbuf = (WCHAR*)malloc((pathlen + 6) * sizeof(WCHAR)); pathbuf = (WCHAR*)malloc((pathlen + 6) * sizeof(WCHAR));
...@@ -216,12 +216,17 @@ pathToNTPath(JNIEnv *env, jstring path, jboolean throwFNFE) { ...@@ -216,12 +216,17 @@ pathToNTPath(JNIEnv *env, jstring path, jboolean throwFNFE) {
return NULL; return NULL;
} else { } else {
pathbuf = (WCHAR*)malloc(sizeof(WCHAR)); pathbuf = (WCHAR*)malloc(sizeof(WCHAR));
pathbuf[0] = L'\0'; if (pathbuf != NULL) {
pathbuf[0] = L'\0';
} else {
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
return NULL;
}
} }
} }
if (pathbuf == 0) { if (pathbuf == 0) {
if (!(*env)->ExceptionCheck(env)) { if (!(*env)->ExceptionCheck(env)) {
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed"); JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
} }
return NULL; return NULL;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册