From e964872f186de0c0ad0640d3a0fda1aff0f8e7c1 Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Thu, 8 Nov 2012 13:33:48 +0000 Subject: [PATCH] sh: Fix two issues when an alias is redefined: * The last character is not displayed. * If the alias ends with itself (as a word), an infinite memory-eating loop occurs. If an alias is defined initially, a space is appended to avoid recursion but this did not happen when an alias was later modified. PR: bin/173418 Submitted by: Daniel F. MFC after: 1 week --- bin/sh/alias.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/bin/sh/alias.c b/bin/sh/alias.c index fb0e92294431..da995bbd4733 100644 --- a/bin/sh/alias.c +++ b/bin/sh/alias.c @@ -68,7 +68,18 @@ setalias(const char *name, const char *val) if (equal(name, ap->name)) { INTOFF; ckfree(ap->val); + /* See HACK below. */ +#ifdef notyet ap->val = savestr(val); +#else + { + size_t len = strlen(val); + ap->val = ckmalloc(len + 2); + memcpy(ap->val, val, len); + ap->val[len] = ' '; + ap->val[len+1] = '\0'; + } +#endif INTON; return; }