afry-south / dragonfly-fcb

ÅF Dragonfly Quadrotor UAV Project
Other
7 stars 3 forks source link

strncat improper use? #75

Closed stenbergd closed 9 years ago

stenbergd commented 9 years ago

strncat is used extensively in the USB CDC command line interface.

But it looks like it may be used improperly. The size set is not the max allowed string size, but the max amount of characters that can be added.

This causes a risk if we do not calculate how many bytes left of original string size.

stenbergd commented 9 years ago

"If src contains n or more bytes, strncat() writes n+1 bytes to dest (n from src plus the terminating null byte). Therefore, the size of dest must be at least strlen(dest)+n+1."

stenbergd commented 9 years ago

This also goes for strcpy -> strncpy and sprintf -> snprintf

stenbergd commented 9 years ago

Done.