Skip to content
This repository was archived by the owner on Aug 7, 2025. It is now read-only.

Commit ba9649e

Browse files
William Douglasbryteise
authored andcommitted
Handle errors from statedir_set_*_path
In the case of the system default paths being set, potential errors from state_set_*_path functions were being ignored. Handle errors and exit accordingly. Previously the directories were not attempted to be created in this code path so there was no error handling needed but with the mkdir addition, no longer handling this erro will cause segfaults later on as the mkdir failure prevents the path setting further causing uninitalized variables to be used. Signed-off-by: William Douglas <[email protected]>
1 parent 65d8d02 commit ba9649e

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/swupd_lib/globals.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,18 +198,28 @@ static void set_default_state_dir_cache(void)
198198
globals.state_dir_cache = NULL;
199199
}
200200

201-
static void set_default_cache_dir(void)
201+
static bool set_default_cache_dir(void)
202202
{
203-
(void)statedir_set_cache_path(STATE_DIR);
203+
if (!statedir_set_cache_path(STATE_DIR)) {
204+
error("Unable to set default cache dir '%s'\n", STATE_DIR);
205+
return false;
206+
}
207+
208+
return true;
204209
}
205210

206-
static void set_default_data_dir(void)
211+
static bool set_default_data_dir(void)
207212
{
213+
bool ret;
208214
char *default_data_dir = NULL;
209215

210216
default_data_dir = sys_path_join("%s/%s", globals.path_prefix, STATE_DIR);
211-
(void)statedir_set_data_path(default_data_dir);
217+
ret = statedir_set_data_path(default_data_dir);
218+
if (!ret) {
219+
error("Unable to set default data dir '%s'\n", default_data_dir);
220+
}
212221
FREE(default_data_dir);
222+
return ret;
213223
}
214224

215225
static bool set_format_string(char *format)
@@ -400,13 +410,17 @@ bool globals_init(void)
400410
}
401411

402412
if (!globals.cache_dir) {
403-
set_default_cache_dir();
413+
if (!set_default_cache_dir()) {
414+
return false;
415+
}
404416
}
405417

406418
// data_dir is relative to the path_prefix so ALWAYS has to run after
407419
// initializing path_prefix
408420
if (!globals.data_dir) {
409-
set_default_data_dir();
421+
if (!set_default_data_dir()) {
422+
return false;
423+
}
410424
}
411425

412426
if (!globals.format_string && !set_default_format_string()) {

0 commit comments

Comments
 (0)