Ticket #304 (closed defect: fixed)

Opened 10 years ago

Last modified 10 years ago

Memory alignment error for hash entry buffer causing crash on ARM (thanks ChenHuan)

Reported by: bennylp Owned by: bennylp
Priority: normal Milestone: release-0.7.0
Component: pjlib Version: trunk
Keywords: Cc:
Backport to 1.x milestone: Backported:

Description (last modified by bennylp) (diff)

When application wants to specify its own buffer when registering an entry in the hash table, it calls pj_hash_set_np and gives it a buffer. This buffer normally is declared by application as:

  char buffer[PJ_HASH_ENTRY_SIZE];

This buffer will be typecasted to struct pj_hash_entry in hash.c:

struct pj_hash_entry
{
    struct pj_hash_entry *next;
    const void *key;
    pj_uint32_t hash;
    pj_uint32_t keylen;
    void *value;
};

And this is where the problem starts.

Since the buffer is of type array of char, this won't get aligned by compiler, and later in find_entry() in hash.c, it will cause unaligned memory access exception in assignment to entry->value.

Thanks ChenHuan <chenhuan at sict.ac.cn> for finding this problem!

Change History

comment:1 Changed 10 years ago by bennylp

  • Status changed from new to closed
  • Resolution set to fixed
  • Description modified (diff)

Fixed in r1307.

Application now should use this construct when declaring the hash buffer:

  pj_hash_entry_buf buffer;

This will make sure that the buffer is aligned and suitable for pointer assignment.

Note: See TracTickets for help on using tickets.