From abfc710b0bb83b4c6db83ede9b01e3c0d26d2738 Mon Sep 17 00:00:00 2001 From: Jason Lowe Date: Wed, 4 Nov 2015 16:34:01 +0000 Subject: [PATCH] HADOOP-12296. when setnetgrent returns 0 in linux, exception should be thrown. Contributed by Chang Li (cherry picked from commit b9d25c3ee2d20166d6a786c5a16cc001e249f61c) --- .../hadoop-common/CHANGES.txt | 3 +++ .../JniBasedUnixGroupsNetgroupMapping.c | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 07d9ef06000..561d8a27553 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -12,6 +12,9 @@ Release 2.7.3 - UNRELEASED BUG FIXES + HADOOP-12296. when setnetgrent returns 0 in linux, exception should be + thrown (Chang Li via jlowe) + Release 2.7.2 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/security/JniBasedUnixGroupsNetgroupMapping.c b/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/security/JniBasedUnixGroupsNetgroupMapping.c index de73a8ae683..4ae1051578f 100644 --- a/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/security/JniBasedUnixGroupsNetgroupMapping.c +++ b/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/security/JniBasedUnixGroupsNetgroupMapping.c @@ -57,6 +57,7 @@ Java_org_apache_hadoop_security_JniBasedUnixGroupsNetgroupMapping_getUsersForNet int setnetgrentCalledFlag = 0; // if not NULL then THROW exception + char *errorType = NULL; char *errorMessage = NULL; cgroup = (*env)->GetStringUTFChars(env, jgroup, NULL); @@ -94,7 +95,14 @@ Java_org_apache_hadoop_security_JniBasedUnixGroupsNetgroupMapping_getUsersForNet } } } - +#if defined(__linux__) + else { + errorType = "java/io/IOException"; + errorMessage = + "no netgroup of this name is known or some other error occurred"; + goto END; + } +#endif //-------------------------------------------------- // build return data (java array) @@ -103,7 +111,7 @@ Java_org_apache_hadoop_security_JniBasedUnixGroupsNetgroupMapping_getUsersForNet (*env)->FindClass(env, "java/lang/String"), NULL); if (jusers == NULL) { - errorMessage = "java/lang/OutOfMemoryError"; + errorType = "java/lang/OutOfMemoryError"; goto END; } @@ -114,7 +122,7 @@ Java_org_apache_hadoop_security_JniBasedUnixGroupsNetgroupMapping_getUsersForNet for(current = userListHead; current != NULL; current = current->next) { jstring juser = (*env)->NewStringUTF(env, current->string); if (juser == NULL) { - errorMessage = "java/lang/OutOfMemoryError"; + errorType = "java/lang/OutOfMemoryError"; goto END; } (*env)->SetObjectArrayElement(env, jusers, i++, juser); @@ -134,8 +142,8 @@ END: } // return results or THROW - if(errorMessage) { - THROW(env, errorMessage, NULL); + if(errorType) { + THROW(env, errorType, errorMessage); return NULL; } else { return jusers;