whoozle / android-file-transfer-linux

Android File Transfer for Linux (and macOS!)
http://whoozle.github.io/android-file-transfer-linux/
GNU Lesser General Public License v2.1
1.47k stars 120 forks source link

mtp/backend/linux/usb/Context.cpp:44: off by one error ? #303

Closed dcb314 closed 2 years ago

dcb314 commented 2 years ago

Static analyser cppcheck says:

mtp/backend/linux/usb/Context.cpp:44:9: error: Width 256 given in format string (no. 2) is larger than destination buffer 'portBuf[256]', use %255[0-9.] to prevent overflowing it. [invalidScanfFormatWidth]

Source code is

if (sscanf(entry.c_str(), "%u-%256[0-9.]:%u.%u", &busId, portBuf, &conf, &interface) == 4)

Suggest new code:

if (sscanf(entry.c_str(), "%u-%255[0-9.]:%u.%u", &busId, portBuf, &conf, &interface) == 4)

whoozle commented 2 years ago

I doubt that linux usbfs would be malicious actor, but nevertheless excellent catch, thanks!

dcb314 commented 2 years ago

Thank you. Would it be a good idea to use cppcheck in your development process ?

I use it in mine and I think it is very good.