mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-18 07:00:06 -05:00
spa: add spa_ptrinside
Add a new overflow safe function to check if region p2 of size s2 fits completely in p1 of size s1. Use this to bounds check the pod iterators. Fixes #3727
This commit is contained in:
parent
92ac9a355f
commit
10d3c547d1
2 changed files with 11 additions and 9 deletions
|
|
@ -178,7 +178,6 @@ struct spa_fraction {
|
|||
#define SPA_PTROFF_ALIGN(ptr_,offset_,alignment_,type_) \
|
||||
SPA_PTR_ALIGN(SPA_PTROFF(ptr_,offset_,type_),alignment_,type_)
|
||||
|
||||
|
||||
/**
|
||||
* Deprecated, use SPA_PTROFF and SPA_PTROFF_ALIGN instead
|
||||
*/
|
||||
|
|
@ -189,6 +188,12 @@ struct spa_fraction {
|
|||
|
||||
#define SPA_PTRDIFF(p1,p2) ((intptr_t)(p1) - (intptr_t)(p2))
|
||||
|
||||
static inline bool spa_ptrinside(const void *p1, size_t s1, const void *p2, size_t s2)
|
||||
{
|
||||
return (uintptr_t)p1 <= (uintptr_t)p2 && s2 <= s1 &&
|
||||
(uintptr_t)p2 - (uintptr_t)p1 <= s1 - s2;
|
||||
}
|
||||
|
||||
#define SPA_PTR_TO_INT(p) ((int) ((intptr_t) (p)))
|
||||
#define SPA_INT_TO_PTR(u) ((void*) ((intptr_t) (u)))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue