• R/O
  • SSH
  • HTTPS

yash: 提交


Commit MetaInfo

修訂4180 (tree)
時間2021-12-16 01:07:54
作者magicant

Log Message

Reject unclosed quotes in heredoc operator

Change Summary

差異

--- yash/trunk/expand.c (revision 4179)
+++ yash/trunk/expand.c (revision 4180)
@@ -1814,7 +1814,9 @@
18141814 return buf;
18151815 }
18161816
1817-/* Removes quotes (', ", \). The result is a newly malloced string. */
1817+/* Removes quotes (', ", \).
1818+ * The result is a newly malloced string if successful.
1819+ * Returns NULL if there is an unclosed quote. */
18181820 wchar_t *unquote(const wchar_t *s)
18191821 {
18201822 bool indq = false;
@@ -1823,13 +1825,19 @@
18231825 for (;;) {
18241826 switch (*s) {
18251827 case L'\0':
1828+ if (indq) {
1829+ wb_destroy(&buf);
1830+ return NULL;
1831+ }
18261832 return wb_towcs(&buf);
18271833 case L'\'':
18281834 if (indq)
18291835 goto default_case;
18301836 add_sq(&s, &buf, false);
1831- if (*s == L'\0')
1832- return wb_towcs(&buf);
1837+ if (*s == L'\0') {
1838+ wb_destroy(&buf);
1839+ return NULL;
1840+ }
18331841 assert(*s == L'\'');
18341842 break;
18351843 case L'"':
--- yash/trunk/parser.c (revision 4179)
+++ yash/trunk/parser.c (revision 4180)
@@ -3165,6 +3165,12 @@
31653165 void read_heredoc_contents_without_expansion(parsestate_T *ps, redir_T *r)
31663166 {
31673167 wchar_t *eoc = unquote(r->rd_hereend); // end-of-contents marker
3168+ if (eoc == NULL) {
3169+ serror(ps, Ngt("the end-of-here-document indicator "
3170+ "is not properly quoted"));
3171+ return;
3172+ }
3173+
31683174 bool skiptab = (r->rd_type == RT_HERERT);
31693175 xwcsbuf_T buf;
31703176
--- yash/trunk/variable.c (revision 4179)
+++ yash/trunk/variable.c (revision 4180)
@@ -1337,7 +1337,7 @@
13371337 {
13381338 if (w != NULL && w->next == NULL && w->wu_type == WT_STRING) {
13391339 wchar_t *cmdname = unquote(w->wu_string);
1340- if (wcschr(cmdname, L'/') == NULL) {
1340+ if (cmdname != NULL && wcschr(cmdname, L'/') == NULL) {
13411341 char *mbsname = malloc_wcstombs(cmdname);
13421342 get_command_path(mbsname, false);
13431343 free(mbsname);
Show on old repository browser