lsalzman / enet

ENet reliable UDP networking library
MIT License
2.72k stars 670 forks source link

packet.c: Fix UB when increasing the size of an unallocated packet #261

Closed cher-nov closed 3 months ago

cher-nov commented 3 months ago

https://en.cppreference.com/w/cpp/string/byte/memcpy

If either dest or src is an invalid or null pointer, the behavior is undefined, even if count is zero.

https://en.cppreference.com/w/c/string/byte/memcpy

The behavior is undefined if either dest or src is an invalid or null pointer.


I've also noticed a lot of trailing whitespace and odd (3-spaced) indentation in the current library code. Would you be interested in a pull request that fixes this?

lsalzman commented 3 months ago

Fixed.

cher-nov commented 3 months ago

Excuse me if my proposal offended you in any way, I didn't mean to.

Fixed.

May I ask, please, why are you checking packet->dataLength for 0 in your version of the patch? Calling the memcpy() function simply turns into a NOP in this case (if both pointers are valid), doesn’t it?

https://github.com/lsalzman/enet/blob/0b924c79ceb7b3c46d82dd00f6f1ed3f664d02d0/packet.c#L92-L98