提交 7f0b3825 编写于 作者: M Michal Privoznik

qemuDomainAttachDeviceMknod: Don't loop endlessly

When working with symlinks it is fairly easy to get into a loop.
Don't.
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
上级 3f5fcacf
......@@ -7735,16 +7735,24 @@ qemuDomainAttachDeviceMknodHelper(pid_t pid ATTRIBUTE_UNUSED,
static int
qemuDomainAttachDeviceMknod(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainDeviceDefPtr devDef,
const char *file)
qemuDomainAttachDeviceMknodRecursive(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainDeviceDefPtr devDef,
const char *file,
unsigned int ttl)
{
struct qemuDomainAttachDeviceMknodData data;
int ret = -1;
char *target = NULL;
bool isLink;
if (!ttl) {
virReportSystemError(ELOOP,
_("Too many levels of symbolic links: %s"),
file);
return ret;
}
memset(&data, 0, sizeof(data));
data.driver = driver;
......@@ -7822,7 +7830,8 @@ qemuDomainAttachDeviceMknod(virQEMUDriverPtr driver,
}
if (isLink &&
qemuDomainAttachDeviceMknod(driver, vm, devDef, target) < 0)
qemuDomainAttachDeviceMknodRecursive(driver, vm, devDef,
target, ttl -1) < 0)
goto cleanup;
ret = 0;
......@@ -7836,6 +7845,19 @@ qemuDomainAttachDeviceMknod(virQEMUDriverPtr driver,
}
static int
qemuDomainAttachDeviceMknod(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainDeviceDefPtr devDef,
const char *file)
{
long symloop_max = sysconf(_SC_SYMLOOP_MAX);
return qemuDomainAttachDeviceMknodRecursive(driver, vm, devDef,
file, symloop_max);
}
static int
qemuDomainDetachDeviceUnlinkHelper(pid_t pid ATTRIBUTE_UNUSED,
void *opaque)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册