#28 parseAcl method has a bug

open
nobody
None
5
2008-07-25
2008-07-25
Anonymous
No

code for finding colons is incorrect. It gets the same colon twice and then considers it a wrong parse

private static ArrayList<ACL> parseACLs(String aclString) {
ArrayList<ACL> acl;
String acls[] = aclString.split(",");
acl = new ArrayList<ACL>();
for (String a : acls) {
int firstColon = a.indexOf(':');
int lastColon = a.indexOf(':');
if (firstColon == -1 || lastColon == -1 || firstColon == lastColon) { //HERE**** <- first and last colon indexes are always the same****
System.err
.println(a + " does not have the form scheme:id:perm");
continue;
}
ACL newAcl = new ACL();
newAcl.setId(new Id(a.substring(0, firstColon), a.substring(
firstColon + 1, lastColon)));
newAcl.setPerms(getPermFromString(a.substring(lastColon + 1)));
acl.add(newAcl);
}
return acl;
}

Discussion

  • Logged In: NO

    This is in ZooKeeper class.

     
  • Don Pinto
    Don Pinto
    2008-08-30

    Logged In: YES
    user_id=1289601
    Originator: NO

    Is changing lastColon = a.indexOf(":"); to lastColon = a.lastIndexOf(":"); a proper fix ?
    If so, I can submit a patch for this.

    --Don Pinto

     
  • Don Pinto
    Don Pinto
    2008-08-31

    Logged In: YES
    user_id=1289601
    Originator: NO

    I already submitted a patch for this in patches section.