aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2022-06-01 14:11:27 +0200
committerDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2022-07-26 17:30:21 +0200
commit5d4cf4d445b2829deac9c755f65c98151eabc157 (patch)
tree587a327d5b50ea530558f098fdf8d82d5043fb46
parent33a2edba55ef60a14b41fafc1bfe7467e548a443 (diff)
downloadhardware_replicant_libsamsung-ipc-5d4cf4d445b2829deac9c755f65c98151eabc157.tar.gz
hardware_replicant_libsamsung-ipc-5d4cf4d445b2829deac9c755f65c98151eabc157.tar.bz2
hardware_replicant_libsamsung-ipc-5d4cf4d445b2829deac9c755f65c98151eabc157.zip
gprs: ipc_gprs_define_pdp_context_setup: fix truncated string
Without that fix, when compiling libsamsung-ipc with --enable-strict-cflags, we have the following error: gprs.c: In function 'ipc_gprs_define_pdp_context_setup': gprs.c:38:9: error: 'strncpy' specified bound 124 equals destination size [-Werror=stringop-truncation] 38 | strncpy((char *) data->apn, apn, sizeof(data->apn)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ It comes from the fact that the size of data->apn is fixed (to 124) in include/gprs.h: struct ipc_gprs_define_pdp_context_data { unsigned char enable; unsigned char cid; unsigned char magic; unsigned char apn[124]; } __attribute__((__packed__)); The issue is that in ipc_gprs_define_pdp_context_setup we had the following code: int ipc_gprs_define_pdp_context_setup( struct ipc_gprs_define_pdp_context_data *data, unsigned char enable, unsigned char cid, const char *apn) { [...] strncpy((char *) data->apn, apn, sizeof(data->apn)); [...] return 0; } And in the strcpy(3) manual we have: The strncpy() function is similar, except that at most n bytes of src are copied. Warning: If there is no null byte among the first n bytes of src, the string placed in dest will not be null-terminated. So if we have an apn of 124 or more characters, the copied data will not be null terminated hence the warning. Since apn is a character array and not a string, and that the field is padded with zeros anyway we can use memcpy instead. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
-rw-r--r--samsung-ipc/gprs.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/samsung-ipc/gprs.c b/samsung-ipc/gprs.c
index 89f06e7..64d94f9 100644
--- a/samsung-ipc/gprs.c
+++ b/samsung-ipc/gprs.c
@@ -35,7 +35,7 @@ int ipc_gprs_define_pdp_context_setup(
data->cid = cid;
data->magic = 0x02;
- strncpy((char *) data->apn, apn, sizeof(data->apn));
+ memcpy(data->apn, apn, sizeof(data->apn));
return 0;
}