提交 5df81317 编写于 作者: P Peter Krempa

util: Check return value from virStrToLong* functions

We do so in the vast majority of places, so there's no problem of adding
the attribute to enforce it by the complier and fix a few leftover
places.

This was originally pointed out by Coverity as a recent change triggered
it's warning that our code checked the vast majority of returns from
virStrToLong_ui.
上级 ba2b4da0
...@@ -567,7 +567,7 @@ sexpr_int(const struct sexpr *sexpr, const char *name) ...@@ -567,7 +567,7 @@ sexpr_int(const struct sexpr *sexpr, const char *name)
if (value) { if (value) {
int val = 0; int val = 0;
virStrToLong_i(value, NULL, 0, &val); ignore_value(virStrToLong_i(value, NULL, 0, &val));
return val; return val;
} }
return 0; return 0;
...@@ -590,7 +590,7 @@ sexpr_float(const struct sexpr *sexpr, const char *name) ...@@ -590,7 +590,7 @@ sexpr_float(const struct sexpr *sexpr, const char *name)
if (value) { if (value) {
double val = 0; double val = 0;
virStrToDouble(value, NULL, &val); ignore_value(virStrToDouble(value, NULL, &val));
return val; return val;
} }
return 0; return 0;
...@@ -613,7 +613,7 @@ sexpr_u64(const struct sexpr *sexpr, const char *name) ...@@ -613,7 +613,7 @@ sexpr_u64(const struct sexpr *sexpr, const char *name)
if (value) { if (value) {
unsigned long long val = 0; unsigned long long val = 0;
virStrToLong_ull(value, NULL, 0, &val); ignore_value(virStrToLong_ull(value, NULL, 0, &val));
return val; return val;
} }
return 0; return 0;
......
...@@ -51,43 +51,53 @@ char *virArgvToString(const char *const *argv); ...@@ -51,43 +51,53 @@ char *virArgvToString(const char *const *argv);
int virStrToLong_i(char const *s, int virStrToLong_i(char const *s,
char **end_ptr, char **end_ptr,
int base, int base,
int *result); int *result)
ATTRIBUTE_RETURN_CHECK;
int virStrToLong_ui(char const *s, int virStrToLong_ui(char const *s,
char **end_ptr, char **end_ptr,
int base, int base,
unsigned int *result); unsigned int *result)
ATTRIBUTE_RETURN_CHECK;
int virStrToLong_uip(char const *s, int virStrToLong_uip(char const *s,
char **end_ptr, char **end_ptr,
int base, int base,
unsigned int *result); unsigned int *result)
ATTRIBUTE_RETURN_CHECK;
int virStrToLong_l(char const *s, int virStrToLong_l(char const *s,
char **end_ptr, char **end_ptr,
int base, int base,
long *result); long *result)
ATTRIBUTE_RETURN_CHECK;
int virStrToLong_ul(char const *s, int virStrToLong_ul(char const *s,
char **end_ptr, char **end_ptr,
int base, int base,
unsigned long *result); unsigned long *result)
ATTRIBUTE_RETURN_CHECK;
int virStrToLong_ulp(char const *s, int virStrToLong_ulp(char const *s,
char **end_ptr, char **end_ptr,
int base, int base,
unsigned long *result); unsigned long *result)
ATTRIBUTE_RETURN_CHECK;
int virStrToLong_ll(char const *s, int virStrToLong_ll(char const *s,
char **end_ptr, char **end_ptr,
int base, int base,
long long *result); long long *result)
ATTRIBUTE_RETURN_CHECK;
int virStrToLong_ull(char const *s, int virStrToLong_ull(char const *s,
char **end_ptr, char **end_ptr,
int base, int base,
unsigned long long *result); unsigned long long *result)
ATTRIBUTE_RETURN_CHECK;
int virStrToLong_ullp(char const *s, int virStrToLong_ullp(char const *s,
char **end_ptr, char **end_ptr,
int base, int base,
unsigned long long *result); unsigned long long *result)
ATTRIBUTE_RETURN_CHECK;
int virStrToDouble(char const *s, int virStrToDouble(char const *s,
char **end_ptr, char **end_ptr,
double *result); double *result)
ATTRIBUTE_RETURN_CHECK;
void virSkipSpaces(const char **str) ATTRIBUTE_NONNULL(1); void virSkipSpaces(const char **str) ATTRIBUTE_NONNULL(1);
void virSkipSpacesAndBackslash(const char **str) ATTRIBUTE_NONNULL(1); void virSkipSpacesAndBackslash(const char **str) ATTRIBUTE_NONNULL(1);
......
...@@ -2344,8 +2344,8 @@ static void vboxHostDeviceGetXMLDesc(vboxGlobalData *data, virDomainDefPtr def, ...@@ -2344,8 +2344,8 @@ static void vboxHostDeviceGetXMLDesc(vboxGlobalData *data, virDomainDefPtr def,
VBOX_UTF16_TO_UTF8(vendorIdUtf16, &vendorIdUtf8); VBOX_UTF16_TO_UTF8(vendorIdUtf16, &vendorIdUtf8);
VBOX_UTF16_TO_UTF8(productIdUtf16, &productIdUtf8); VBOX_UTF16_TO_UTF8(productIdUtf16, &productIdUtf8);
virStrToLong_ui(vendorIdUtf8, &endptr, 16, &vendorId); ignore_value(virStrToLong_ui(vendorIdUtf8, &endptr, 16, &vendorId));
virStrToLong_ui(productIdUtf8, &endptr, 16, &productId); ignore_value(virStrToLong_ui(productIdUtf8, &endptr, 16, &productId));
def->hostdevs[USBFilterCount]->source.subsys.u.usb.vendor = vendorId; def->hostdevs[USBFilterCount]->source.subsys.u.usb.vendor = vendorId;
def->hostdevs[USBFilterCount]->source.subsys.u.usb.product = productId; def->hostdevs[USBFilterCount]->source.subsys.u.usb.product = productId;
......
...@@ -335,7 +335,7 @@ xenStoreDomainGetVNCPort(virConnectPtr conn, int domid) ...@@ -335,7 +335,7 @@ xenStoreDomainGetVNCPort(virConnectPtr conn, int domid)
tmp = virDomainDoStoreQuery(conn, domid, "console/vnc-port"); tmp = virDomainDoStoreQuery(conn, domid, "console/vnc-port");
if (tmp != NULL) { if (tmp != NULL) {
virStrToLong_i(tmp, NULL, 10, &ret); ignore_value(virStrToLong_i(tmp, NULL, 10, &ret));
VIR_FREE(tmp); VIR_FREE(tmp);
} }
return ret; return ret;
......
...@@ -1026,8 +1026,13 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ...@@ -1026,8 +1026,13 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
if (VIR_STRDUP(graphics->data.vnc.keymap, key + 7) < 0) if (VIR_STRDUP(graphics->data.vnc.keymap, key + 7) < 0)
goto cleanup; goto cleanup;
} else if (STRPREFIX(key, "vncdisplay=")) { } else if (STRPREFIX(key, "vncdisplay=")) {
virStrToLong_i(key + 11, NULL, 10, if (virStrToLong_i(key + 11, NULL, 10,
&graphics->data.vnc.port); &graphics->data.vnc.port) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("invalid vncdisplay value '%s'"),
key + 11);
goto cleanup;
}
graphics->data.vnc.port += 5900; graphics->data.vnc.port += 5900;
} }
} else { } else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册