Hello List, 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 = ""; ---> if (!tmp) tmp = getenv("NAME"); > 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 = ""; ---> if (!tmp) tmp = getenv("NAME"); > if (!tmp) tmp = "";
Thanks very much Marcus for the bug report and the patch. Applied: http://lists.cs.uiuc.edu/pipermail/vmkit-commits/2011-June/002023.html Cheers, Nicolas On Fri, Jun 10, 2011 at 2:58 PM, marcus <marcus at mh-development.info> wrote:> 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 = ""; > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110614/6ac6e952/attachment.html>