[PATCH] openbsc[master]: ipaccess-config: properly create swload

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Wed Mar 8 17:36:21 UTC 2017


Review at  https://gerrit.osmocom.org/2018

ipaccess-config: properly create swload

Instead of 20, use the actual buffer sizes of struct sw_load, which are 255.
Previous code would truncate a longer string at 20 without(!) NUL termination.

In the _len members, store the actual length copied. In previous code, if the
source string were longer than 20, we would store only 20 (without NUL term)
but still reflect the longer length of the source string.

Fix both of these issues for sw_load.file_id / file_id_len and
sw_load.file_version / file_version_len.

Change-Id: I2e34a1348a290d3f58dd830d08da65b94b3270db
---
M openbsc/src/ipaccess/ipaccess-config.c
1 file changed, 6 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/openbsc refs/changes/18/2018/1

diff --git a/openbsc/src/ipaccess/ipaccess-config.c b/openbsc/src/ipaccess/ipaccess-config.c
index 0c3f888..a741836 100644
--- a/openbsc/src/ipaccess/ipaccess-config.c
+++ b/openbsc/src/ipaccess/ipaccess-config.c
@@ -624,11 +624,13 @@
 
 	load = talloc_zero(tall_ctx_config, struct sw_load);
 
-	strncpy((char *)load->file_id, header->firmware_info.sw_part, 20);
-	load->file_id_len = strlen(header->firmware_info.sw_part) + 1;
+	osmo_strlcpy((char *)load->file_id, header->firmware_info.sw_part,
+		     sizeof(load->file_id));
+	load->file_id_len = strlen((char*)load->file_id) + 1;
 
-	strncpy((char *)load->file_version, header->firmware_info.version, 20);
-	load->file_version_len = strlen(header->firmware_info.version) + 1;
+	osmo_strlcpy((char *)load->file_version, header->firmware_info.version,
+		     sizeof(load->file_version));
+	load->file_version_len = strlen((char*)load->file_version) + 1;
 
 	return load;
 }

-- 
To view, visit https://gerrit.osmocom.org/2018
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2e34a1348a290d3f58dd830d08da65b94b3270db
Gerrit-PatchSet: 1
Gerrit-Project: openbsc
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list