aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-07-15 08:37:36 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2011-07-15 08:37:36 +0200
commitf2f9bc59327256baf2cf66bf634560c163c22852 (patch)
tree0ceb1ab1a8c58c1edbe132d834914f764c242d62
parent43a668b2eef5f77d1fe0bee1289cea6649fa793d (diff)
downloadbusybox-w32-f2f9bc59327256baf2cf66bf634560c163c22852.tar.gz
busybox-w32-f2f9bc59327256baf2cf66bf634560c163c22852.tar.bz2
busybox-w32-f2f9bc59327256baf2cf66bf634560c163c22852.zip
dc: fix a case where we can run off malloced space
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/dc.c25
1 files changed, 7 insertions, 18 deletions
diff --git a/miscutils/dc.c b/miscutils/dc.c
index b080ba133..6903761e4 100644
--- a/miscutils/dc.c
+++ b/miscutils/dc.c
@@ -15,7 +15,7 @@
15//usage: "p - print top of the stack (without popping),\n" 15//usage: "p - print top of the stack (without popping),\n"
16//usage: "f - print entire stack,\n" 16//usage: "f - print entire stack,\n"
17//usage: "o - pop the value and set output radix (must be 10, 16, 8 or 2).\n" 17//usage: "o - pop the value and set output radix (must be 10, 16, 8 or 2).\n"
18//usage: "Examples: 'dc 2 2 add' -> 4, 'dc 8 8 * 2 2 + /' -> 16" 18//usage: "Examples: 'dc 2 2 add p' -> 4, 'dc 8 8 * 2 2 + / p' -> 16"
19//usage: 19//usage:
20//usage:#define dc_example_usage 20//usage:#define dc_example_usage
21//usage: "$ dc 2 2 + p\n" 21//usage: "$ dc 2 2 + p\n"
@@ -245,19 +245,6 @@ static void stack_machine(const char *argument)
245 bb_error_msg_and_die("syntax error at '%s'", argument); 245 bb_error_msg_and_die("syntax error at '%s'", argument);
246} 246}
247 247
248/* return pointer to next token in buffer and set *buffer to one char
249 * past the end of the above mentioned token
250 */
251static char *get_token(char **buffer)
252{
253 char *current = skip_whitespace(*buffer);
254 if (*current != '\0') {
255 *buffer = skip_non_whitespace(current);
256 return current;
257 }
258 return NULL;
259}
260
261int dc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 248int dc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
262int dc_main(int argc UNUSED_PARAM, char **argv) 249int dc_main(int argc UNUSED_PARAM, char **argv)
263{ 250{
@@ -272,16 +259,18 @@ int dc_main(int argc UNUSED_PARAM, char **argv)
272 while ((line = xmalloc_fgetline(stdin)) != NULL) { 259 while ((line = xmalloc_fgetline(stdin)) != NULL) {
273 cursor = line; 260 cursor = line;
274 while (1) { 261 while (1) {
275 token = get_token(&cursor); 262 token = skip_whitespace(cursor);
276 if (!token) 263 if (*token == '\0')
277 break; 264 break;
278 *cursor++ = '\0'; 265 cursor = skip_non_whitespace(token);
266 if (*cursor != '\0')
267 *cursor++ = '\0';
279 stack_machine(token); 268 stack_machine(token);
280 } 269 }
281 free(line); 270 free(line);
282 } 271 }
283 } else { 272 } else {
284 // why? it breaks "dc -2 2 * p" 273 // why? it breaks "dc -2 2 + p"
285 //if (argv[0][0] == '-') 274 //if (argv[0][0] == '-')
286 // bb_show_usage(); 275 // bb_show_usage();
287 do { 276 do {