From patchwork Fri Apr 5 12:59:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tremer X-Patchwork-Id: 7712 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4V9z9Z2GNpz3wws for ; Fri, 5 Apr 2024 13:00:18 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4V9z9G0bbWz65L; Fri, 5 Apr 2024 13:00:02 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4V9z9F6HnQz32lr; Fri, 5 Apr 2024 13:00:01 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4V9z914Gcvz32jQ for ; Fri, 5 Apr 2024 12:59:49 +0000 (UTC) Received: from michael.haj.ipfire.org (michael.haj.ipfire.org [172.28.1.242]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "michael.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4V9z905vtHz5ST; Fri, 5 Apr 2024 12:59:48 +0000 (UTC) Received: by michael.haj.ipfire.org (Postfix, from userid 0) id 4V9z8x4QBCzTvm0; Fri, 5 Apr 2024 12:59:45 +0000 (UTC) From: Michael Tremer To: development@lists.ipfire.org Subject: [PATCH 10/13] installer: Replace all uses of strncpy with snprintf Date: Fri, 5 Apr 2024 12:59:39 +0000 Message-Id: <20240405125942.1803058-10-michael.tremer@ipfire.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240405125942.1803058-1-michael.tremer@ipfire.org> References: <20240405125942.1803058-1-michael.tremer@ipfire.org> MIME-Version: 1.0 Message-ID-Hash: AO6GKRWB5SRUV3GI3HRNFURJ4DHISYQB X-Message-ID-Hash: AO6GKRWB5SRUV3GI3HRNFURJ4DHISYQB X-MailFrom: root@michael.haj.ipfire.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Michael Tremer X-Mailman-Version: 3.3.8 Precedence: list List-Id: IPFire development talk Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Signed-off-by: Michael Tremer --- src/installer/hw.c | 8 ++++---- src/installer/main.c | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/installer/hw.c b/src/installer/hw.c index 809a448a0..6bf05b185 100644 --- a/src/installer/hw.c +++ b/src/installer/hw.c @@ -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) { diff --git a/src/installer/main.c b/src/installer/main.c index 20a8cc962..ecfcff2ec 100644 --- a/src/installer/main.c +++ b/src/installer/main.c @@ -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;