]> granicus.if.org Git - sudo/commitdiff
fix bugs with prompt expansion
authorTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 5 Nov 1998 03:24:40 +0000 (03:24 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 5 Nov 1998 03:24:40 +0000 (03:24 +0000)
check.c

diff --git a/check.c b/check.c
index fbf953113861d26f669b7ab642b63da6b5fa248d..b278997dac6c52a636c2031fa80f68e2a4cc7225 100644 (file)
--- a/check.c
+++ b/check.c
@@ -965,9 +965,10 @@ static char *expand_prompt(old_prompt, user, host)
            }
        }
 
-       if (lastchar == '%' && *p == '%')
+       if (lastchar == '%' && *p == '%') {
            lastchar = '\0';
-       else
+           len--;
+       } else
            lastchar = *p;
     }
 
@@ -977,12 +978,14 @@ static char *expand_prompt(old_prompt, user, host)
            exit(1);
        }
        for (p = prompt, np = new_prompt; *p; p++) {
-           if (lastchar == '%' && (*p == 'h' || *p == 'u')) {
+           if (lastchar == '%' && (*p == 'h' || *p == 'u' || *p == '%')) {
                /* substiture user/host name */
                if (*p == 'h') {
+                   np--;
                    strcpy(np, shost);
                    np += strlen(shost);
                } else if (*p == 'u') {
+                   np--;
                    strcpy(np, user_name);
                    np += strlen(user_name);
                }
@@ -994,6 +997,7 @@ static char *expand_prompt(old_prompt, user, host)
            else
                lastchar = *p;
        }
+       *np = '\0';
     } else
        new_prompt = prompt;