Rajaram-Regupathy / libtypec

“libtypec” is aimed to provide a generic interface abstracting all platform complexity for user space to develop tools for efficient USB-C port management. The library can also enable development of diagnostic and debug tools to debug system issues around USB-C/USB PD topology.
34 stars 4 forks source link

wrong use of sizeof being used on a string pointer and not the string in function get_svid_string() #36

Open ColinIanKing opened 2 months ago

ColinIanKing commented 2 months ago

In function get_svid_string() the sizeof(str) operator is being incorrectly used to determine the size of the string str. The current use will return the size of the pointer, which will be 4 (32 bit systems) or 8 (64 bit systems) and not the size of the string.

Static analysis reports:

224void get_svid_string(uint32_t svid, char* str) {
225
226    switch (svid) {
227        case 0xFF01:
228            strcpy(str, "Display Alternate Mode");
229            break;
230        case 0x8087:
231            strcpy(str, "TBT Alternate Mode");
232            break;
233        default:

suspicious_sizeof: Passing argument str of type char * and argument 8UL /* sizeof (str) */ to function get_vendor_string is suspicious.

234            get_vendor_string(str, sizeof(str), svid);
235            break;
236    }
237}