mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
chore: safety-checks before accessing the result of GetConfig()
This commit is contained in:
parent
9e554ce527
commit
9bbfb73622
@ -323,6 +323,10 @@ void Config::FirstRunPasswordSetup()
|
|||||||
|
|
||||||
// check if the password is already set
|
// check if the password is already set
|
||||||
auto config = GetConfig();
|
auto config = GetConfig();
|
||||||
|
if (!config) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!(config->Secret.isEmpty()) && !(config->Salt.isEmpty())) {
|
if (!(config->Secret.isEmpty()) && !(config->Salt.isEmpty())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -509,9 +509,9 @@ QSystemTrayIcon* Utils::GetTrayIcon() {
|
|||||||
return reinterpret_cast<QSystemTrayIcon*>(systemTray);
|
return reinterpret_cast<QSystemTrayIcon*>(systemTray);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Utils::SysTrayNotify(QString text,
|
void Utils::SysTrayNotify(QString text, QSystemTrayIcon::MessageIcon icon, QString title) {
|
||||||
QSystemTrayIcon::MessageIcon icon, QString title) {
|
auto config = GetConfig();
|
||||||
if (!GetConfig()->AlertsEnabled ||
|
if ((config && !config->AlertsEnabled) ||
|
||||||
!QSystemTrayIcon::isSystemTrayAvailable() ||
|
!QSystemTrayIcon::isSystemTrayAvailable() ||
|
||||||
!QSystemTrayIcon::supportsMessages())
|
!QSystemTrayIcon::supportsMessages())
|
||||||
{
|
{
|
||||||
|
@ -194,7 +194,8 @@ WSRequestHandler::WSRequestHandler(ConnectionProperties& connProperties) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
RpcResponse WSRequestHandler::processRequest(const RpcRequest& request) {
|
RpcResponse WSRequestHandler::processRequest(const RpcRequest& request) {
|
||||||
if (GetConfig()->AuthRequired
|
auto config = GetConfig();
|
||||||
|
if ((config && config->AuthRequired)
|
||||||
&& (!authNotRequired.contains(request.methodName()))
|
&& (!authNotRequired.contains(request.methodName()))
|
||||||
&& (!_connProperties.isAuthenticated()))
|
&& (!_connProperties.isAuthenticated()))
|
||||||
{
|
{
|
||||||
|
@ -115,13 +115,13 @@ RpcResponse WSRequestHandler::GetVersion(const RpcRequest& request) {
|
|||||||
* @since 0.3
|
* @since 0.3
|
||||||
*/
|
*/
|
||||||
RpcResponse WSRequestHandler::GetAuthRequired(const RpcRequest& request) {
|
RpcResponse WSRequestHandler::GetAuthRequired(const RpcRequest& request) {
|
||||||
bool authRequired = GetConfig()->AuthRequired;
|
auto config = GetConfig();
|
||||||
|
bool authRequired = (config && config->AuthRequired);
|
||||||
|
|
||||||
OBSDataAutoRelease data = obs_data_create();
|
OBSDataAutoRelease data = obs_data_create();
|
||||||
obs_data_set_bool(data, "authRequired", authRequired);
|
obs_data_set_bool(data, "authRequired", authRequired);
|
||||||
|
|
||||||
if (authRequired) {
|
if (authRequired) {
|
||||||
auto config = GetConfig();
|
|
||||||
obs_data_set_string(data, "challenge",
|
obs_data_set_string(data, "challenge",
|
||||||
config->SessionChallenge.toUtf8());
|
config->SessionChallenge.toUtf8());
|
||||||
obs_data_set_string(data, "salt",
|
obs_data_set_string(data, "salt",
|
||||||
@ -155,7 +155,8 @@ RpcResponse WSRequestHandler::Authenticate(const RpcRequest& request) {
|
|||||||
return request.failed("auth not specified!");
|
return request.failed("auth not specified!");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GetConfig()->CheckAuth(auth) == false) {
|
auto config = GetConfig();
|
||||||
|
if (!config || (config->CheckAuth(auth) == false)) {
|
||||||
return request.failed("Authentication Failed.");
|
return request.failed("Authentication Failed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,13 +135,14 @@ void WSServer::broadcast(const RpcEvent& event)
|
|||||||
{
|
{
|
||||||
std::string message = OBSRemoteProtocol::encodeEvent(event);
|
std::string message = OBSRemoteProtocol::encodeEvent(event);
|
||||||
|
|
||||||
if (GetConfig()->DebugEnabled) {
|
auto config = GetConfig();
|
||||||
|
if (config && config->DebugEnabled) {
|
||||||
blog(LOG_INFO, "Update << '%s'", message.c_str());
|
blog(LOG_INFO, "Update << '%s'", message.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
QMutexLocker locker(&_clMutex);
|
QMutexLocker locker(&_clMutex);
|
||||||
for (connection_hdl hdl : _connections) {
|
for (connection_hdl hdl : _connections) {
|
||||||
if (GetConfig()->AuthRequired) {
|
if (config && config->AuthRequired) {
|
||||||
bool authenticated = _connectionProperties[hdl].isAuthenticated();
|
bool authenticated = _connectionProperties[hdl].isAuthenticated();
|
||||||
if (!authenticated) {
|
if (!authenticated) {
|
||||||
continue;
|
continue;
|
||||||
@ -184,14 +185,15 @@ void WSServer::onMessage(connection_hdl hdl, server::message_ptr message)
|
|||||||
ConnectionProperties& connProperties = _connectionProperties[hdl];
|
ConnectionProperties& connProperties = _connectionProperties[hdl];
|
||||||
locker.unlock();
|
locker.unlock();
|
||||||
|
|
||||||
if (GetConfig()->DebugEnabled) {
|
auto config = GetConfig();
|
||||||
|
if (config && config->DebugEnabled) {
|
||||||
blog(LOG_INFO, "Request >> '%s'", payload.c_str());
|
blog(LOG_INFO, "Request >> '%s'", payload.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
WSRequestHandler requestHandler(connProperties);
|
WSRequestHandler requestHandler(connProperties);
|
||||||
std::string response = OBSRemoteProtocol::processMessage(requestHandler, payload);
|
std::string response = OBSRemoteProtocol::processMessage(requestHandler, payload);
|
||||||
|
|
||||||
if (GetConfig()->DebugEnabled) {
|
if (config && config->DebugEnabled) {
|
||||||
blog(LOG_INFO, "Response << '%s'", response.c_str());
|
blog(LOG_INFO, "Response << '%s'", response.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,17 +43,18 @@ SettingsDialog::SettingsDialog(QWidget* parent) :
|
|||||||
|
|
||||||
void SettingsDialog::showEvent(QShowEvent* event) {
|
void SettingsDialog::showEvent(QShowEvent* event) {
|
||||||
auto conf = GetConfig();
|
auto conf = GetConfig();
|
||||||
|
if (conf) {
|
||||||
|
ui->serverEnabled->setChecked(conf->ServerEnabled);
|
||||||
|
ui->serverPort->setValue(conf->ServerPort);
|
||||||
|
ui->lockToIPv4->setChecked(conf->LockToIPv4);
|
||||||
|
|
||||||
ui->serverEnabled->setChecked(conf->ServerEnabled);
|
ui->debugEnabled->setChecked(conf->DebugEnabled);
|
||||||
ui->serverPort->setValue(conf->ServerPort);
|
ui->alertsEnabled->setChecked(conf->AlertsEnabled);
|
||||||
ui->lockToIPv4->setChecked(conf->LockToIPv4);
|
|
||||||
|
|
||||||
ui->debugEnabled->setChecked(conf->DebugEnabled);
|
ui->authRequired->blockSignals(true);
|
||||||
ui->alertsEnabled->setChecked(conf->AlertsEnabled);
|
ui->authRequired->setChecked(conf->AuthRequired);
|
||||||
|
ui->authRequired->blockSignals(false);
|
||||||
ui->authRequired->blockSignals(true);
|
}
|
||||||
ui->authRequired->setChecked(conf->AuthRequired);
|
|
||||||
ui->authRequired->blockSignals(false);
|
|
||||||
|
|
||||||
ui->password->setText(CHANGE_ME);
|
ui->password->setText(CHANGE_ME);
|
||||||
ui->password->setEnabled(ui->authRequired->isChecked());
|
ui->password->setEnabled(ui->authRequired->isChecked());
|
||||||
@ -94,6 +95,9 @@ void SettingsDialog::AuthCheckboxChanged() {
|
|||||||
|
|
||||||
void SettingsDialog::FormAccepted() {
|
void SettingsDialog::FormAccepted() {
|
||||||
auto conf = GetConfig();
|
auto conf = GetConfig();
|
||||||
|
if (!conf) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
conf->ServerEnabled = ui->serverEnabled->isChecked();
|
conf->ServerEnabled = ui->serverEnabled->isChecked();
|
||||||
conf->ServerPort = ui->serverPort->value();
|
conf->ServerPort = ui->serverPort->value();
|
||||||
@ -107,7 +111,7 @@ void SettingsDialog::FormAccepted() {
|
|||||||
conf->SetPassword(ui->password->text());
|
conf->SetPassword(ui->password->text());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!GetConfig()->Secret.isEmpty())
|
if (!conf->Secret.isEmpty())
|
||||||
conf->AuthRequired = true;
|
conf->AuthRequired = true;
|
||||||
else
|
else
|
||||||
conf->AuthRequired = false;
|
conf->AuthRequired = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user