提交 7330a365 编写于 作者: J Ján Tomko

conf: check for buffer errors before virBufferUse

After an OOM error, virBuffer* APIs set buf->use to zero.
Adding a buffer to the parent buffer only if use is non-zero
would quietly drop data on error.

Check the error beforehand to make sure buf->use is zero
because we have not attempted to add anything to it.
上级 338c74da
......@@ -931,6 +931,9 @@ virCapabilitiesFormatCaches(virBufferPtr buf,
bank->controls[j]->max_allocation);
}
if (virBufferCheckError(&controlBuf) < 0)
return -1;
if (virBufferUse(&controlBuf)) {
virBufferAddLit(buf, ">\n");
virBufferAddBuffer(buf, &controlBuf);
......
......@@ -646,6 +646,10 @@ virCPUDefFormatBufFull(virBufferPtr buf,
if (virDomainNumaDefCPUFormat(&childrenBuf, numa) < 0)
goto cleanup;
if (virBufferCheckError(&attributeBuf) < 0 ||
virBufferCheckError(&childrenBuf) < 0)
goto cleanup;
/* Put it all together */
if (virBufferUse(&attributeBuf) || virBufferUse(&childrenBuf)) {
virBufferAddLit(buf, "<cpu");
......
......@@ -21573,6 +21573,9 @@ virDomainDiskDefFormat(virBufferPtr buf,
virDomainVirtioOptionsFormat(&driverBuf, def->virtio);
if (virBufferCheckError(&driverBuf) < 0)
return -1;
if (virBufferUse(&driverBuf)) {
virBufferAddLit(buf, "<driver");
virBufferAddBuffer(buf, &driverBuf);
......@@ -21757,7 +21760,7 @@ virDomainControllerDriverFormat(virBufferPtr buf,
virDomainVirtioOptionsFormat(&driverBuf, def->virtio);
if (virBufferUse(&driverBuf)) {
if (virBufferError(&driverBuf) != 0 || virBufferUse(&driverBuf)) {
virBufferAddLit(buf, "<driver");
virBufferAddBuffer(buf, &driverBuf);
virBufferAddLit(buf, "/>\n");
......@@ -21904,6 +21907,9 @@ virDomainControllerDefFormat(virBufferPtr buf,
"pcihole64>\n", def->opts.pciopts.pcihole64size);
}
if (virBufferCheckError(&childBuf) < 0)
return -1;
if (virBufferUse(&childBuf)) {
virBufferAddLit(buf, ">\n");
virBufferAddBuffer(buf, &childBuf);
......@@ -21975,6 +21981,9 @@ virDomainFSDefFormat(virBufferPtr buf,
virDomainVirtioOptionsFormat(&driverBuf, def->virtio);
if (virBufferCheckError(&driverBuf) < 0)
return -1;
if (virBufferUse(&driverBuf)) {
virBufferAddLit(buf, "<driver");
virBufferAddBuffer(buf, &driverBuf);
......@@ -23239,6 +23248,9 @@ virDomainMemballoonDefFormat(virBufferPtr buf,
}
}
if (virBufferCheckError(&childrenBuf) < 0)
return -1;
if (!virBufferUse(&childrenBuf)) {
virBufferAddLit(buf, "/>\n");
} else {
......@@ -23325,6 +23337,10 @@ static int virDomainPanicDefFormat(virBufferPtr buf,
virBufferAdjustIndent(&childrenBuf, indent + 2);
if (virDomainDeviceInfoFormat(&childrenBuf, &def->info, 0) < 0)
return -1;
if (virBufferCheckError(&childrenBuf) < 0)
return -1;
if (virBufferUse(&childrenBuf)) {
virBufferAddLit(buf, ">\n");
virBufferAddBuffer(buf, &childrenBuf);
......@@ -23671,6 +23687,9 @@ virDomainInputDefFormat(virBufferPtr buf,
if (virDomainDeviceInfoFormat(&childbuf, &def->info, flags) < 0)
return -1;
if (virBufferCheckError(&childbuf) < 0)
return -1;
if (!virBufferUse(&childbuf)) {
virBufferAddLit(buf, "/>\n");
} else {
......@@ -24612,6 +24631,9 @@ virDomainCputuneDefFormat(virBufferPtr buf,
def->iothreadids[i]->iothread_id);
}
if (virBufferCheckError(&childrenBuf) < 0)
return -1;
if (virBufferUse(&childrenBuf)) {
virBufferAddLit(buf, "<cputune>\n");
virBufferAddBuffer(buf, &childrenBuf);
......@@ -24725,7 +24747,8 @@ virDomainIOMMUDefFormat(virBufferPtr buf,
virBufferAsprintf(buf, "<iommu model='%s'",
virDomainIOMMUModelTypeToString(iommu->model));
if (virBufferUse(&childBuf)) {
if (virBufferError(&childBuf) != 0 || virBufferUse(&childBuf)) {
virBufferAddLit(buf, ">\n");
virBufferAddBuffer(buf, &childBuf);
virBufferAddLit(buf, "</iommu>\n");
......@@ -24863,6 +24886,10 @@ virDomainDefFormatInternal(virDomainDefPtr def,
virBufferAdjustIndent(&childrenBuf, -2);
virBufferAddLit(&childrenBuf, "</device>\n");
}
if (virBufferCheckError(&childrenBuf) < 0)
goto error;
if (virBufferUse(&childrenBuf)) {
virBufferAddLit(buf, "<blkiotune>\n");
virBufferAddBuffer(buf, &childrenBuf);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册