Author: vangyzen
Date: Wed May  4 02:06:46 2016
New Revision: 299035
URL: https://svnweb.freebsd.org/changeset/base/299035

Log:
  sh: Handle empty hostname and $PWD when building prompt
  
  If the hostname is empty and \h is used in $PS1,
  the remainder of the prompt following \h will be empty.
  Likewise for $PWD and \w.  Fix it.
  
  Reviewed by:  jilles
  MFC after:    1 week
  Sponsored by: Dell Inc.
  Differential Revision:        https://reviews.freebsd.org/D6188

Modified:
  head/bin/sh/parser.c

Modified: head/bin/sh/parser.c
==============================================================================
--- head/bin/sh/parser.c        Wed May  4 01:56:37 2016        (r299034)
+++ head/bin/sh/parser.c        Wed May  4 02:06:46 2016        (r299035)
@@ -2014,8 +2014,9 @@ getprompt(void *unused __unused)
                                gethostname(&ps[i], PROMPTLEN - i);
                                /* Skip to end of hostname. */
                                trim = (*fmt == 'h') ? '.' : '\0';
-                               while ((ps[i+1] != '\0') && (ps[i+1] != trim))
+                               while ((ps[i] != '\0') && (ps[i] != trim))
                                        i++;
+                               --i;
                                break;
 
                                /*
@@ -2027,7 +2028,7 @@ getprompt(void *unused __unused)
                        case 'W':
                        case 'w':
                                pwd = lookupvar("PWD");
-                               if (pwd == NULL)
+                               if (pwd == NULL || *pwd == '\0')
                                        pwd = "?";
                                if (*fmt == 'W' &&
                                    *pwd == '/' && pwd[1] != '\0')
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to