mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-16 23:42:10 +00:00
lxc-usernsexec: fix default map functionality
* Place NULL bytes at the end of strings so that lxc_safe_ulong() can parse them correctly * Only free the newly created id_map on error, to avoid passing garbage to lxc_map_ids() Signed-off-by: Cameron Nemo <camerontnorman@gmail.com>
This commit is contained in:
parent
b8f44de376
commit
c14ea11dcc
@ -200,6 +200,7 @@ static int read_default_map(char *fnam, int which, char *user)
|
|||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
char *p1, *p2;
|
char *p1, *p2;
|
||||||
|
unsigned long ul1, ul2;
|
||||||
FILE *fin;
|
FILE *fin;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
size_t sz = 0;
|
size_t sz = 0;
|
||||||
@ -224,37 +225,42 @@ static int read_default_map(char *fnam, int which, char *user)
|
|||||||
if (!p2)
|
if (!p2)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
line[strlen(line) - 1] = '\0';
|
||||||
|
*p2 = '\0';
|
||||||
|
|
||||||
|
ret = lxc_safe_ulong(p1 + 1, &ul1);
|
||||||
|
if (ret < 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
ret = lxc_safe_ulong(p2 + 1, &ul2);
|
||||||
|
if (ret < 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
ret = -1;
|
||||||
newmap = malloc(sizeof(*newmap));
|
newmap = malloc(sizeof(*newmap));
|
||||||
if (!newmap)
|
if (!newmap)
|
||||||
goto on_error;
|
break;
|
||||||
|
|
||||||
ret = lxc_safe_ulong(p1 + 1, &newmap->hostid);
|
|
||||||
if (ret < 0)
|
|
||||||
goto on_error;
|
|
||||||
|
|
||||||
ret = lxc_safe_ulong(p2 + 1, &newmap->range);
|
|
||||||
if (ret < 0)
|
|
||||||
goto on_error;
|
|
||||||
|
|
||||||
newmap->nsid = 0;
|
newmap->nsid = 0;
|
||||||
newmap->idtype = which;
|
newmap->idtype = which;
|
||||||
|
newmap->hostid = ul1;
|
||||||
|
newmap->range = ul2;
|
||||||
|
|
||||||
ret = -1;
|
|
||||||
tmp = malloc(sizeof(*tmp));
|
tmp = malloc(sizeof(*tmp));
|
||||||
if (!tmp)
|
if (!tmp) {
|
||||||
goto on_error;
|
free(newmap);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
tmp->elem = newmap;
|
tmp->elem = newmap;
|
||||||
lxc_list_add_tail(&active_map, tmp);
|
lxc_list_add_tail(&active_map, tmp);
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
on_error:
|
|
||||||
fclose(fin);
|
fclose(fin);
|
||||||
free(line);
|
free(line);
|
||||||
free(newmap);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user