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
This commit is contained in:
Jilles Tjoelker 2012-11-08 13:33:48 +00:00
parent b72d9fd455
commit e964872f18
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=242766

View File

@ -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;
}