HomeFreeBSD

MFC r343479: Fix potential buffer overflow and undefined behavior.

Description

MFC r343479: Fix potential buffer overflow and undefined behavior.

The buffer allocated in read_chat() could be 1 element too short, if the
chatstr parameter passed in is 1 or 3 charachters long (e.g. "a" or "a b").
The allocation of the pointer array does not account for the terminating
NULL pointer in that case.

Overlapping source and destination strings are undefined in strcpy().
Instead of moving a string to the left by one character just increment the
char pointer before it is assigned to the results array.

Details

Provenance
seAuthored on
Parents
rS344125: MFC r343408: Silence Clang Scan warnings regarding unsafe use of strcp().
Branches
Unknown
Tags
Unknown