Skip to content

Commit

Permalink
Fix pointer arithmetic (invalid use of void in umm_poison_*)
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Ismirlian committed Sep 14, 2022
1 parent 12b717c commit 85f9a7f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/umm_poison.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ static bool check_poison_block(umm_block *pblock) {
void *pc = (void *)pblock->body.data;
void *pc_cur;

pc_cur = pc + sizeof(UMM_POISONED_BLOCK_LEN_TYPE);
pc_cur = (uint8_t *)pc + sizeof(UMM_POISONED_BLOCK_LEN_TYPE);
if (!check_poison(pc_cur, UMM_POISON_SIZE_BEFORE, "before")) {
ok = false;
goto clean;
}

pc_cur = pc + *((UMM_POISONED_BLOCK_LEN_TYPE *)pc) - UMM_POISON_SIZE_AFTER;
pc_cur = (uint8_t *)pc + *((UMM_POISONED_BLOCK_LEN_TYPE *)pc) - UMM_POISON_SIZE_AFTER;
if (!check_poison(pc_cur, UMM_POISON_SIZE_AFTER, "after")) {
ok = false;
goto clean;
Expand All @@ -103,16 +103,16 @@ static void *get_poisoned(void *ptr, size_t size_w_poison) {
if (size_w_poison != 0 && ptr != NULL) {

/* Poison beginning and the end of the allocated chunk */
put_poison(ptr + sizeof(UMM_POISONED_BLOCK_LEN_TYPE),
put_poison((uint8_t *)ptr + sizeof(UMM_POISONED_BLOCK_LEN_TYPE),
UMM_POISON_SIZE_BEFORE);
put_poison(ptr + size_w_poison - UMM_POISON_SIZE_AFTER,
put_poison((uint8_t *)ptr + size_w_poison - UMM_POISON_SIZE_AFTER,
UMM_POISON_SIZE_AFTER);

/* Put exact length of the user's chunk of memory */
*(UMM_POISONED_BLOCK_LEN_TYPE *)ptr = (UMM_POISONED_BLOCK_LEN_TYPE)size_w_poison;

/* Return pointer at the first non-poisoned byte */
return ptr + sizeof(UMM_POISONED_BLOCK_LEN_TYPE) + UMM_POISON_SIZE_BEFORE;
return (uint8_t *)ptr + sizeof(UMM_POISONED_BLOCK_LEN_TYPE) + UMM_POISON_SIZE_BEFORE;
} else {
return ptr;
}
Expand All @@ -128,10 +128,10 @@ static void *get_unpoisoned(void *ptr) {
if (ptr != NULL) {
uint16_t c;

ptr -= (sizeof(UMM_POISONED_BLOCK_LEN_TYPE) + UMM_POISON_SIZE_BEFORE);
ptr = (uint8_t *)ptr - (sizeof(UMM_POISONED_BLOCK_LEN_TYPE) + UMM_POISON_SIZE_BEFORE);

/* Figure out which block we're in. Note the use of truncated division... */
c = (((void *)ptr) - (void *)(&(UMM_HEAP[0]))) / UMM_BLOCKSIZE;
c = (((uint8_t *)ptr) - (uint8_t *)(&(UMM_HEAP[0]))) / UMM_BLOCKSIZE;

check_poison_block(&UMM_BLOCK(c));
}
Expand Down

0 comments on commit 85f9a7f

Please sign in to comment.