I'm currently trying to compile VMKit for the L4 Operating System and the L4Re Runtime environment for my student project.
While doing so I stumbled upon a bug in the implementation of lib/J3/Classpath/ClasspathVMSystemProperties.inc
The current version first tries to get the username by checking the LOGNAME environment variable. If this is NULL it then checks
tmp = getenv("USERNAME");
if (!tmp) tmp = getenv("LOGNAME");
else if (!tmp) tmp = getenv("NAME");
else if (!tmp) tmp = "";
setProperty(vm, prop, "user.
diff a/ClasspathVMSystemProperties.inc b/ClasspathVMSystemProperties.inc
118,119c118,119
< else if (!tmp) tmp = getenv("NAME");
< else if (!tmp) tmp = "";
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 = "";