1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-02-03 13:47:04 +03:00

alloc-util: use memcpy_safe() in memdup() or friends

This commit is contained in:
Yu Watanabe 2021-05-19 21:21:28 +09:00
parent d1f3b08098
commit 550721c2e3
2 changed files with 5 additions and 6 deletions

View File

@ -17,8 +17,7 @@ void* memdup(const void *p, size_t l) {
if (!ret)
return NULL;
memcpy(ret, p, l);
return ret;
return memcpy_safe(ret, p, l);
}
void* memdup_suffix0(const void *p, size_t l) {
@ -35,8 +34,8 @@ void* memdup_suffix0(const void *p, size_t l) {
if (!ret)
return NULL;
*((uint8_t*) mempcpy(ret, p, l)) = 0;
return ret;
((uint8_t*) ret)[l] = 0;
return memcpy_safe(ret, p, l);
}
void* greedy_realloc(void **p, size_t *allocated, size_t need, size_t size) {

View File

@ -66,7 +66,7 @@ void* memdup_suffix0(const void *p, size_t l); /* We can't use _alloc_() here, s
size_t _l_ = l; \
assert(_l_ <= ALLOCA_MAX); \
_q_ = alloca(_l_ ?: 1); \
memcpy(_q_, p, _l_); \
memcpy_safe(_q_, p, _l_); \
})
#define memdupa_suffix0(p, l) \
@ -76,7 +76,7 @@ void* memdup_suffix0(const void *p, size_t l); /* We can't use _alloc_() here, s
assert(_l_ <= ALLOCA_MAX); \
_q_ = alloca(_l_ + 1); \
((uint8_t*) _q_)[_l_] = 0; \
memcpy(_q_, p, _l_); \
memcpy_safe(_q_, p, _l_); \
})
static inline void freep(void *p) {