Commit a2eea3c1 by Dwight Engen Committed by Serge Hallyn

coverity: ensure string is null terminated, return in

error case Signed-off-by: 's avatarDwight Engen <dwight.engen@oracle.com> Signed-off-by: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com>
parent 2d4bcb96
...@@ -1160,10 +1160,11 @@ static int update_name_and_paths(const char *path, struct lxc_container *oldc, ...@@ -1160,10 +1160,11 @@ static int update_name_and_paths(const char *path, struct lxc_container *oldc,
SYSERROR("rewinding old config"); SYSERROR("rewinding old config");
return -1; return -1;
} }
contents = malloc(flen); contents = malloc(flen+1);
if (!contents) { if (!contents) {
SYSERROR("out of memory"); SYSERROR("out of memory");
fclose(f); fclose(f);
return -1;
} }
if (fread(contents, 1, flen, f) != flen) { if (fread(contents, 1, flen, f) != flen) {
free(contents); free(contents);
...@@ -1171,6 +1172,7 @@ static int update_name_and_paths(const char *path, struct lxc_container *oldc, ...@@ -1171,6 +1172,7 @@ static int update_name_and_paths(const char *path, struct lxc_container *oldc,
SYSERROR("reading old config"); SYSERROR("reading old config");
return -1; return -1;
} }
contents[flen] = '\0';
if (fclose(f) < 0) { if (fclose(f) < 0) {
free(contents); free(contents);
SYSERROR("closing old config"); SYSERROR("closing old config");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment