Browse Source

PlutoSDR: use std::string prefix check in scan URI helper

Replace strncmp()/strlen() in withBackendPrefix() with
std::string::rfind(prefix, 0), as done elsewhere in this file. The
inputs were always null-terminated, but static analysis (Flawfinder,
CWE-126) flags any strlen() use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
chirpmodem-v8.0.0
Marcel 1 month ago
parent
commit
ad02539347
  1. 12
      devices/plutosdr/deviceplutosdrscan.cpp

12
devices/plutosdr/deviceplutosdrscan.cpp

@ -37,18 +37,18 @@ @@ -37,18 +37,18 @@
#ifdef LIBIIO_V1
// libiio 1.x reports network contexts as a bare host name, without the "ip:" prefix
static std::string withBackendPrefix(const char *uri)
static std::string withBackendPrefix(const std::string& uri)
{
static const char *backends[] = {"ip:", "usb:", "local:", "serial:", "xml:"};
static const std::string backends[] = {"ip:", "usb:", "local:", "serial:", "xml:"};
for (const char *backend : backends)
for (const std::string& backend : backends)
{
if (std::strncmp(uri, backend, std::strlen(backend)) == 0) {
return std::string(uri);
if (uri.rfind(backend, 0) == 0) {
return uri;
}
}
return std::string("ip:") + uri;
return "ip:" + uri;
}
#endif

Loading…
Cancel
Save