Skip to content

Commit 28b7fb3

Browse files
committed
Fix JSON output and network configuration
- Fixed invalid JSON output in DeviceManager: changed '}' to ']}' to properly close device list array - Added proper JSON string escaping using StringBuilder::stringify() to prevent XSS/injection vulnerabilities - Set default network configuration for UDPStreamer and TCPClientStreamer (127.0.0.1:10110) - Fixed install script path: corrected DBMS directory reference from 'DBMS/create.sql' to 'Source/DBMS/create.sql'
1 parent e0f7242 commit 28b7fb3

6 files changed

Lines changed: 186 additions & 94 deletions

File tree

Source/Application/Config.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ bool Config::isActiveObject(const JSON::Value &pd)
3838
void Config::setSettingsFromJSON(const JSON::Value &pd, Setting &s)
3939
{
4040

41-
for (const JSON::Property &p : pd.getObject().getProperties()) {
41+
for (const JSON::Property &p : pd.getObject().getProperties())
42+
{
43+
if (p.Key() < 0 || p.Key() >= AIS::KeyMap.size())
44+
continue;
45+
4246
if (p.Key() != AIS::KEY_SETTING_ACTIVE)
4347
{
4448
s.Set(AIS::KeyMap[p.Key()][JSON_DICT_SETTING], p.Get().to_string());
@@ -350,11 +354,10 @@ void Config::setSharing(const std::vector<JSON::Property> &props)
350354
_msg.push_back(std::unique_ptr<IO::OutputMessage>(new IO::TCPClientStreamer()));
351355
commm_feed = _msg.back().get();
352356

353-
commm_feed->Set("HOST", AISCATCHER_URL).Set("PORT", AISCATCHER_PORT).Set("MSGFORMAT", "COMMUNITY_HUB").Set("FILTER", "on").Set("GPS", "off").Set("REMOVE_EMPTY","on").Set("KEEP_ALIVE", "on").Set("DOWNSAMPLE", "on").Set("INCLUDE_SAMPLE_START", "on");
357+
commm_feed->Set("HOST", AISCATCHER_URL).Set("PORT", AISCATCHER_PORT).Set("MSGFORMAT", "COMMUNITY_HUB").Set("FILTER", "on").Set("GPS", "off").Set("REMOVE_EMPTY", "on").Set("KEEP_ALIVE", "on").Set("DOWNSAMPLE", "on").Set("INCLUDE_SAMPLE_START", "on");
354358
}
355359
if (!uuid.empty() && commm_feed)
356360
commm_feed->Set("UUID", uuid);
357-
358361
}
359362

360363
void Config::set(const std::string &str)
@@ -447,7 +450,10 @@ void Config::set(const std::string &str)
447450
_screen.verboseUpdateTime = Util::Parse::Integer(p.Get().to_string(), 1, 300);
448451
break;
449452
default:
450-
throw std::runtime_error("Config file: field \"" + AIS::KeyMap[p.Key()][JSON_DICT_SETTING] + "\" in main section is not allowed.");
453+
if (p.Key() >= 0 && p.Key() < AIS::KeyMap.size())
454+
throw std::runtime_error("Config file: field \"" + AIS::KeyMap[p.Key()][JSON_DICT_SETTING] + "\" in main section is not allowed.");
455+
else
456+
throw std::runtime_error("Config file: unknown field in main section is not allowed.");
451457
}
452458
}
453459
}

Source/Application/DeviceManager.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "DeviceManager.h"
2121
#include "Logger.h"
2222
#include "Parse.h"
23+
#include "StringBuilder.h"
2324

2425
std::vector<Device::Description> DeviceManager::device_list;
2526

@@ -170,20 +171,28 @@ void DeviceManager::printAvailableDevices(bool JSON)
170171
for (int i = 0; i < device_list.size(); i++)
171172
{
172173
std::string type = Util::Parse::DeviceTypeString(device_list[i].getType());
173-
std::cout << "{\"input\":\"" + type;
174-
std::cout << "\",\"serial\":\"" + device_list[i].getSerial();
175-
std::cout << "\",\"name\":\"" + type + " [" + device_list[i].getSerial() + "]\"";
174+
std::string serial = device_list[i].getSerial();
175+
std::string name = type + " [" + serial + "]";
176+
177+
// Properly escape JSON strings
178+
std::string type_escaped = JSON::StringBuilder::stringify(type, false);
179+
std::string serial_escaped = JSON::StringBuilder::stringify(serial, false);
180+
std::string name_escaped = JSON::StringBuilder::stringify(name, false);
181+
182+
std::cout << "{\"input\":\"" + type_escaped;
183+
std::cout << "\",\"serial\":\"" + serial_escaped;
184+
std::cout << "\",\"name\":\"" + name_escaped + "\"";
176185

177186
std::cout << "}" << (i == device_list.size() - 1 ? "" : ",");
178187
}
179-
std::cout << "}\n";
188+
std::cout << "]}\n";
180189
}
181190
}
182191

183192
void DeviceManager::selectDeviceByIndex(int index)
184193
{
185194
if (index < 0 || index >= device_list.size())
186195
throw std::runtime_error("device does not exist");
187-
196+
188197
serial = device_list[index].getSerial();
189198
}

0 commit comments

Comments
 (0)