From: Hongbo Zhang <[email protected]>

This is for https://bugs.linaro.org/show_bug.cgi?id=2030:
"Memory - illegal accesses  (BUFFER_SIZE_WARNING)
Calling strncpy with a maximum size argument of 128 bytes on destination
array "sysinfo->model_str[id]" of size 128 bytes might leave the
destination string unterminated."

In fact in the following code there is operation like this:
sysinfo->model_str[id][len - 1] = 0
to handle the last character of string, but is is also good to eliminate
this coding warning.

Signed-off-by: Hongbo Zhang <[email protected]>
---
 platform/linux-generic/arch/mips64/odp_sysinfo_parse.c  | 2 +-
 platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c | 2 +-
 platform/linux-generic/arch/x86/odp_sysinfo_parse.c     | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c 
b/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c
index 53074f7..d45b420 100644
--- a/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c
+++ b/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c
@@ -39,7 +39,7 @@ int odp_cpuinfo_parser(FILE *file, odp_system_info_t *sysinfo)
 
                                pos = strchr(str, ':');
                                strncpy(sysinfo->model_str[id], pos + 2,
-                                       sizeof(sysinfo->model_str[id]));
+                                       sizeof(sysinfo->model_str[id]) - 1);
                                len = strlen(sysinfo->model_str[id]);
                                sysinfo->model_str[id][len - 1] = 0;
                                model = 1;
diff --git a/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c 
b/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c
index 99457ce..95200ee 100644
--- a/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c
+++ b/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c
@@ -38,7 +38,7 @@ int odp_cpuinfo_parser(FILE *file, odp_system_info_t *sysinfo)
 
                                pos = strchr(str, ':');
                                strncpy(sysinfo->model_str[id], pos + 2,
-                                       sizeof(sysinfo->model_str[id]));
+                                       sizeof(sysinfo->model_str[id]) - 1);
                                len = strlen(sysinfo->model_str[id]);
                                sysinfo->model_str[id][len - 1] = 0;
                                model = 1;
diff --git a/platform/linux-generic/arch/x86/odp_sysinfo_parse.c 
b/platform/linux-generic/arch/x86/odp_sysinfo_parse.c
index 816629d..2ef49e4 100644
--- a/platform/linux-generic/arch/x86/odp_sysinfo_parse.c
+++ b/platform/linux-generic/arch/x86/odp_sysinfo_parse.c
@@ -21,7 +21,7 @@ int odp_cpuinfo_parser(FILE *file, odp_system_info_t *sysinfo)
                if (pos) {
                        pos = strchr(str, ':');
                        strncpy(sysinfo->model_str[id], pos + 2,
-                               sizeof(sysinfo->model_str[id]));
+                               sizeof(sysinfo->model_str[id]) - 1);
 
                        pos = strchr(sysinfo->model_str[id], '@');
                        *(pos - 1) = '\0';
-- 
2.1.4

_______________________________________________
lng-odp mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to