int ret = -1;
unsigned long long bytes, max;
- /* On 32-bit machines, our bound is 0xffffffff * KiB. On 64-bit
- * machines, our bound is off_t (2^63). */
- if (capped && sizeof(unsigned long) < sizeof(long long))
- max = 1024ull * ULONG_MAX;
- else
- max = LLONG_MAX;
+ max = virMemoryMaxValue(capped);
ret = virDomainParseScaledValue(xpath, units_xpath, ctxt,
&bytes, 1024, max, required);
virCheckReadOnlyGoto(conn->flags, error);
virCheckNonZeroArgGoto(memory, error);
+ if (virMemoryMaxValue(true) / 1024 <= memory) {
+ virReportError(VIR_ERR_OVERFLOW, _("input too large: %lu"),
+ memory);
+ goto error;
+ }
+
if (conn->driver->domainSetMaxMemory) {
int ret;
ret = conn->driver->domainSetMaxMemory(domain, memory);
virCheckReadOnlyGoto(conn->flags, error);
virCheckNonZeroArgGoto(memory, error);
+ if (virMemoryMaxValue(true) / 1024 <= memory) {
+ virReportError(VIR_ERR_OVERFLOW, _("input too large: %lu"),
+ memory);
+ goto error;
+ }
+
if (conn->driver->domainSetMemory) {
int ret;
ret = conn->driver->domainSetMemory(domain, memory);
virCheckReadOnlyGoto(conn->flags, error);
virCheckNonZeroArgGoto(memory, error);
+ if (virMemoryMaxValue(true) / 1024 <= memory) {
+ virReportError(VIR_ERR_OVERFLOW, _("input too large: %lu"),
+ memory);
+ goto error;
+ }
+
if (conn->driver->domainSetMemoryFlags) {
int ret;
ret = conn->driver->domainSetMemoryFlags(domain, memory, flags);
{
return value < VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
}
+
+
+/**
+ * virMemoryMaxValue
+ *
+ * @ulong: whether the value must fit into unsigned long
+ * (long long is assumed otherwise)
+ *
+ * Returns the maximum possible memory value in bytes.
+ */
+unsigned long long
+virMemoryMaxValue(bool ulong)
+{
+ /* On 32-bit machines, our bound is 0xffffffff * KiB. On 64-bit
+ * machines, our bound is off_t (2^63). */
+ if (ulong && sizeof(unsigned long) < sizeof(long long))
+ return 1024ull * ULONG_MAX;
+ else
+ return LLONG_MAX;
+}
unsigned long long virMemoryLimitTruncate(unsigned long long value);
bool virMemoryLimitIsSet(unsigned long long value);
+unsigned long long virMemoryMaxValue(bool ulong);
#endif /* __VIR_UTIL_H__ */