__FUNCTION__, __LINE__, __VA_ARGS__)
#if SIZEOF_LONG < 8
-# define HYPER_TO_TYPE(_type, _to, _from) \
- do { \
- if ((_from) != (_type)(_from)) { \
- virNetError(VIR_ERR_INTERNAL_ERROR, \
- _("conversion from hyper to %s overflowed"), #_type); \
- goto cleanup; \
- } \
- (_to) = (_from); \
+# define HYPER_TO_TYPE(_type, _to, _from) \
+ do { \
+ if ((_from) != (_type)(_from)) { \
+ virNetError(VIR_ERR_OVERFLOW, \
+ _("conversion from hyper to %s overflowed"), \
+ #_type); \
+ goto cleanup; \
+ } \
+ (_to) = (_from); \
} while (0)
# define HYPER_TO_LONG(_to, _from) HYPER_TO_TYPE(long, _to, _from)
* Description: Provides the interfaces of the libvirt library to handle
* errors raised while using the library.
*
- * Copy: Copyright (C) 2006, 2010-2011 Red Hat, Inc.
+ * Copy: Copyright (C) 2006, 2010-2012 Red Hat, Inc.
*
* See COPYING.LIB for the License of this software
*
VIR_ERR_AUTH_CANCELLED = 79, /* authentication cancelled */
VIR_ERR_NO_DOMAIN_METADATA = 80, /* The metadata is not present */
VIR_ERR_MIGRATE_UNSAFE = 81, /* Migration is not safe */
+ VIR_ERR_OVERFLOW = 82, /* integer overflow */
} virErrorNumber;
/**
}
/* Perform some argument validation common to all implementations. */
- if (nvcpus < 1 || (unsigned short) nvcpus != nvcpus) {
+ if (nvcpus < 1) {
virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
goto error;
}
+ if ((unsigned short) nvcpus != nvcpus) {
+ virLibDomainError(VIR_ERR_OVERFLOW, _("input too large: %u"), nvcpus);
+ goto error;
+ }
conn = domain->conn;
if (conn->driver->domainSetVcpusFlags) {
return -1;
}
- if (ncpumaps < 1 || !cpumaps || maplen <= 0 ||
- INT_MULTIPLY_OVERFLOW(ncpumaps, maplen)) {
+ if (ncpumaps < 1 || !cpumaps || maplen <= 0) {
virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
goto error;
}
+ if (INT_MULTIPLY_OVERFLOW(ncpumaps, maplen)) {
+ virLibDomainError(VIR_ERR_OVERFLOW, _("input too large: %d * %d"),
+ ncpumaps, maplen);
+ goto error;
+ }
/* At most one of these two flags should be set. */
if ((flags & VIR_DOMAIN_AFFECT_LIVE) &&
/* Ensure that domainGetVcpus (aka remoteDomainGetVcpus) does not
try to memcpy anything into a NULL pointer. */
- if (!cpumaps ? maplen != 0
- : (maplen <= 0 || INT_MULTIPLY_OVERFLOW(maxinfo, maplen))) {
+ if (!cpumaps ? maplen != 0 : maplen <= 0) {
virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
goto error;
}
+ if (cpumaps && INT_MULTIPLY_OVERFLOW(maxinfo, maplen)) {
+ virLibDomainError(VIR_ERR_OVERFLOW, _("input too large: %d * %d"),
+ maxinfo, maplen);
+ goto error;
+ }
conn = domain->conn;
if (start_cpu < -1 ||
(start_cpu == -1 && ncpus != 1) ||
((params == NULL) != (nparams == 0)) ||
- (ncpus == 0 && params != NULL) ||
- (nparams && ncpus > UINT_MAX / nparams)) {
+ (ncpus == 0 && params != NULL)) {
virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
goto error;
}
+ if (nparams && ncpus > UINT_MAX / nparams) {
+ virLibDomainError(VIR_ERR_OVERFLOW, _("input too large: %u * %u"),
+ nparams, ncpus);
+ goto error;
+ }
if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
VIR_DRV_FEATURE_TYPED_PARAM_STRING))
flags |= VIR_TYPED_PARAM_STRING_OKAY;