aboutsummaryrefslogtreecommitdiffstats
path: root/lib/packing.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/packing.c')
-rw-r--r--lib/packing.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/packing.c b/lib/packing.c
index 3f656167c17e0c..439125286d2b4e 100644
--- a/lib/packing.c
+++ b/lib/packing.c
@@ -86,8 +86,10 @@ int packing(void *pbuf, u64 *uval, int startbit, int endbit, size_t pbuflen,
*/
int plogical_first_u8, plogical_last_u8, box;
- /* startbit is expected to be larger than endbit */
- if (startbit < endbit)
+ /* startbit is expected to be larger than endbit, and both are
+ * expected to be within the logically addressable range of the buffer.
+ */
+ if (unlikely(startbit < endbit || startbit >= 8 * pbuflen || endbit < 0))
/* Invalid function call */
return -EINVAL;