[LLVMdev] [VMKit] Bug in J3 User.Name detection

marcus marcus at mh-development.info
Fri Jun 10 05:58:04 PDT 2011


 Please excuse the previous mail. My mailclient misbehaved.

 The below code to check for the environment variable NAME and for 
 setting a default username of "" fails, because the else paths are only 
 taken when there inside if condition is false anyways. The elses should 
 not be there but instead each method should be used until a username is 
 returned.

 lib/J3/Classpath/ClasspathVMSystemProperties.inc

 tmp = getenv("USERNAME");
 if (!tmp) tmp = getenv("LOGNAME");
 else if (!tmp) tmp = getenv("NAME");
 else if (!tmp) tmp = "";

 The proper way to do this would be

 tmp = getenv("USERNAME");
 if (!tmp) tmp = getenv("LOGNAME");
 if (!tmp) tmp = getenv("NAME");
 if (!tmp) tmp = "";

 because then you don't fall victim to the dangling else problem of the 
 current implementation.
 The bug manifests in that setProperty fails if provided with a null 
 pointer as value. (Occurs if neither USERNAME nor LOGNAME are set in the 
 environment)

 Regards,

 Marcus

 --- Patch to fix the behaviour ----

 diff a/ClasspathVMSystemProperties.inc
 b/ClasspathVMSystemProperties.inc
 118,119c118,119
 <   else if (!tmp) tmp = getenv("NAME");
 <   else if (!tmp) tmp = "";
 ---
>  if (!tmp) tmp = getenv("NAME");
>  if (!tmp) tmp = "";




More information about the llvm-dev mailing list