• R/O
  • SSH
  • HTTPS

yash: Commit


Commit MetaInfo

Revision4179 (tree)
Time2021-12-16 01:07:52
Authormagicant

Log Message

Don't crash on unquoting unclosed quotes (#43398)

Change Summary

Incremental Difference

--- yash/trunk/NEWS (revision 4178)
+++ yash/trunk/NEWS (revision 4179)
@@ -13,6 +13,8 @@
1313 * Fixed a bug where command substitutions contained in the regular
1414 expression inside the "[[ word =~ regex ]]" syntax were not
1515 parsed correctly.
16+ * Fixed a bug where unclosed quotes in an end-of-here-document
17+ indicator were causing the shell to crash or misbehave.
1618
1719 ----------------------------------------------------------------------
1820 Yash 2.52 (2021-10-11)
--- yash/trunk/expand.c (revision 4178)
+++ yash/trunk/expand.c (revision 4179)
@@ -469,6 +469,7 @@
469469 sb_ccat(&ccbuf, defaultcc | CC_QUOTATION);
470470
471471 add_sq(&ss, &valuebuf, false);
472+ assert(*ss == L'\'');
472473 fill_ccbuf(&valuebuf, &ccbuf, defaultcc | CC_QUOTED);
473474
474475 wb_wccat(&valuebuf, L'\'');
@@ -1681,6 +1682,7 @@
16811682 * buffer.
16821683 * `ss' is a pointer to a pointer to the opening quote in the string.
16831684 * `*ss' is incremented so that it points to the closing quote.
1685+ * If there is no closing quote, `*ss' will point to the L'\0' terminator.
16841686 * If `escape' is true, all the characters added are backslashed. */
16851687 void add_sq(const wchar_t *restrict *ss, xwcsbuf_T *restrict buf, bool escape)
16861688 {
@@ -1689,7 +1691,6 @@
16891691 (*ss)++;
16901692 switch (**ss) {
16911693 case L'\0':
1692- assert(false);
16931694 case L'\'':
16941695 return;
16951696 default:
@@ -1827,6 +1828,9 @@
18271828 if (indq)
18281829 goto default_case;
18291830 add_sq(&s, &buf, false);
1831+ if (*s == L'\0')
1832+ return wb_towcs(&buf);
1833+ assert(*s == L'\'');
18301834 break;
18311835 case L'"':
18321836 indq = !indq;
Show on old repository browser