compile error and NULL ptr deref
GWO opened this issue · 1 comments
GWO commented
Hi,
Great software. Here's a patch that fixes:
i) a compile error on gcc-4.8 [getuid() now needs <unistd.h> including explicitly]
ii) a NULL pointer deref on ./jmtpfs -l with an unknown device
GWO commented
diff --git a/src/ConnectedMtpDevices.cpp b/src/ConnectedMtpDevices.cpp index b0f569a..c6541e1 100644 --- a/src/ConnectedMtpDevices.cpp +++ b/src/ConnectedMtpDevices.cpp @@ -92,9 +92,17 @@ ConnectedDeviceInfo ConnectedMtpDevices::GetDeviceInfo(int index) info.bus_location = m_devs[index].bus_location; info.devnum = m_devs[index].devnum; info.device_flags = m_devs[index].device_entry.device_flags; - info.product = m_devs[index].device_entry.product; + if(m_devs[index].device_entry.product != NULL) { + info.product = m_devs[index].device_entry.product; + } else { + info.product = "UNKNOWN"; + } info.product_id = m_devs[index].device_entry.product_id; - info.vendor = m_devs[index].device_entry.vendor; + if(m_devs[index].device_entry.vendor != NULL) { + info.vendor = m_devs[index].device_entry.vendor; + } else { + info.product = "UNKNOWN"; + } info.vendor_id = m_devs[index].device_entry.vendor_id; return info; diff --git a/src/jmtpfs.cpp b/src/jmtpfs.cpp index 2d2eed4..ce7390d 100644 --- a/src/jmtpfs.cpp +++ b/src/jmtpfs.cpp @@ -32,6 +32,7 @@ #include <sstream> #include <iomanip> #include <assert.h> +#include <unistd.h> #define JMTPFS_VERSION "0.4"