[Python-checkins] r50585 - in python/branches/bcannon-sandboxing: Include/sandbox.h Python/sandbox.c
brett.cannon
python-checkins at python.org
Tue Jul 11 20:46:20 CEST 2006
Author: brett.cannon
Date: Tue Jul 11 20:46:19 2006
New Revision: 50585
Modified:
python/branches/bcannon-sandboxing/Include/sandbox.h
python/branches/bcannon-sandboxing/Python/sandbox.c
Log:
Switch to using size_t for memory tracking. Also watch for integer overflow.
Modified: python/branches/bcannon-sandboxing/Include/sandbox.h
==============================================================================
--- python/branches/bcannon-sandboxing/Include/sandbox.h (original)
+++ python/branches/bcannon-sandboxing/Include/sandbox.h Tue Jul 11 20:46:19 2006
@@ -10,8 +10,8 @@
typedef struct _sandbox_state {
/* The memory cap and current usage. */
- Py_ssize_t mem_cap;
- Py_ssize_t mem_usage;
+ size_t mem_cap;
+ size_t mem_usage;
} PySandboxState;
Modified: python/branches/bcannon-sandboxing/Python/sandbox.c
==============================================================================
--- python/branches/bcannon-sandboxing/Python/sandbox.c (original)
+++ python/branches/bcannon-sandboxing/Python/sandbox.c Tue Jul 11 20:46:19 2006
@@ -31,18 +31,19 @@
PySandboxState *sandbox_state = _PySandbox_GET();
if (_PySandbox_Check() && _PySandbox_IsMemCapped()) {
+ size_t orig_mem_usage = sandbox_state->mem_usage;
+
sandbox_state->mem_usage += allocate;
- if (sandbox_state->mem_cap < sandbox_state->mem_usage) {
+ /* Watch out for integer overflow. */
+ if ((sandbox_state->mem_cap < sandbox_state->mem_usage) ||
+ (orig_mem_usage > sandbox_state->mem_usage)) {
sandbox_state -= allocate;
PyErr_SetString(PyExc_SandboxError, "memory allocation exceeded");
return 0;
}
- else
- return 1;
-
}
- else
- return 1;
+
+ return 1;
}
/*
More information about the Python-checkins
mailing list