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

nicolas geoffray nicolas.geoffray at gmail.com
Mon Jun 13 15:26:35 PDT 2011


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>


More information about the llvm-dev mailing list