From aee8d777fcbf83590a6a03e42f048a62081d2b7c Mon Sep 17 00:00:00 2001 From: Martin Riedel Date: Fri, 7 Jul 2023 16:30:02 -0400 Subject: [PATCH] fixed root cause of GDrive config parsing crash --- src/cfg.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/cfg.cpp b/src/cfg.cpp index f217aca..a00705a 100644 --- a/src/cfg.cpp +++ b/src/cfg.cpp @@ -309,15 +309,20 @@ static void loadDriveConfig() if(!clientSecretPath.empty()) { - json_object *installed, *clientID, *clientSecret,*driveJSON = json_object_from_file(clientSecretPath.c_str()); - json_object_object_get_ex(driveJSON, "installed", &installed); - json_object_object_get_ex(installed, "client_id", &clientID); - json_object_object_get_ex(installed, "client_secret", &clientSecret); - - cfg::driveClientID = json_object_get_string(clientID); - cfg::driveClientSecret = json_object_get_string(clientSecret); - - json_object_put(driveJSON); + json_object *installed, *clientID, *clientSecret, *driveJSON = json_object_from_file(clientSecretPath.c_str()); + if (driveJSON) + { + if(json_object_object_get_ex(driveJSON, "installed", &installed)) + { + if(json_object_object_get_ex(installed, "client_id", &clientID) + && json_object_object_get_ex(installed, "client_secret", &clientSecret)) + { + cfg::driveClientID = json_object_get_string(clientID); + cfg::driveClientSecret = json_object_get_string(clientSecret); + } + } + json_object_put(driveJSON); + } } }