From 47e8150c9a912f4899e1a687ab754bf763db341f Mon Sep 17 00:00:00 2001 From: Maksym Litvinov Date: Thu, 21 Mar 2024 16:08:50 -0700 Subject: [PATCH] Safe handling of ignoredSourceOutputs array --- src/main.cpp | 2 +- src/pulse.cpp | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d35af12..cef01ff 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,7 +31,7 @@ int main(int argc, char *argv[]) { bool printSource = false; bool printSink = false; - char* ignoredSourceOutputs[MAX_IGNORED_SOURCE_OUTPUTS]; + char* ignoredSourceOutputs[MAX_IGNORED_SOURCE_OUTPUTS] = {nullptr}; int ignoredSourceOutputsCount = 0; if (argc > 1) { diff --git a/src/pulse.cpp b/src/pulse.cpp index 9994550..2b0d93c 100644 --- a/src/pulse.cpp +++ b/src/pulse.cpp @@ -44,12 +44,17 @@ void Pulse::source_output_info_callback(pa_context *, if (i && i->proplist) { const char *appName = pa_proplist_gets(i->proplist, "application.name"); if (appName) { - int i = 0; - while (data->ignoredSourceOutputs[i] != nullptr) { - if (strcmp(appName, data->ignoredSourceOutputs[i]) == 0) { + int ignoredSourceOutputsCount = 0; + while ( + data->ignoredSourceOutputs[ignoredSourceOutputsCount] != nullptr + && ignoreSourceOutput == false + && ignoredSourceOutputsCount < MAX_IGNORED_SOURCE_OUTPUTS + ) { + if (strcmp(appName, data->ignoredSourceOutputs[ignoredSourceOutputsCount]) == 0) { ignoreSourceOutput = true; + break; } - i++; + ignoredSourceOutputsCount++; } } }