]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
fix allocation issues config
authorBastian Dehn <hhaalo@arcor.de>
Sat, 11 Oct 2025 10:14:09 +0000 (12:14 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 11 Oct 2025 10:14:09 +0000 (12:14 +0200)
src/kds_s2000w_config.c
src/kds_s2000w_handler.c

index 96ffe76640eb3db5d7d2c0f1e0678f0649ddb66c..f3fc756ee859c34f441aa2e9b4165ecf80b89a61 100644 (file)
@@ -13,6 +13,8 @@
 program_config* _kds_s2000w_config_init()
 {
        program_config* config = malloc(sizeof(program_config));
+       if (config == NULL)
+               return NULL;
 
        config->scanner_url = malloc(sizeof(char));
        config->username = malloc(sizeof(char));
@@ -31,15 +33,16 @@ char* _kds_s2000w_config_copy_config_string(cfg_t* cfg, const char* key)
        char* value_str = cfg_getstr(cfg, key);
        size_t length = strlen(value_str) + 1;
        char* new_str = malloc(sizeof(char) * length);
-       new_str = strncpy(new_str, value_str, length);
+       if (new_str == NULL)
+               return NULL;
 
+       new_str = strncpy(new_str, value_str, length);
        return new_str;
 }
 
 char* kds_s2000w_config_read(const char* filename)
 {
        FILE* config_file = fopen(filename, "r");
-
        if (config_file == NULL)
                return NULL;
 
@@ -48,6 +51,11 @@ char* kds_s2000w_config_read(const char* filename)
        rewind(config_file);
 
        char* config_string = malloc(sizeof(char) * config_size + 1);
+       if (config_string == NULL) {
+               fclose(config_file);
+               return NULL;
+       }
+
        fread(config_string, config_size, 1, config_file);
        config_string[config_size] = '\0';
 
@@ -60,6 +68,8 @@ char* kds_s2000w_config_read(const char* filename)
 program_config* kds_s2000w_config_load(char* config_string)
 {
        program_config* config = _kds_s2000w_config_init();
+       if (config == NULL)
+               return NULL;
 
        if (config_string == NULL)
                return config;
index 7b4c4793e93d3ab8bca3b6d2efbfc6d11e29d658..67897a84df780cb1e0211e1dc0eb19f8427d835f 100644 (file)
@@ -42,7 +42,12 @@ void _kds_s2000w_handler_load_config(handler* h)
        kds_s2000w_debug_printf(ALL, "kds_s2000w_handler_load_config");
 
        char* config_stream = kds_s2000w_config_read(CONFIG_FILE);
+       if (config_stream == NULL)
+               return;
+
        program_config* config = kds_s2000w_config_load(config_stream);
+       if (config == NULL)
+               return;
 
        kds_s2000w_client_init(config->scanner_url,
                config->username,