coverity: ensure string is null terminated, return in

error case

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
This commit is contained in:
Dwight Engen 2013-05-03 11:29:39 -04:00 committed by Serge Hallyn
parent 2d4bcb9615
commit a2eea3c197

View File

@ -1160,10 +1160,11 @@ static int update_name_and_paths(const char *path, struct lxc_container *oldc,
SYSERROR("rewinding old config");
return -1;
}
contents = malloc(flen);
contents = malloc(flen+1);
if (!contents) {
SYSERROR("out of memory");
fclose(f);
return -1;
}
if (fread(contents, 1, flen, f) != flen) {
free(contents);
@ -1171,6 +1172,7 @@ static int update_name_and_paths(const char *path, struct lxc_container *oldc,
SYSERROR("reading old config");
return -1;
}
contents[flen] = '\0';
if (fclose(f) < 0) {
free(contents);
SYSERROR("closing old config");