Skip to content

Commit 89029db

Browse files
committedOct 22, 2024
More error checking.
1 parent 73943ed commit 89029db

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed
 

‎src/decode_aprs.c

+17-3
Original file line numberDiff line numberDiff line change
@@ -1428,7 +1428,7 @@ static void aprs_mic_e (decode_aprs_t *A, packet_t pp, unsigned char *info, int
14281428
}
14291429
return;
14301430
}
1431-
info[ilen] = '\0';\
1431+
info[ilen] = '\0';
14321432

14331433
p = (struct aprs_mic_e_s *)info;
14341434

@@ -1658,12 +1658,26 @@ static void aprs_mic_e (decode_aprs_t *A, packet_t pp, unsigned char *info, int
16581658

16591659
// The rest is a comment which can have other information cryptically embedded.
16601660
// Remove any trailing CR, which I would argue, violates the protocol spec.
1661-
// It is essential to keep trailing spaces. e.g. VX-8 suffix is "_ "
1661+
// It is essential to keep trailing spaces. e.g. VX-8 device id suffix is "_ "
1662+
1663+
if (ilen <= sizeof(struct aprs_mic_e_s)) {
1664+
// Too short for a comment. We are finished.
1665+
strlcpy (A->g_mfr, "UNKNOWN vendor/model", sizeof(A->g_mfr));
1666+
return;
1667+
}
16621668

16631669
char mcomment[256];
16641670
strlcpy (mcomment, ((char*)info) + sizeof(struct aprs_mic_e_s), sizeof(mcomment));
1671+
1672+
assert (strlen(mcomment) > 0);
1673+
16651674
if (mcomment[strlen(mcomment)-1] == '\r') {
16661675
mcomment[strlen(mcomment)-1] = '\0';
1676+
if (strlen(mcomment) == 0) {
1677+
// Nothing left after removing trailing CR.
1678+
strlcpy (A->g_mfr, "UNKNOWN vendor/model", sizeof(A->g_mfr));
1679+
return;
1680+
}
16671681
}
16681682

16691683
/* Now try to pick out manufacturer and other optional items. */
@@ -1678,7 +1692,7 @@ static void aprs_mic_e (decode_aprs_t *A, packet_t pp, unsigned char *info, int
16781692
// Three base 91 characters followed by }
16791693

16801694

1681-
if (strlen(trimmed) >=4 &&
1695+
if (strlen(trimmed) >= 4 &&
16821696
isdigit91(trimmed[0]) &&
16831697
isdigit91(trimmed[1]) &&
16841698
isdigit91(trimmed[2]) &&

0 commit comments

Comments
 (0)