From b87215bbaf5763a4e368c6b8025b103b5e266ad0 Mon Sep 17 00:00:00 2001 From: tg Date: Sun, 5 Jul 2015 16:47:28 +0000 Subject: [PATCH] =?UTF-8?q?when=20storing=20commands=20with=20embedded=20n?= =?UTF-8?q?ewlines,=20don=E2=80=99t=20take=20those=20as=20end=20of=20strin?= =?UTF-8?q?g=20(inspired=20fix=20from=20Debian=20#783978;=20bug=20in=20ori?= =?UTF-8?q?ginal=20pdksh=20COMPLEX=5FHISTORY=20code)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- histrap.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/histrap.c b/histrap.c index 37ee258..4bd9066 100644 --- a/histrap.c +++ b/histrap.c @@ -27,7 +27,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.143 2015/04/29 20:44:35 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.144 2015/07/05 16:47:28 tg Exp $"); Trap sigtraps[ksh_NSIG + 1]; static struct sigaction Sigact_ign; @@ -634,11 +634,13 @@ void histsave(int *lnp, const char *cmd, bool dowrite MKSH_A_UNUSED, bool ignoredups) { char **hp; - char *c, *cp; + char *c; + const char *ccp; - strdupx(c, cmd, APERM); - if ((cp = strchr(c, '\n')) != NULL) - *cp = '\0'; + ccp = cmd + strlen(cmd); + while (ccp > cmd && ccp[-1] == '\n') + --ccp; + strndupx(c, cmd, ccp - cmd, APERM); if (ignoredups && !strcmp(c, *histptr) #if !defined(MKSH_SMALL) && HAVE_PERSISTENT_HISTORY