diff --git a/src/pack.c b/src/pack.c index 5c51e11..4899bd8 100644 --- a/src/pack.c +++ b/src/pack.c @@ -252,9 +252,9 @@ void* pack_readfile(const char* packfile, const char* filename, uint32_t* filesi } DEBUG("Opened file '%s' from '%s'", filename, packfile); - // Read the entire thing. + // Read the entire file. size = file->end - file->start; - buf = malloc(size); + buf = malloc(size+1); if((bytes = pack_read(file, buf, size)) != size) { ERR("Reading '%s' from packfile '%s'. Expected %d bytes got %d bytes", filename, packfile, size, bytes); free(buf); @@ -262,6 +262,7 @@ void* pack_readfile(const char* packfile, const char* filename, uint32_t* filesi return NULL; } DEBUG("Read %d bytes from '%s'", bytes, filename); + memset(buf+size, '\0', 1); // Append size '\0' for it to validate as a string. // Check the md5. md5_state_t md5;