From: DeaDDooMER Date: Fri, 3 Mar 2017 23:15:06 +0000 (+0300) Subject: Fix memory corruption when load library X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=c55b539d4632f554d76e7c5c5be0dbbca7e3ffdd;p=mp3cc.git Fix memory corruption when load library --- diff --git a/mpc/.gitignore b/mpc/.gitignore new file mode 100644 index 0000000..9854580 --- /dev/null +++ b/mpc/.gitignore @@ -0,0 +1 @@ +mp3CC diff --git a/mpc/Makefile b/mpc/Makefile index 61e8c9d..e12def3 100644 --- a/mpc/Makefile +++ b/mpc/Makefile @@ -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 diff --git a/mpc/structures/block.c b/mpc/structures/block.c index cb7b9d4..1b55eea 100644 --- a/mpc/structures/block.c +++ b/mpc/structures/block.c @@ -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); }