aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2009-04-05 22:17:04 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2009-04-05 22:17:04 +0000
commit913a201bf098a5fbe1da02cb332d7d0787974c4d (patch)
treea46c0aa74f4fbc2a8b22d07bd7bce48b467418e5 /shell
parent258275d85f8e58cba040fec1aad1131017c4a69d (diff)
downloadbusybox-913a201bf098a5fbe1da02cb332d7d0787974c4d.tar.gz
hush: strip NULs from file input, they are PITA/impossible to handle correctly
function old new delta file_peek 89 93 +4 file_get 260 264 +4
Diffstat (limited to 'shell')
-rw-r--r--shell/hush.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/shell/hush.c b/shell/hush.c
index dbb38719a..fa85ad533 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -1225,6 +1225,7 @@ static int file_get(struct in_str *i)
ch = *i->p++;
if (i->eof_flag && !*i->p)
ch = EOF;
+ /* note: ch is never NUL */
} else {
/* need to double check i->file because we might be doing something
* more complicated by now, like sourcing or substituting. */
@@ -1238,9 +1239,9 @@ static int file_get(struct in_str *i)
goto take_cached;
}
#endif
- ch = fgetc(i->file);
+ do ch = fgetc(i->file); while (ch == '\0');
}
- debug_printf("file_get: got a '%c' %d\n", ch, ch);
+ debug_printf("file_get: got '%c' %d\n", ch, ch);
#if ENABLE_HUSH_INTERACTIVE
if (ch == '\n')
i->promptme = 1;
@@ -1248,8 +1249,8 @@ static int file_get(struct in_str *i)
return ch;
}
-/* All the callers guarantee this routine will never be
- * used right after a newline, so prompting is not needed.
+/* All callers guarantee this routine will never
+ * be used right after a newline, so prompting is not needed.
*/
static int file_peek(struct in_str *i)
{
@@ -1258,13 +1259,14 @@ static int file_peek(struct in_str *i)
if (i->eof_flag && !i->p[1])
return EOF;
return *i->p;
+ /* note: ch is never NUL */
}
- ch = fgetc(i->file);
+ do ch = fgetc(i->file); while (ch == '\0');
i->eof_flag = (ch == EOF);
i->peek_buf[0] = ch;
i->peek_buf[1] = '\0';
i->p = i->peek_buf;
- debug_printf("file_peek: got a '%c' %d\n", *i->p, *i->p);
+ debug_printf("file_peek: got '%c' %d\n", ch, ch);
return ch;
}