coverity: #1425859

check return value of snprintf() Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 558996bd
...@@ -717,10 +717,12 @@ char *lxc_deslashify(const char *path) ...@@ -717,10 +717,12 @@ char *lxc_deslashify(const char *path)
char *lxc_append_paths(const char *first, const char *second) char *lxc_append_paths(const char *first, const char *second)
{ {
size_t len = strlen(first) + strlen(second) + 1; int ret;
const char *pattern = "%s%s"; size_t len;
char *result = NULL; char *result = NULL;
const char *pattern = "%s%s";
len = strlen(first) + strlen(second) + 1;
if (second[0] != '/') { if (second[0] != '/') {
len += 1; len += 1;
pattern = "%s/%s"; pattern = "%s/%s";
...@@ -730,7 +732,12 @@ char *lxc_append_paths(const char *first, const char *second) ...@@ -730,7 +732,12 @@ char *lxc_append_paths(const char *first, const char *second)
if (!result) if (!result)
return NULL; return NULL;
snprintf(result, len, pattern, first, second); ret = snprintf(result, len, pattern, first, second);
if (ret < 0 || (size_t)ret >= len) {
free(result);
return NULL;
}
return result; return result;
} }
......
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