summaryrefslogtreecommitdiffstats
path: root/base/common/src/com/netscape/cmscore
diff options
context:
space:
mode:
authorAbhishek Koneru <akoneru@redhat.com>2012-06-15 10:28:40 -0400
committerEndi Sukma Dewata <edewata@redhat.com>2012-06-20 09:33:31 -0500
commitd5d0b91bc5597eec19520cee74569e9ddacc2090 (patch)
tree414a43625acd2e3f44c39cdd87912e5c562930e7 /base/common/src/com/netscape/cmscore
parent4880d86856d183d4ba3fb0291519353ac238af5d (diff)
downloadpki-d5d0b91bc5597eec19520cee74569e9ddacc2090.tar.gz
pki-d5d0b91bc5597eec19520cee74569e9ddacc2090.tar.xz
pki-d5d0b91bc5597eec19520cee74569e9ddacc2090.zip
Fixes for Coverity Issues of type Null Returns - Part 3
Diffstat (limited to 'base/common/src/com/netscape/cmscore')
-rw-r--r--base/common/src/com/netscape/cmscore/profile/ProfileSubsystem.java2
-rw-r--r--base/common/src/com/netscape/cmscore/security/KeyCertUtil.java7
-rw-r--r--base/common/src/com/netscape/cmscore/usrgrp/UGSubsystem.java40
3 files changed, 36 insertions, 13 deletions
diff --git a/base/common/src/com/netscape/cmscore/profile/ProfileSubsystem.java b/base/common/src/com/netscape/cmscore/profile/ProfileSubsystem.java
index 7da1cc332..45807d6e9 100644
--- a/base/common/src/com/netscape/cmscore/profile/ProfileSubsystem.java
+++ b/base/common/src/com/netscape/cmscore/profile/ProfileSubsystem.java
@@ -97,7 +97,7 @@ public class ProfileSubsystem implements IProfileSubsystem {
String classid = subStore.getString(PROP_CLASS_ID);
IPluginInfo info = registry.getPluginInfo("profile", classid);
if (info == null) {
- throw new EBaseException("No plugins for type : profile with id " + classid);
+ throw new EBaseException("No plugins for type : profile, with id " + classid);
}
String configPath = subStore.getString(PROP_CONFIG);
diff --git a/base/common/src/com/netscape/cmscore/security/KeyCertUtil.java b/base/common/src/com/netscape/cmscore/security/KeyCertUtil.java
index 844052e4b..80ad36c2d 100644
--- a/base/common/src/com/netscape/cmscore/security/KeyCertUtil.java
+++ b/base/common/src/com/netscape/cmscore/security/KeyCertUtil.java
@@ -1056,8 +1056,11 @@ public class KeyCertUtil {
String dn = "ou=certificateRepository,ou=ca," + baseDN;
BigInteger serialno = null;
LDAPEntry entry = conn.read(dn);
- String serialnoStr = (String) entry.getAttribute(
- "serialno").getStringValues().nextElement();
+ LDAPAttribute serialNo = entry.getAttribute("serialno");
+ if (serialNo == null) {
+ throw new LDAPException("No value for attribute serial number in LDAP entry " + entry.getDN());
+ }
+ String serialnoStr = (String) serialNo.getStringValues().nextElement();
serialno = BigIntegerMapper.BigIntegerFromDB(serialnoStr);
LDAPAttribute attr = new LDAPAttribute("serialno");
diff --git a/base/common/src/com/netscape/cmscore/usrgrp/UGSubsystem.java b/base/common/src/com/netscape/cmscore/usrgrp/UGSubsystem.java
index 95e213541..20ad26524 100644
--- a/base/common/src/com/netscape/cmscore/usrgrp/UGSubsystem.java
+++ b/base/common/src/com/netscape/cmscore/usrgrp/UGSubsystem.java
@@ -416,8 +416,11 @@ public final class UGSubsystem implements IUGSubsystem {
* @return the User entity.
*/
protected IUser lbuildUser(LDAPEntry entry) throws EUsrGrpException {
- IUser id = createUser(this, (String)
- entry.getAttribute("uid").getStringValues().nextElement());
+ LDAPAttribute uid = entry.getAttribute("uid");
+ if (uid == null) {
+ throw new EUsrGrpException("No Attribute UID in LDAP Entry " + entry.getDN());
+ }
+ IUser id = createUser(this, (String) uid.getStringValues().nextElement());
LDAPAttribute cnAttr = entry.getAttribute("cn");
if (cnAttr != null) {
@@ -472,8 +475,11 @@ public final class UGSubsystem implements IUGSubsystem {
* @return the User entity.
*/
protected IUser buildUser(LDAPEntry entry) throws EUsrGrpException {
- IUser id = createUser(this, (String)
- entry.getAttribute("uid").getStringValues().nextElement());
+ LDAPAttribute uid = entry.getAttribute("uid");
+ if (uid == null) {
+ throw new EUsrGrpException("No Attribute UID in LDAP Entry " + entry.getDN());
+ }
+ IUser id = createUser(this, (String) uid.getStringValues().nextElement());
LDAPAttribute cnAttr = entry.getAttribute("cn");
if (cnAttr != null) {
@@ -1119,7 +1125,7 @@ public final class UGSubsystem implements IUGSubsystem {
}
}
- protected Enumeration<IGroup> buildGroups(LDAPSearchResults res) {
+ protected Enumeration<IGroup> buildGroups(LDAPSearchResults res) throws EUsrGrpException {
Vector<IGroup> v = new Vector<IGroup>();
while (res.hasMoreElements()) {
@@ -1132,8 +1138,9 @@ public final class UGSubsystem implements IUGSubsystem {
/**
* Finds groups.
+ * @throws EUsrGrpException
*/
- public Enumeration<IGroup> findGroups(String filter) {
+ public Enumeration<IGroup> findGroups(String filter) throws EUsrGrpException {
if (filter == null) {
return null;
}
@@ -1160,7 +1167,7 @@ public final class UGSubsystem implements IUGSubsystem {
}
}
- public IGroup findGroup(String filter) {
+ public IGroup findGroup(String filter) throws EUsrGrpException {
Enumeration<IGroup> groups = findGroups(filter);
if (groups == null || !groups.hasMoreElements())
@@ -1205,9 +1212,14 @@ public final class UGSubsystem implements IUGSubsystem {
/**
* builds an instance of a Group entry
+ * @throws EUsrGrpException
*/
- protected IGroup buildGroup(LDAPEntry entry) {
- String groupName = (String) entry.getAttribute("cn").getStringValues().nextElement();
+ protected IGroup buildGroup(LDAPEntry entry) throws EUsrGrpException {
+ LDAPAttribute cn = entry.getAttribute("cn");
+ if (cn == null) {
+ throw new EUsrGrpException("Cannot build group. No Attribute cn in LDAP Entry " + entry.getDN());
+ }
+ String groupName = (String) cn.getStringValues().nextElement();
IGroup grp = createGroup(this, groupName);
LDAPAttribute grpDesc = entry.getAttribute("description");
@@ -1357,7 +1369,9 @@ public final class UGSubsystem implements IUGSubsystem {
public boolean isMemberOf(String userid, String groupname) {
try {
IUser user = getUser(userid);
- return isMemberOfLdapGroup(user.getUserDN(), groupname);
+ if (user != null) {
+ return isMemberOfLdapGroup(user.getUserDN(), groupname);
+ }
} catch (Exception e) {
/* do nothing */
}
@@ -1630,6 +1644,12 @@ public final class UGSubsystem implements IUGSubsystem {
protected boolean isMatched(String dn1, String dn2) {
String rdn1[] = LDAPDN.explodeDN(dn1, false);
String rdn2[] = LDAPDN.explodeDN(dn2, false);
+ if (rdn1 == null && rdn2 == null) {
+ return true;
+ }
+ if (rdn1 == null || rdn2 == null) {
+ return false;
+ }
if (rdn1.length == rdn2.length) {
for (int j = 0; j < rdn1.length; j++) {