confile: convert to strnprintf()

parent b4d3e2f4
...@@ -2386,8 +2386,8 @@ static int do_includedir(const char *dirp, struct lxc_conf *lxc_conf) ...@@ -2386,8 +2386,8 @@ static int do_includedir(const char *dirp, struct lxc_conf *lxc_conf)
if (len < 6 || strncmp(fnam + len - 5, ".conf", 5) != 0) if (len < 6 || strncmp(fnam + len - 5, ".conf", 5) != 0)
continue; continue;
len = snprintf(path, PATH_MAX, "%s/%s", dirp, fnam); len = strnprintf(path, sizeof(path), "%s/%s", dirp, fnam);
if (len < 0 || len >= PATH_MAX) if (len < 0)
return ret_errno(EIO); return ret_errno(EIO);
ret = lxc_config_read(path, lxc_conf, true); ret = lxc_config_read(path, lxc_conf, true);
...@@ -2895,10 +2895,10 @@ bool do_append_unexp_config_line(struct lxc_conf *conf, const char *key, ...@@ -2895,10 +2895,10 @@ bool do_append_unexp_config_line(struct lxc_conf *conf, const char *key,
tmp = must_realloc(NULL, len); tmp = must_realloc(NULL, len);
if (lxc_config_value_empty(v)) if (lxc_config_value_empty(v))
ret = snprintf(tmp, len, "%s =", key); ret = strnprintf(tmp, len, "%s =", key);
else else
ret = snprintf(tmp, len, "%s = %s", key, v); ret = strnprintf(tmp, len, "%s = %s", key, v);
if (ret < 0 || ret >= len) if (ret < 0)
return false; return false;
/* Save the line verbatim into unexpanded_conf */ /* Save the line verbatim into unexpanded_conf */
...@@ -2963,16 +2963,14 @@ bool clone_update_unexp_ovl_paths(struct lxc_conf *conf, const char *oldpath, ...@@ -2963,16 +2963,14 @@ bool clone_update_unexp_ovl_paths(struct lxc_conf *conf, const char *oldpath,
olddirlen = strlen(ovldir) + strlen(oldpath) + strlen(oldname) + 2; olddirlen = strlen(ovldir) + strlen(oldpath) + strlen(oldname) + 2;
olddir = must_realloc(NULL, olddirlen + 1); olddir = must_realloc(NULL, olddirlen + 1);
ret = snprintf(olddir, olddirlen + 1, "%s=%s/%s", ovldir, oldpath, ret = strnprintf(olddir, olddirlen + 1, "%s=%s/%s", ovldir, oldpath, oldname);
oldname); if (ret < 0)
if (ret < 0 || ret >= olddirlen + 1)
return false; return false;
newdirlen = strlen(ovldir) + strlen(newpath) + strlen(newname) + 2; newdirlen = strlen(ovldir) + strlen(newpath) + strlen(newname) + 2;
newdir = must_realloc(NULL, newdirlen + 1); newdir = must_realloc(NULL, newdirlen + 1);
ret = snprintf(newdir, newdirlen + 1, "%s=%s/%s", ovldir, newpath, ret = strnprintf(newdir, newdirlen + 1, "%s=%s/%s", ovldir, newpath, newname);
newname); if (ret < 0)
if (ret < 0 || ret >= newdirlen + 1)
return false; return false;
if (!conf->unexpanded_config) if (!conf->unexpanded_config)
...@@ -3072,14 +3070,14 @@ bool clone_update_unexp_hooks(struct lxc_conf *conf, const char *oldpath, ...@@ -3072,14 +3070,14 @@ bool clone_update_unexp_hooks(struct lxc_conf *conf, const char *oldpath,
olddirlen = strlen(oldpath) + strlen(oldname) + 1; olddirlen = strlen(oldpath) + strlen(oldname) + 1;
olddir = must_realloc(NULL, olddirlen + 1); olddir = must_realloc(NULL, olddirlen + 1);
ret = snprintf(olddir, olddirlen + 1, "%s/%s", oldpath, oldname); ret = strnprintf(olddir, olddirlen + 1, "%s/%s", oldpath, oldname);
if (ret < 0 || ret >= olddirlen + 1) if (ret < 0)
return false; return false;
newdirlen = strlen(newpath) + strlen(newname) + 1; newdirlen = strlen(newpath) + strlen(newname) + 1;
newdir = must_realloc(NULL, newdirlen + 1); newdir = must_realloc(NULL, newdirlen + 1);
ret = snprintf(newdir, newdirlen + 1, "%s/%s", newpath, newname); ret = strnprintf(newdir, newdirlen + 1, "%s/%s", newpath, newname);
if (ret < 0 || ret >= newdirlen + 1) if (ret < 0)
return false; return false;
if (!conf->unexpanded_config) if (!conf->unexpanded_config)
...@@ -3543,10 +3541,10 @@ static int get_config_idmaps(const char *key, char *retv, int inlen, ...@@ -3543,10 +3541,10 @@ static int get_config_idmaps(const char *key, char *retv, int inlen,
listlen = lxc_list_len(&c->id_map); listlen = lxc_list_len(&c->id_map);
lxc_list_for_each(it, &c->id_map) { lxc_list_for_each(it, &c->id_map) {
struct id_map *map = it->elem; struct id_map *map = it->elem;
ret = snprintf(buf, __LXC_IDMAP_STR_BUF, "%c %lu %lu %lu", ret = strnprintf(buf, sizeof(buf), "%c %lu %lu %lu",
(map->idtype == ID_TYPE_UID) ? 'u' : 'g', (map->idtype == ID_TYPE_UID) ? 'u' : 'g',
map->nsid, map->hostid, map->range); map->nsid, map->hostid, map->range);
if (ret < 0 || ret >= __LXC_IDMAP_STR_BUF) if (ret < 0)
return ret_errno(EIO); return ret_errno(EIO);
strprint(retv, inlen, "%s%s", buf, (listlen-- > 1) ? "\n" : ""); strprint(retv, inlen, "%s%s", buf, (listlen-- > 1) ? "\n" : "");
......
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