Skip to content

Commit f8e0994

Browse files
Use proper buffer size in tt_user.c's digit_suffix
Modern Ubuntu (e.g. GitHub Actions' `ubuntu-latest`), among other distros, compiles with `-D_FORTIFY_SOURCE=3` which does neat things like checking `strlcpy` won't overflow. `tt_user_s` has a `char digit_suffix[3+1]`, so when attempting to `strlcpy` into it with length 5, this triggers a buffer overflow error for safety reasons (even though the source string only has length 4) Let's instead pass a size to `digit_suffix` and use that.
1 parent 486b3cf commit f8e0994

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/tt_user.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,13 +429,13 @@ static int corral_slot (void)
429429
*
430430
*----------------------------------------------------------------*/
431431

432-
static void digit_suffix (char *callsign, char *suffix)
432+
static void digit_suffix (char *callsign, char *suffix, size_t suffix_len)
433433
{
434434
char two_key[50];
435435
char *t;
436436

437437

438-
strlcpy (suffix, "000", 5); // TODO: should have proper size
438+
strlcpy (suffix, "000", suffix_len);
439439
tt_text_to_two_key (callsign, 0, two_key);
440440
for (t = two_key; *t != '\0'; t++) {
441441
if (isdigit(*t)) {
@@ -515,7 +515,7 @@ int tt_user_heard (char *callsign, int ssid, char overlay, char symbol, char *lo
515515
tt_user[i].ssid = ssid;
516516
tt_user[i].overlay = overlay;
517517
tt_user[i].symbol = symbol;
518-
digit_suffix(tt_user[i].callsign, tt_user[i].digit_suffix);
518+
digit_suffix(tt_user[i].callsign, tt_user[i].digit_suffix, sizeof(tt_user[i].digit_suffix));
519519
strlcpy (tt_user[i].loc_text, loc_text, sizeof(tt_user[i].loc_text));
520520

521521
if (latitude != G_UNKNOWN && longitude != G_UNKNOWN) {

0 commit comments

Comments
 (0)