1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-01-27 18:03:50 +03:00

Blank out invalid interface names with escaped letters etc.

Check that interface names only contain valid characters. Blank them out
otherwise.
Valid characters in this code are currently a-z,A-Z,0-9, '-' and '_'.
This commit is contained in:
Stefan Berger 2010-03-31 10:22:10 -04:00
parent ffbfd2c813
commit 2f646237da
2 changed files with 11 additions and 1 deletions

View File

@ -1776,6 +1776,11 @@ cleanup:
}
static bool
isValidIfname(const char *ifname) {
return (strspn(ifname, VALID_IFNAME_CHARS) == strlen(ifname));
}
/* Parse the XML definition for a network interface
* @param node XML nodeset to parse for net definition
@ -1859,8 +1864,10 @@ virDomainNetDefParseXML(virCapsPtr caps,
xmlStrEqual(cur->name, BAD_CAST "target")) {
ifname = virXMLPropString(cur, "dev");
if ((ifname != NULL) &&
(STRPREFIX((const char*)ifname, "vnet"))) {
((STRPREFIX((const char*)ifname, "vnet")) ||
(!isValidIfname(ifname)))) {
/* An auto-generated target name, blank it out */
/* blank out invalid interface names */
VIR_FREE(ifname);
}
} else if ((script == NULL) &&

View File

@ -297,6 +297,9 @@ struct _virDomainNetDef {
virNWFilterHashTablePtr filterparams;
};
# define VALID_IFNAME_CHARS \
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"
enum virDomainChrTargetType {
VIR_DOMAIN_CHR_TARGET_TYPE_NULL = 0,
VIR_DOMAIN_CHR_TARGET_TYPE_MONITOR,