antirez / antirez/lua-cmsgpack

mp_buf_append and sanitizing realloc

Open
#66 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
383
Forks
122
PR merge metrics
No merged PRs in 30d

Description

I noticed mp_buf_append and mp_buf_new are not sanitizing the result to [mp_realloc](https://github.com/antirez/lua-cmsgpack/blob/master/lua_cmsgpack.c#L122).

The Lua documentation states that when the pointer is non-null is must behave like realloc (and in the default case it is: `return realloc(ptr, nsize)`). In turn, when realloc fails the original block is left untouched and NULL is returned, which paths into a memcpy (and likely segmenta.... fau.. or something else entirely dependent on `buf->len`).

While a minor issue, a bit of defensive programming here would not hurt.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.