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
|
||||
auto config = GetConfig();
|
||||
if (!config) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(config->Secret.isEmpty()) && !(config->Salt.isEmpty())) {
|
||||
return;
|
||||
}
|
||||
|
@ -509,9 +509,9 @@ QSystemTrayIcon* Utils::GetTrayIcon() {
|
||||
return reinterpret_cast<QSystemTrayIcon*>(systemTray);
|
||||
}
|
||||
|
||||
void Utils::SysTrayNotify(QString text,
|
||||
QSystemTrayIcon::MessageIcon icon, QString title) {
|
||||
if (!GetConfig()->AlertsEnabled ||
|
||||
void Utils::SysTrayNotify(QString text, QSystemTrayIcon::MessageIcon icon, QString title) {
|
||||
auto config = GetConfig();
|
||||
if ((config && !config->AlertsEnabled) ||
|
||||
!QSystemTrayIcon::isSystemTrayAvailable() ||
|
||||
!QSystemTrayIcon::supportsMessages())
|
||||
{
|
||||
|
@ -194,7 +194,8 @@ WSRequestHandler::WSRequestHandler(ConnectionProperties& connProperties) :
|
||||
}
|
||||
|
||||
RpcResponse WSRequestHandler::processRequest(const RpcRequest& request) {
|
||||
if (GetConfig()->AuthRequired
|
||||
auto config = GetConfig();
|
||||
if ((config && config->AuthRequired)
|
||||
&& (!authNotRequired.contains(request.methodName()))
|
||||
&& (!_connProperties.isAuthenticated()))
|
||||
{
|
||||
|
@ -115,13 +115,13 @@ RpcResponse WSRequestHandler::GetVersion(const RpcRequest& request) {
|
||||
* @since 0.3
|
||||
*/
|
||||
RpcResponse WSRequestHandler::GetAuthRequired(const RpcRequest& request) {
|
||||
bool authRequired = GetConfig()->AuthRequired;
|
||||
auto config = GetConfig();
|
||||
bool authRequired = (config && config->AuthRequired);
|
||||
|
||||
OBSDataAutoRelease data = obs_data_create();
|
||||
obs_data_set_bool(data, "authRequired", authRequired);
|
||||
|
||||
if (authRequired) {
|
||||
auto config = GetConfig();
|
||||
obs_data_set_string(data, "challenge",
|
||||
config->SessionChallenge.toUtf8());
|
||||
obs_data_set_string(data, "salt",
|
||||
@ -155,7 +155,8 @@ RpcResponse WSRequestHandler::Authenticate(const RpcRequest& request) {
|
||||
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.");
|
||||
}
|
||||
|
||||
|
@ -135,13 +135,14 @@ void WSServer::broadcast(const RpcEvent& 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());
|
||||
}
|
||||
|
||||
QMutexLocker locker(&_clMutex);
|
||||
for (connection_hdl hdl : _connections) {
|
||||
if (GetConfig()->AuthRequired) {
|
||||
if (config && config->AuthRequired) {
|
||||
bool authenticated = _connectionProperties[hdl].isAuthenticated();
|
||||
if (!authenticated) {
|
||||
continue;
|
||||
@ -184,14 +185,15 @@ void WSServer::onMessage(connection_hdl hdl, server::message_ptr message)
|
||||
ConnectionProperties& connProperties = _connectionProperties[hdl];
|
||||
locker.unlock();
|
||||
|
||||
if (GetConfig()->DebugEnabled) {
|
||||
auto config = GetConfig();
|
||||
if (config && config->DebugEnabled) {
|
||||
blog(LOG_INFO, "Request >> '%s'", payload.c_str());
|
||||
}
|
||||
|
||||
WSRequestHandler requestHandler(connProperties);
|
||||
std::string response = OBSRemoteProtocol::processMessage(requestHandler, payload);
|
||||
|
||||
if (GetConfig()->DebugEnabled) {
|
||||
if (config && config->DebugEnabled) {
|
||||
blog(LOG_INFO, "Response << '%s'", response.c_str());
|
||||
}
|
||||
|
||||
|
@ -43,17 +43,18 @@ SettingsDialog::SettingsDialog(QWidget* parent) :
|
||||
|
||||
void SettingsDialog::showEvent(QShowEvent* event) {
|
||||
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->serverPort->setValue(conf->ServerPort);
|
||||
ui->lockToIPv4->setChecked(conf->LockToIPv4);
|
||||
ui->debugEnabled->setChecked(conf->DebugEnabled);
|
||||
ui->alertsEnabled->setChecked(conf->AlertsEnabled);
|
||||
|
||||
ui->debugEnabled->setChecked(conf->DebugEnabled);
|
||||
ui->alertsEnabled->setChecked(conf->AlertsEnabled);
|
||||
|
||||
ui->authRequired->blockSignals(true);
|
||||
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->setEnabled(ui->authRequired->isChecked());
|
||||
@ -94,6 +95,9 @@ void SettingsDialog::AuthCheckboxChanged() {
|
||||
|
||||
void SettingsDialog::FormAccepted() {
|
||||
auto conf = GetConfig();
|
||||
if (!conf) {
|
||||
return;
|
||||
}
|
||||
|
||||
conf->ServerEnabled = ui->serverEnabled->isChecked();
|
||||
conf->ServerPort = ui->serverPort->value();
|
||||
@ -107,7 +111,7 @@ void SettingsDialog::FormAccepted() {
|
||||
conf->SetPassword(ui->password->text());
|
||||
}
|
||||
|
||||
if (!GetConfig()->Secret.isEmpty())
|
||||
if (!conf->Secret.isEmpty())
|
||||
conf->AuthRequired = true;
|
||||
else
|
||||
conf->AuthRequired = false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user