aboutsummaryrefslogtreecommitdiff
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
parent258275d85f8e58cba040fec1aad1131017c4a69d (diff)
downloadbusybox-w32-913a201bf098a5fbe1da02cb332d7d0787974c4d.tar.gz
busybox-w32-913a201bf098a5fbe1da02cb332d7d0787974c4d.tar.bz2
busybox-w32-913a201bf098a5fbe1da02cb332d7d0787974c4d.zip
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
-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)
1225 ch = *i->p++; 1225 ch = *i->p++;
1226 if (i->eof_flag && !*i->p) 1226 if (i->eof_flag && !*i->p)
1227 ch = EOF; 1227 ch = EOF;
1228 /* note: ch is never NUL */
1228 } else { 1229 } else {
1229 /* need to double check i->file because we might be doing something 1230 /* need to double check i->file because we might be doing something
1230 * more complicated by now, like sourcing or substituting. */ 1231 * more complicated by now, like sourcing or substituting. */
@@ -1238,9 +1239,9 @@ static int file_get(struct in_str *i)
1238 goto take_cached; 1239 goto take_cached;
1239 } 1240 }
1240#endif 1241#endif
1241 ch = fgetc(i->file); 1242 do ch = fgetc(i->file); while (ch == '\0');
1242 } 1243 }
1243 debug_printf("file_get: got a '%c' %d\n", ch, ch); 1244 debug_printf("file_get: got '%c' %d\n", ch, ch);
1244#if ENABLE_HUSH_INTERACTIVE 1245#if ENABLE_HUSH_INTERACTIVE
1245 if (ch == '\n') 1246 if (ch == '\n')
1246 i->promptme = 1; 1247 i->promptme = 1;
@@ -1248,8 +1249,8 @@ static int file_get(struct in_str *i)
1248 return ch; 1249 return ch;
1249} 1250}
1250 1251
1251/* All the callers guarantee this routine will never be 1252/* All callers guarantee this routine will never
1252 * used right after a newline, so prompting is not needed. 1253 * be used right after a newline, so prompting is not needed.
1253 */ 1254 */
1254static int file_peek(struct in_str *i) 1255static int file_peek(struct in_str *i)
1255{ 1256{
@@ -1258,13 +1259,14 @@ static int file_peek(struct in_str *i)
1258 if (i->eof_flag && !i->p[1]) 1259 if (i->eof_flag && !i->p[1])
1259 return EOF; 1260 return EOF;
1260 return *i->p; 1261 return *i->p;
1262 /* note: ch is never NUL */
1261 } 1263 }
1262 ch = fgetc(i->file); 1264 do ch = fgetc(i->file); while (ch == '\0');
1263 i->eof_flag = (ch == EOF); 1265 i->eof_flag = (ch == EOF);
1264 i->peek_buf[0] = ch; 1266 i->peek_buf[0] = ch;
1265 i->peek_buf[1] = '\0'; 1267 i->peek_buf[1] = '\0';
1266 i->p = i->peek_buf; 1268 i->p = i->peek_buf;
1267 debug_printf("file_peek: got a '%c' %d\n", *i->p, *i->p); 1269 debug_printf("file_peek: got '%c' %d\n", ch, ch);
1268 return ch; 1270 return ch;
1269} 1271}
1270 1272