mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-05 16:00:05 +01:00
Add crypt_safe_alloc_size helper.
Returns size of the payload. Zero means error.
This commit is contained in:
committed by
Milan Broz
parent
54d937dfc7
commit
f86ab28ad6
@@ -281,4 +281,6 @@ static inline bool uint64_mult_overflow(uint64_t *u, uint64_t b, size_t size)
|
||||
#define KEY_EXTERNAL_VERIFICATION -1
|
||||
#define KEY_VERIFIED 0
|
||||
|
||||
size_t crypt_safe_alloc_size(const void *data);
|
||||
|
||||
#endif /* INTERNAL_H */
|
||||
|
||||
@@ -107,3 +107,15 @@ void *crypt_safe_realloc(void *data, size_t size)
|
||||
crypt_safe_free(data);
|
||||
return new_data;
|
||||
}
|
||||
|
||||
size_t crypt_safe_alloc_size(const void *data)
|
||||
{
|
||||
const void *p;
|
||||
|
||||
if (!data)
|
||||
return 0;
|
||||
|
||||
p = (const char *)data - OVERHEAD;
|
||||
|
||||
return ((const struct safe_allocation *)p)->size;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user