Skip to content

Commit 541b9a9

Browse files
committed
fix parser for ";", support line buffer overflow protect
1 parent 4f4b26c commit 541b9a9

File tree

5 files changed

+31
-41
lines changed

5 files changed

+31
-41
lines changed

port/linux/.vscode/launch.json

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,9 @@
1111
"program": "${workspaceFolder}/build/test/pikascript_test",
1212
// "program": "${workspaceFolder}/build/boot/demo06-pikamain/pikascript_demo06-pikamain",
1313
"args": [
14-
// "--gtest_filter=vm.keyword_2"
15-
// "--gtest_filter=compiler.find_break_point"
16-
// "--gtest_filter=pikaMain.REPL_pdb_set_break"
17-
// "--gtest_filter=vm.subsrc_import",
18-
// "--gtest_filter=vm.run_file_subsrc"
19-
// "--gtest_filter=vm.run_file"
20-
// "--gtest_filter=stddata.encode_decode"
21-
// "--gtest_filter=packtool.packfiles_txt"
22-
// "--gtest_filter=cmodule.class_attr_obj"
23-
// "--gtest_filter=except.try_import_except"
24-
// "--gtest_filter=vm.test_cmodule_import_as"
25-
// "--gtest_filter=vm.subsrc_import"
26-
// "--gtest_filter=event.event_thread3"
27-
// "--gtest_filter=parser.semicolon*"
28-
// "--gtest_filter=time*"
29-
// "--gtest_filter=flashdb.tsdb1"
30-
// "--gtest_filter=flashdb.base"
31-
// "--gtest_filter=jrpc.server"
32-
// "--gtest_filter=jrpc.client"
33-
// "--gtest_filter=jrpc.BlockingRequestBetweenTwoJRPC"
34-
// "--gtest_filter=jrpc.cmd"
35-
// "--gtest_filter=jrpc.exec_get_val"
36-
// "--gtest_filter=jrpc.exec_get_val"
37-
// "--gtest_filter=thread.issue1"
38-
// "--gtest_filter=except.isinstance"
39-
// "--gtest_filter=builtin.isinstance"
40-
// "--gtest_filter=bytes.bytes_split"
41-
// "--gtest_filter=except.dict"
42-
// "--gtest_filter=except.*"
43-
// "--gtest_filter=except.try1"
44-
// "--gtest_filter=except.for_loop"
45-
// "--gtest_filter=builtin.init_raise"
46-
// "--gtest_filter=builtin.strformat"
47-
// "--gtest_filter=except.typeerr"
14+
// "--gtest_filter=module.REPL_big_script"
15+
// "--gtest_filter=parser.input_issue1"
16+
"--gtest_filter=except.raise_type"
4817
],
4918
"stopAtEntry": false,
5019
"cwd": "${workspaceFolder}",

port/linux/test/module-test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,9 @@ char f_getchar(void) {
504504
if (n > 0) {
505505
return c;
506506
}
507-
pika_platform_printf("f_getchar error\r\n");
508-
pika_assert(0);
509-
return -1;
507+
// pika_platform_printf("f_getchar error\r\n");
508+
// pika_assert(0);
509+
return EOF;
510510
}
511511
void pikaScriptShell_withGetchar(PikaObj* self, sh_getchar getchar_fn);
512512
}
@@ -603,7 +603,7 @@ TEST(module, REPL_big_script) {
603603
fclose((FILE*)f_getchar_fp);
604604
/* collect */
605605
/* assert */
606-
EXPECT_STREQ(log_buff[0],
606+
EXPECT_STREQ(log_buff[3],
607607
"\r\nError: line buff overflow, please use bigger "
608608
"'PIKA_LINE_BUFF_SIZE'\r\n");
609609
/* deinit */

src/PikaObj.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1668,6 +1668,14 @@ enum shellCTRL _inner_do_obj_runChar(PikaObj* self,
16681668
ShellConfig* shell) {
16691669
char* input_line = NULL;
16701670
enum shellCTRL ctrl = SHELL_CTRL_CONTINUE;
1671+
static uint64_t tick_start_block_input = 0;
1672+
if (tick_start_block_input != 0) {
1673+
if (pika_platform_get_tick() - tick_start_block_input < 5000) {
1674+
return SHELL_CTRL_CONTINUE;
1675+
} else {
1676+
tick_start_block_input = 0;
1677+
}
1678+
}
16711679
if (inputChar == 0x7F) {
16721680
inputChar = '\b';
16731681
}
@@ -1762,7 +1770,12 @@ enum shellCTRL _inner_do_obj_runChar(PikaObj* self,
17621770
pika_platform_printf(
17631771
"\r\nError: line buff overflow, please use bigger "
17641772
"'PIKA_LINE_BUFF_SIZE'\r\n");
1765-
ctrl = SHELL_CTRL_EXIT;
1773+
ctrl = SHELL_CTRL_CONTINUE;
1774+
pika_platform_printf(
1775+
"Input is blocked for 5 seconds to protect the "
1776+
"kernel...\r\n");
1777+
tick_start_block_input = pika_platform_get_tick();
1778+
pika_platform_printf(">>> ");
17661779
__clearBuff(shell);
17671780
goto __exit;
17681781
}
@@ -1981,6 +1994,12 @@ void _do_pikaScriptShell(PikaObj* self, ShellConfig* cfg) {
19811994
while (1) {
19821995
inputChar[1] = inputChar[0];
19831996
inputChar[0] = _await_getchar(cfg->fn_getchar);
1997+
#ifdef __linux
1998+
if (inputChar[0] == EOF) {
1999+
pika_platform_printf("\r\n");
2000+
return;
2001+
}
2002+
#endif
19842003
#if !PIKA_NANO_ENABLE
19852004
/* run python script */
19862005
if (inputChar[0] == '!' && inputChar[1] == '#') {

src/PikaParser.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2720,7 +2720,9 @@ static char* Suger_semicolon(Args* outbuffs, char* sLine) {
27202720
sStmtItem = strsAppend(&buffs, sStmtItem, "\n");
27212721
sStmtAfter = strsAppend(&buffs, sStmtAfter, sStmtItem);
27222722
}
2723-
sStmtAfter[strGetSize(sStmtAfter) - 1] = '\0';
2723+
if (sStmtAfter[0] != '\0') {
2724+
sStmtAfter[strGetSize(sStmtAfter) - 1] = '\0';
2725+
}
27242726
sStmtAfter = strsCopy(outbuffs, sStmtAfter);
27252727
strsDeinit(&buffs);
27262728
return sStmtAfter;

src/PikaVersion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
#define PIKA_VERSION_MINOR 13
33
#define PIKA_VERSION_MICRO 4
44

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy