From d17ceb3c53844a8393b4c429e85ba80fb2743ea7 Mon Sep 17 00:00:00 2001 From: kakadu Date: Mon, 10 Oct 2022 18:31:27 +0300 Subject: [PATCH 1/3] Runtime: Initializate concatenation buffer by zeros There was a bug about stringcat-ing of empty list, where it would be filled by garbage. It seems to happen becase stringBuf.contents are used without proper check of length of the buffer. We defend from that my initializing buffer by zeros (end of string) Signed-off-by: kakadu --- runtime/runtime.c | 1 + 1 file changed, 1 insertion(+) diff --git a/runtime/runtime.c b/runtime/runtime.c index a2f15d05f..6710bd94a 100644 --- a/runtime/runtime.c +++ b/runtime/runtime.c @@ -402,6 +402,7 @@ static StringBuf stringBuf; static void createStringBuf () { stringBuf.contents = (char*) malloc (STRINGBUF_INIT); + memset(stringBuf.contents, 0, STRINGBUF_INIT); stringBuf.ptr = 0; stringBuf.len = STRINGBUF_INIT; } From e18b46787ffc96d7ed157314fff73d30e9492f83 Mon Sep 17 00:00:00 2001 From: Kakadu Date: Tue, 11 Oct 2022 15:47:04 +0300 Subject: [PATCH 2/3] .gitignore files Signed-off-by: Kakadu --- regression/.gitignore | 6 +++++- stdlib/.gitignore | 3 +-- stdlib/regression/.gitignore | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) mode change 120000 => 100644 regression/.gitignore create mode 100644 stdlib/regression/.gitignore diff --git a/regression/.gitignore b/regression/.gitignore deleted file mode 120000 index 65f1cfa74..000000000 --- a/regression/.gitignore +++ /dev/null @@ -1 +0,0 @@ -../stdlib/.gitignore \ No newline at end of file diff --git a/regression/.gitignore b/regression/.gitignore new file mode 100644 index 000000000..bf30d1b26 --- /dev/null +++ b/regression/.gitignore @@ -0,0 +1,5 @@ +*.html +*.sm +/*.log +*.i +*.s diff --git a/stdlib/.gitignore b/stdlib/.gitignore index 0ec54007e..bf30d1b26 100644 --- a/stdlib/.gitignore +++ b/stdlib/.gitignore @@ -1,6 +1,5 @@ *.html *.sm -*.log +/*.log *.i *.s - diff --git a/stdlib/regression/.gitignore b/stdlib/regression/.gitignore new file mode 100644 index 000000000..50e13221d --- /dev/null +++ b/stdlib/regression/.gitignore @@ -0,0 +1 @@ +/*.log From f94702445365cf6ecfdcc9b72fd3c5228f489fe2 Mon Sep 17 00:00:00 2001 From: Kakadu Date: Tue, 11 Oct 2022 15:47:26 +0300 Subject: [PATCH 3/3] A test about bad initialization of stringBuf in runtime Signed-off-by: Kakadu --- stdlib/regression/orig/test33.log | 2 ++ stdlib/regression/test33.lama | 5 +++++ 2 files changed, 7 insertions(+) create mode 100644 stdlib/regression/orig/test33.log create mode 100644 stdlib/regression/test33.lama diff --git a/stdlib/regression/orig/test33.log b/stdlib/regression/orig/test33.log new file mode 100644 index 000000000..35beaeee9 --- /dev/null +++ b/stdlib/regression/orig/test33.log @@ -0,0 +1,2 @@ +{}.string: 0 +{}.stringcat: diff --git a/stdlib/regression/test33.lama b/stdlib/regression/test33.lama new file mode 100644 index 000000000..8bce46926 --- /dev/null +++ b/stdlib/regression/test33.lama @@ -0,0 +1,5 @@ +import List; +import Array; + +printf ("{}.string: %s\n", {}.string); +printf ("{}.stringcat: %s\n", {}.stringcat)