DEADSOFTWARE

Fix memory corruption when load library
authorDeaDDooMER <deaddoomer@deadsoftware.ru>
Fri, 3 Mar 2017 23:15:06 +0000 (02:15 +0300)
committerDeaDDooMER <deaddoomer@deadsoftware.ru>
Fri, 3 Mar 2017 23:15:06 +0000 (02:15 +0300)
mpc/.gitignore [new file with mode: 0644]
mpc/Makefile
mpc/structures/block.c

diff --git a/mpc/.gitignore b/mpc/.gitignore
new file mode 100644 (file)
index 0000000..9854580
--- /dev/null
@@ -0,0 +1 @@
+mp3CC
index 61e8c9d63918a1fba92ef7b2c46f11da35e44359..e12def34f2d70f81765462a11181323123990e66 100644 (file)
@@ -1,5 +1,5 @@
 CC = gcc
-CFLAGS = -DLINUX -DUNIX -DNDEBUG -D_CONSOLE
+CFLAGS = -g -DLINUX -DUNIX -DNDEBUG -D_CONSOLE
 LDFLAGS = -lm
 OUTPUT = mp3CC
 SOURCES = */*.c
index cb7b9d4bdf085b1e561905672b59464d49f72aef..1b55eeae2479366bf16c2474d8e1981b4ad7c303 100644 (file)
@@ -792,9 +792,10 @@ void read_library_file(FILE* library_file, unit* library_unit)
                        method->container_unit = library_unit;
                        method_name = string_create();
                        method_name->length = constant_pool[method_name_index].data_len;
-                       method_name->cstr = malloc(method_name->length + 1);
-                       strcpy(method_name->cstr, constant_pool[method_name_index].data);
-                       method_name->cstr[method_name->length] = '\0';
+                       // Strings in class has no null char
+                       method_name->cstr = malloc(method_name->length + 2);
+                       strncpy(method_name->cstr, constant_pool[method_name_index].data, method_name->length);
+                       method_name->cstr[method_name->length + 1] = '\0';
                        name_table_insert(library_unit->names, method_name, method);
                }