Skip to content

Commit

Permalink
fix parser for ";", support line buffer overflow protect
Browse files Browse the repository at this point in the history
  • Loading branch information
pikasTech committed Oct 14, 2024
1 parent 4f4b26c commit 541b9a9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 41 deletions.
37 changes: 3 additions & 34 deletions port/linux/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,9 @@
"program": "${workspaceFolder}/build/test/pikascript_test",
// "program": "${workspaceFolder}/build/boot/demo06-pikamain/pikascript_demo06-pikamain",
"args": [
// "--gtest_filter=vm.keyword_2"
// "--gtest_filter=compiler.find_break_point"
// "--gtest_filter=pikaMain.REPL_pdb_set_break"
// "--gtest_filter=vm.subsrc_import",
// "--gtest_filter=vm.run_file_subsrc"
// "--gtest_filter=vm.run_file"
// "--gtest_filter=stddata.encode_decode"
// "--gtest_filter=packtool.packfiles_txt"
// "--gtest_filter=cmodule.class_attr_obj"
// "--gtest_filter=except.try_import_except"
// "--gtest_filter=vm.test_cmodule_import_as"
// "--gtest_filter=vm.subsrc_import"
// "--gtest_filter=event.event_thread3"
// "--gtest_filter=parser.semicolon*"
// "--gtest_filter=time*"
// "--gtest_filter=flashdb.tsdb1"
// "--gtest_filter=flashdb.base"
// "--gtest_filter=jrpc.server"
// "--gtest_filter=jrpc.client"
// "--gtest_filter=jrpc.BlockingRequestBetweenTwoJRPC"
// "--gtest_filter=jrpc.cmd"
// "--gtest_filter=jrpc.exec_get_val"
// "--gtest_filter=jrpc.exec_get_val"
// "--gtest_filter=thread.issue1"
// "--gtest_filter=except.isinstance"
// "--gtest_filter=builtin.isinstance"
// "--gtest_filter=bytes.bytes_split"
// "--gtest_filter=except.dict"
// "--gtest_filter=except.*"
// "--gtest_filter=except.try1"
// "--gtest_filter=except.for_loop"
// "--gtest_filter=builtin.init_raise"
// "--gtest_filter=builtin.strformat"
// "--gtest_filter=except.typeerr"
// "--gtest_filter=module.REPL_big_script"
// "--gtest_filter=parser.input_issue1"
"--gtest_filter=except.raise_type"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
Expand Down
8 changes: 4 additions & 4 deletions port/linux/test/module-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,9 @@ char f_getchar(void) {
if (n > 0) {
return c;
}
pika_platform_printf("f_getchar error\r\n");
pika_assert(0);
return -1;
// pika_platform_printf("f_getchar error\r\n");
// pika_assert(0);
return EOF;
}
void pikaScriptShell_withGetchar(PikaObj* self, sh_getchar getchar_fn);
}
Expand Down Expand Up @@ -603,7 +603,7 @@ TEST(module, REPL_big_script) {
fclose((FILE*)f_getchar_fp);
/* collect */
/* assert */
EXPECT_STREQ(log_buff[0],
EXPECT_STREQ(log_buff[3],
"\r\nError: line buff overflow, please use bigger "
"'PIKA_LINE_BUFF_SIZE'\r\n");
/* deinit */
Expand Down
21 changes: 20 additions & 1 deletion src/PikaObj.c
Original file line number Diff line number Diff line change
Expand Up @@ -1668,6 +1668,14 @@ enum shellCTRL _inner_do_obj_runChar(PikaObj* self,
ShellConfig* shell) {
char* input_line = NULL;
enum shellCTRL ctrl = SHELL_CTRL_CONTINUE;
static uint64_t tick_start_block_input = 0;
if (tick_start_block_input != 0) {
if (pika_platform_get_tick() - tick_start_block_input < 5000) {
return SHELL_CTRL_CONTINUE;
} else {
tick_start_block_input = 0;
}
}
if (inputChar == 0x7F) {
inputChar = '\b';
}
Expand Down Expand Up @@ -1762,7 +1770,12 @@ enum shellCTRL _inner_do_obj_runChar(PikaObj* self,
pika_platform_printf(
"\r\nError: line buff overflow, please use bigger "
"'PIKA_LINE_BUFF_SIZE'\r\n");
ctrl = SHELL_CTRL_EXIT;
ctrl = SHELL_CTRL_CONTINUE;
pika_platform_printf(
"Input is blocked for 5 seconds to protect the "
"kernel...\r\n");
tick_start_block_input = pika_platform_get_tick();
pika_platform_printf(">>> ");
__clearBuff(shell);
goto __exit;
}
Expand Down Expand Up @@ -1981,6 +1994,12 @@ void _do_pikaScriptShell(PikaObj* self, ShellConfig* cfg) {
while (1) {
inputChar[1] = inputChar[0];
inputChar[0] = _await_getchar(cfg->fn_getchar);
#ifdef __linux
if (inputChar[0] == EOF) {
pika_platform_printf("\r\n");
return;
}
#endif
#if !PIKA_NANO_ENABLE
/* run python script */
if (inputChar[0] == '!' && inputChar[1] == '#') {
Expand Down
4 changes: 3 additions & 1 deletion src/PikaParser.c
Original file line number Diff line number Diff line change
Expand Up @@ -2720,7 +2720,9 @@ static char* Suger_semicolon(Args* outbuffs, char* sLine) {
sStmtItem = strsAppend(&buffs, sStmtItem, "\n");
sStmtAfter = strsAppend(&buffs, sStmtAfter, sStmtItem);
}
sStmtAfter[strGetSize(sStmtAfter) - 1] = '\0';
if (sStmtAfter[0] != '\0') {
sStmtAfter[strGetSize(sStmtAfter) - 1] = '\0';
}
sStmtAfter = strsCopy(outbuffs, sStmtAfter);
strsDeinit(&buffs);
return sStmtAfter;
Expand Down
2 changes: 1 addition & 1 deletion src/PikaVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
#define PIKA_VERSION_MINOR 13
#define PIKA_VERSION_MICRO 4

#define PIKA_EDIT_TIME "2024/10/13 23:56:45"
#define PIKA_EDIT_TIME "2024/10/14 11:09:44"

0 comments on commit 541b9a9

Please sign in to comment.