mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 15:27:47 +00:00
virDomainAudioCommonParse: Use virXMLProp*
This strictens the parser to disallow negative values (interpreted as `UINT_MAX + value + 1`) for attributes `voices` (typically 1), `bufferLength` (measured in milliseconds), `frequency` (in Hz, typically 44100), and `channels` (typically 2 for stereo). None of these properties benefit from or have a sensible use-case for wrap-around behavior. Signed-off-by: Tim Wiederhake <twiederh@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com> Signed-off-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
c9876ccf56
commit
38180f87f5
@ -13044,31 +13044,19 @@ virDomainAudioCommonParse(virDomainAudioIOCommon *def,
|
|||||||
xmlNodePtr node,
|
xmlNodePtr node,
|
||||||
xmlXPathContextPtr ctxt)
|
xmlXPathContextPtr ctxt)
|
||||||
{
|
{
|
||||||
g_autofree char *mixingEngine = virXMLPropString(node, "mixingEngine");
|
|
||||||
g_autofree char *fixedSettings = virXMLPropString(node, "fixedSettings");
|
|
||||||
g_autofree char *voices = virXMLPropString(node, "voices");
|
|
||||||
g_autofree char *bufferLength = virXMLPropString(node, "bufferLength");
|
|
||||||
xmlNodePtr settings;
|
xmlNodePtr settings;
|
||||||
VIR_XPATH_NODE_AUTORESTORE(ctxt);
|
VIR_XPATH_NODE_AUTORESTORE(ctxt);
|
||||||
|
|
||||||
ctxt->node = node;
|
ctxt->node = node;
|
||||||
settings = virXPathNode("./settings", ctxt);
|
settings = virXPathNode("./settings", ctxt);
|
||||||
|
|
||||||
if (mixingEngine &&
|
if (virXMLPropTristateBool(node, "mixingEngine", VIR_XML_PROP_NONE,
|
||||||
((def->mixingEngine =
|
&def->mixingEngine) < 0)
|
||||||
virTristateBoolTypeFromString(mixingEngine)) <= 0)) {
|
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
|
||||||
_("unknown 'mixingEngine' value '%s'"), mixingEngine);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
if (fixedSettings &&
|
if (virXMLPropTristateBool(node, "fixedSettings", VIR_XML_PROP_NONE,
|
||||||
((def->fixedSettings =
|
&def->fixedSettings) < 0)
|
||||||
virTristateBoolTypeFromString(fixedSettings)) <= 0)) {
|
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
|
||||||
_("unknown 'fixedSettings' value '%s'"), fixedSettings);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
if (def->fixedSettings == VIR_TRISTATE_BOOL_YES &&
|
if (def->fixedSettings == VIR_TRISTATE_BOOL_YES &&
|
||||||
def->mixingEngine != VIR_TRISTATE_BOOL_YES) {
|
def->mixingEngine != VIR_TRISTATE_BOOL_YES) {
|
||||||
@ -13077,59 +13065,38 @@ virDomainAudioCommonParse(virDomainAudioIOCommon *def,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (voices &&
|
if (virXMLPropUInt(node, "voices", 10,
|
||||||
(virStrToLong_ui(voices, NULL, 10, &def->voices) < 0 ||
|
VIR_XML_PROP_NONZERO,
|
||||||
!def->voices)) {
|
&def->voices) < 0)
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
|
||||||
_("cannot parse 'voices' value '%s'"), voices);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
if (bufferLength &&
|
if (virXMLPropUInt(node, "bufferLength", 10,
|
||||||
(virStrToLong_ui(bufferLength, NULL, 10, &def->bufferLength) < 0 ||
|
VIR_XML_PROP_NONZERO,
|
||||||
!def->bufferLength)) {
|
&def->bufferLength) < 0)
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
|
||||||
_("cannot parse 'bufferLength' value '%s'"), bufferLength);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
if (settings) {
|
if (settings) {
|
||||||
g_autofree char *frequency = virXMLPropString(settings, "frequency");
|
|
||||||
g_autofree char *channels = virXMLPropString(settings, "channels");
|
|
||||||
g_autofree char *format = virXMLPropString(settings, "format");
|
|
||||||
|
|
||||||
if (def->fixedSettings != VIR_TRISTATE_BOOL_YES) {
|
if (def->fixedSettings != VIR_TRISTATE_BOOL_YES) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
_("audio settings specified without fixed settings flag"));
|
_("audio settings specified without fixed settings flag"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (frequency &&
|
if (virXMLPropUInt(settings, "frequency", 10,
|
||||||
(virStrToLong_ui(frequency, NULL, 10, &def->frequency) < 0 ||
|
VIR_XML_PROP_NONZERO,
|
||||||
!def->frequency)) {
|
&def->frequency) < 0)
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
|
||||||
_("cannot parse 'frequency' value '%s'"), frequency);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
if (channels &&
|
if (virXMLPropUInt(settings, "channels", 10,
|
||||||
(virStrToLong_ui(channels, NULL, 10, &def->channels) < 0 ||
|
VIR_XML_PROP_NONZERO,
|
||||||
!def->channels)) {
|
&def->channels) < 0)
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
|
||||||
_("cannot parse 'channels' value '%s'"), channels);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
if (format) {
|
if (virXMLPropEnum(settings, "format",
|
||||||
int value;
|
virDomainAudioFormatTypeFromString,
|
||||||
if ((value = virDomainAudioFormatTypeFromString(format)) <= 0) {
|
VIR_XML_PROP_NONE, &def->format) < 0)
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
|
||||||
_("cannot parse 'format' value '%s'"), format);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
def->format = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user