提交 5923ea67 编写于 作者: D Daniel P. Berrange

Fix error checking of qemuParseKeywords return status

Most callers of qemuParseKeywords were assigning its return
value to a 'size_t' variable. Then then also checked '< 0'
for error condition, but this will never be true with the
unsigned size_t variable. Rather than using 'ssize_t', change
qemuParseKeywords so that the element count is returned via
an output parameter, leaving the return value solely as an
error indicator.

This avoids a crash accessing beyond the end of an error
upon OOM.
Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
上级 150c1db5
...@@ -9776,6 +9776,7 @@ int ...@@ -9776,6 +9776,7 @@ int
qemuParseKeywords(const char *str, qemuParseKeywords(const char *str,
char ***retkeywords, char ***retkeywords,
char ***retvalues, char ***retvalues,
int *retnkeywords,
int allowEmptyValue) int allowEmptyValue)
{ {
int keywordCount = 0; int keywordCount = 0;
...@@ -9788,6 +9789,7 @@ qemuParseKeywords(const char *str, ...@@ -9788,6 +9789,7 @@ qemuParseKeywords(const char *str,
*retkeywords = NULL; *retkeywords = NULL;
*retvalues = NULL; *retvalues = NULL;
*retnkeywords = 0;
end = start + strlen(str); end = start + strlen(str);
while (start) { while (start) {
...@@ -9857,8 +9859,8 @@ qemuParseKeywords(const char *str, ...@@ -9857,8 +9859,8 @@ qemuParseKeywords(const char *str,
*retkeywords = keywords; *retkeywords = keywords;
*retvalues = values; *retvalues = values;
*retnkeywords = keywordCount;
return keywordCount; return 0;
error: error:
for (i = 0; i < keywordCount; i++) { for (i = 0; i < keywordCount; i++) {
...@@ -9893,9 +9895,11 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, ...@@ -9893,9 +9895,11 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt,
int unitid = -1; int unitid = -1;
int trans = VIR_DOMAIN_DISK_TRANS_DEFAULT; int trans = VIR_DOMAIN_DISK_TRANS_DEFAULT;
if ((nkeywords = qemuParseKeywords(val, if (qemuParseKeywords(val,
&keywords, &keywords,
&values, 0)) < 0) &values,
&nkeywords,
0) < 0)
return NULL; return NULL;
if (VIR_ALLOC(def) < 0) if (VIR_ALLOC(def) < 0)
...@@ -10244,9 +10248,11 @@ qemuParseCommandLineNet(virDomainXMLOptionPtr xmlopt, ...@@ -10244,9 +10248,11 @@ qemuParseCommandLineNet(virDomainXMLOptionPtr xmlopt,
tmp = strchr(val, ','); tmp = strchr(val, ',');
if (tmp) { if (tmp) {
if ((nkeywords = qemuParseKeywords(tmp+1, if (qemuParseKeywords(tmp+1,
&keywords, &keywords,
&values, 0)) < 0) &values,
&nkeywords,
0) < 0)
return NULL; return NULL;
} else { } else {
nkeywords = 0; nkeywords = 0;
...@@ -10314,9 +10320,11 @@ qemuParseCommandLineNet(virDomainXMLOptionPtr xmlopt, ...@@ -10314,9 +10320,11 @@ qemuParseCommandLineNet(virDomainXMLOptionPtr xmlopt,
VIR_FREE(values); VIR_FREE(values);
if (STRPREFIX(nic, "nic,")) { if (STRPREFIX(nic, "nic,")) {
if ((nkeywords = qemuParseKeywords(nic + strlen("nic,"), if (qemuParseKeywords(nic + strlen("nic,"),
&keywords, &keywords,
&values, 0)) < 0) { &values,
&nkeywords,
0) < 0) {
virDomainNetDefFree(def); virDomainNetDefFree(def);
def = NULL; def = NULL;
goto cleanup; goto cleanup;
...@@ -10820,8 +10828,7 @@ qemuParseCommandLineSmp(virDomainDefPtr dom, ...@@ -10820,8 +10828,7 @@ qemuParseCommandLineSmp(virDomainDefPtr dom,
char *end; char *end;
int ret; int ret;
nkws = qemuParseKeywords(val, &kws, &vals, 1); if (qemuParseKeywords(val, &kws, &vals, &nkws, 1) < 0)
if (nkws < 0)
return -1; return -1;
for (i = 0; i < nkws; i++) { for (i = 0; i < nkws; i++) {
......
...@@ -296,6 +296,7 @@ int ...@@ -296,6 +296,7 @@ int
qemuParseKeywords(const char *str, qemuParseKeywords(const char *str,
char ***retkeywords, char ***retkeywords,
char ***retvalues, char ***retvalues,
int *retnkeywords,
int allowEmptyValue); int allowEmptyValue);
#endif /* __QEMU_COMMAND_H__*/ #endif /* __QEMU_COMMAND_H__*/
...@@ -533,9 +533,7 @@ qemuMonitorJSONKeywordStringToJSON(const char *str, const char *firstkeyword) ...@@ -533,9 +533,7 @@ qemuMonitorJSONKeywordStringToJSON(const char *str, const char *firstkeyword)
if (!(ret = virJSONValueNewObject())) if (!(ret = virJSONValueNewObject()))
goto error; goto error;
nkeywords = qemuParseKeywords(str, &keywords, &values, 1); if (qemuParseKeywords(str, &keywords, &values, &nkeywords, 1) < 0)
if (nkeywords < 0)
goto error; goto error;
for (i = 0; i < nkeywords; i++) { for (i = 0; i < nkeywords; i++) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册