pespin has submitted this change. ( 
https://gerrit.osmocom.org/c/osmocom-bb/+/30942 )

Change subject: layer23: Fix gcc warning sprintf() writing on too short buf
......................................................................

layer23: Fix gcc warning sprintf() writing on too short buf

Triggered with gcc 12.2.0:
/osmocom-bb/src/host/layer23/src/common/sysinfo.c: In function 
‘gsm48_sysinfo_dump’:
/osmocom-bb/src/host/layer23/src/common/sysinfo.c:198:42: warning: ‘sprintf’ 
may write a terminating nul past the end of the destination [-Wformat-overflow=]
  198 |                 sprintf(buffer + 69, " %d", i + 63);
      |                                          ^
/osmocom-bb/src/host/layer23/src/common/sysinfo.c:198:17: note: ‘sprintf’ 
output between 3 and 13 bytes into a destination of size 12
  198 |                 sprintf(buffer + 69, " %d", i + 63);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Change-Id: I29a64fbb7aca0d1b469b6d278d4a24ddc6f57b3a
---
M src/host/layer23/src/common/sysinfo.c
1 file changed, 3 insertions(+), 3 deletions(-)

Approvals:
  laforge: Looks good to me, but someone else must approve
  fixeria: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/host/layer23/src/common/sysinfo.c 
b/src/host/layer23/src/common/sysinfo.c
index 392cdc3..be4e84b 100644
--- a/src/host/layer23/src/common/sysinfo.c
+++ b/src/host/layer23/src/common/sysinfo.c
@@ -68,7 +68,7 @@
                       void (*print)(void *, const char *, ...),
                       void *priv, uint8_t *freq_map)
 {
-       char buffer[81];
+       char buffer[82];
        int i, j, k, index;
        int refer_pcs = gsm_refer_pcs(arfcn, s);

@@ -173,7 +173,7 @@

        /* frequency map */
        for (i = 0; i < 1024; i += 64) {
-               sprintf(buffer, " %3d ", i);
+               snprintf(buffer, sizeof(buffer), " %3d ", i);
                for (j = 0; j < 64; j++) {
                        index = i+j;
                        if (refer_pcs && index >= 512 && index <= 885)
@@ -195,7 +195,7 @@
                }
                for (; j < 64; j++)
                        buffer[j + 5] = ' ';
-               sprintf(buffer + 69, " %d", i + 63);
+               snprintf(buffer + 69, sizeof(buffer) - 69, " %d", i + 63);
                print(priv, "%s\n", buffer);
        }
        print(priv, " 'S' = serv. cell  'n' = SI2 (neigh.)  'r' = SI5 (rep.)  "

--
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/30942
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: I29a64fbb7aca0d1b469b6d278d4a24ddc6f57b3a
Gerrit-Change-Number: 30942
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <pes...@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanits...@sysmocom.de>
Gerrit-Reviewer: laforge <lafo...@osmocom.org>
Gerrit-Reviewer: pespin <pes...@sysmocom.de>
Gerrit-MessageType: merged

Reply via email to