pespin submitted this change.
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(-)
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 change 30942. To unsubscribe, or for help writing mail filters, visit settings.