]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
installer: Replace all uses of strncpy with snprintf
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 5 Apr 2024 12:59:39 +0000 (12:59 +0000)
committerArne Fitzenreiter <arne_f@ipfire.org>
Fri, 19 Apr 2024 06:04:59 +0000 (06:04 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Signed-off-by: Arne Fitzenreiter <arne_f@ipfire.org>
src/installer/hw.c
src/installer/main.c

index 809a448a017189372bb6a34b8a2fb0998f4da868..6bf05b185a6fd509783fba0e694ed867045fdd98 100644 (file)
@@ -324,6 +324,7 @@ static unsigned long long hw_block_device_get_size(const char* dev) {
 struct hw_disk** hw_find_disks(struct hw* hw, const char* sourcedrive) {
        struct hw_disk** ret = hw_create_disks();
        struct hw_disk** disks = ret;
+       char size_str[32];
 
        // Determine the disk device of source if it is a partition
        const char* sourcedisk = NULL;
@@ -388,7 +389,7 @@ struct hw_disk** hw_find_disks(struct hw* hw, const char* sourcedrive) {
 
                disk->ref = 1;
 
-               strncpy(disk->path, dev_path, sizeof(disk->path));
+               snprintf(disk->path, sizeof(disk->path), "%s", dev_path);
                const char* p = disk->path + 5;
 
                disk->size = size;
@@ -401,7 +402,7 @@ struct hw_disk** hw_find_disks(struct hw* hw, const char* sourcedrive) {
                        vendor = udev_device_get_sysattr_value(dev, "manufacturer");
 
                if (vendor)
-                       strncpy(disk->vendor, vendor, sizeof(disk->vendor));
+                       snprintf(disk->vendor, sizeof(disk->vendor), "%s", vendor);
                else
                        *disk->vendor = '\0';
 
@@ -413,12 +414,11 @@ struct hw_disk** hw_find_disks(struct hw* hw, const char* sourcedrive) {
                        model = udev_device_get_sysattr_value(dev, "product");
 
                if (model)
-                       strncpy(disk->model, model, sizeof(disk->model));
+                       snprintf(disk->model, sizeof(disk->model), "%s", model);
                else
                        *disk->model = '\0';
 
                // Format description
-               char size_str[STRING_SIZE];
                snprintf(size_str, sizeof(size_str), "%4.1fGB", (double)disk->size / pow(1024, 3));
 
                if (*disk->vendor && *disk->model) {
index 20a8cc9623162e86b8d6a7594ca5502265f6cc4c..ecfcff2ecc5b085a28fbd43b7bd530fedaaff82c 100644 (file)
@@ -310,7 +310,8 @@ static void parse_command_line(FILE* flog, struct config* c) {
 
                char* token = strtok(cmdline, " ");
                while (token) {
-                       strncpy(buffer, token, sizeof(buffer));
+                       snprintf(buffer, sizeof(buffer), "%s", token);
+
                        char* val = buffer;
                        char* key = strsep(&val, "=");
 
@@ -336,7 +337,7 @@ static void parse_command_line(FILE* flog, struct config* c) {
 
                        // download url
                        else if (strcmp(key, "installer.download-url") == 0) {
-                               strncpy(c->download_url, val, sizeof(c->download_url));
+                               snprintf(c->download_url, sizeof(c->download_url), "%s", val);
                                c->perform_download = 1;
 
                                // Require networking for the download
@@ -344,7 +345,7 @@ static void parse_command_line(FILE* flog, struct config* c) {
 
                        // postinstall script
                        } else if (strcmp(key, "installer.postinstall") == 0) {
-                               strncpy(c->postinstall, val, sizeof(c->postinstall));
+                               snprintf(c->postinstall, sizeof(c->postinstall), "%s", val);
 
                                // Require networking for the download
                                c->require_networking = 1;