Skip to content

Commit c084d1f

Browse files
author
Bernd Eckenfels
committed
Prevent overflow in ax25 and netrom
Fixes sourceforge #48 Thanks to Bernard Pidoux.
1 parent 0a30b88 commit c084d1f

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

lib/ax25.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ static char AX25_errmsg[128];
4747

4848
extern struct aftype ax25_aftype;
4949

50+
// align with NETROM_orint
5051
static const char *AX25_print(const char *ptr)
5152
{
52-
static char buff[8];
53+
static char buff[10]; // N0CALL-15
5354
int i;
5455

5556
for (i = 0; i < 6; i++) {
@@ -58,9 +59,14 @@ static const char *AX25_print(const char *ptr)
5859
buff[i] = '\0';
5960
}
6061
buff[6] = '\0';
62+
63+
// add SSID
6164
i = ((ptr[6] & 0x1E) >> 1);
62-
if (i != 0)
63-
sprintf(&buff[strlen(buff)], "-%d", i);
65+
if (i != 0) {
66+
int l = strlen(buff);
67+
sprintf(&buff[l], sizeof(buff)-l, "-%d", i);
68+
}
69+
6470
return (buff);
6571
}
6672

lib/netrom.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ extern struct aftype netrom_aftype;
5454

5555
static const char *NETROM_print(const char *ptr)
5656
{
57-
static char buff[8];
57+
static char buff[10]; // N0CALL-15\0
5858
int i;
5959

6060
for (i = 0; i < 6; i++) {
@@ -63,9 +63,15 @@ static const char *NETROM_print(const char *ptr)
6363
buff[i] = '\0';
6464
}
6565
buff[6] = '\0';
66+
67+
// add SSID
6668
i = ((ptr[6] & 0x1E) >> 1);
6769
if (i != 0)
68-
sprintf(&buff[strlen(buff)], "-%d", i);
70+
{
71+
int l = strlen(buff); // 0-6
72+
snprintf(&buff[l],sizeof(buff)-l, "-%d", i);
73+
}
74+
6975
return (buff);
7076
}
7177

0 commit comments

Comments
 (0)