From ad02539347db9fc8e30fab87e19c14e8e471f2e0 Mon Sep 17 00:00:00 2001 From: Marcel Date: Mon, 19 Oct 2026 11:12:58 -0400 Subject: [PATCH] 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 --- devices/plutosdr/deviceplutosdrscan.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/devices/plutosdr/deviceplutosdrscan.cpp b/devices/plutosdr/deviceplutosdrscan.cpp index 50ced1685..cc4cb66e6 100644 --- a/devices/plutosdr/deviceplutosdrscan.cpp +++ b/devices/plutosdr/deviceplutosdrscan.cpp @@ -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