Add crypt_safe_alloc_size helper.

Returns size of the payload. Zero means error.
This commit is contained in:
Ondrej Kozina
2025-02-03 16:57:42 +01:00
committed by Milan Broz
parent 54d937dfc7
commit f86ab28ad6
2 changed files with 14 additions and 0 deletions

View File

@@ -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 */

View File

@@ -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;
}