Skip to content

Conversation

@iphydf
Copy link
Member

@iphydf iphydf commented Jan 19, 2026

Replaces unsafe strcpy calls with snprintf, memcpy, or strdup to mitigate potential buffer overflows. Also fixed -Wdouble-promotion build warnings in netprof.c and prompt.c by using explicit double casts and sprintf in configdir.c.


This change is Reviewable

@iphydf iphydf added this to the v0.16.2 milestone Jan 19, 2026
@github-actions github-actions bot added the bug Bug fix for the user, not a fix to a build script label Jan 19, 2026
@iphydf iphydf changed the title fix: Replace unsafe strcpy with safer alternatives and fix build warn… refactor: Replace unsafe strcpy with safer alternatives and fix build warn… Jan 19, 2026
@iphydf iphydf changed the title refactor: Replace unsafe strcpy with safer alternatives and fix build warn… refactor: Replace unsafe strcpy with safer alternatives and fix build warnings Jan 19, 2026
@github-actions github-actions bot added the refactor Refactoring production code, eg. renaming a variable, not affecting semantics label Jan 21, 2026
@iphydf iphydf marked this pull request as ready for review January 21, 2026 21:30
Copy link
Member

@JFreegman JFreegman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JFreegman made 2 comments.
Reviewable status: 1 change requests, 0 of 1 approvals obtained (waiting on @iphydf).


src/misc_tools.c line 491 at r2 (raw file):

on_error:
    snprintf(buf, TOXIC_MAX_NAME_LENGTH + 1, "%s", UNKNOWN_NAME);

The buffer size here (and in all the ones below) is TOX_MAX_NAME_LENGTH which is incidentally <= than TOXIC_MAX_NAME_LENGTH. Maybe we should pass the buffer size so there's less room for error.


src/misc_tools.c line 694 at r2 (raw file):

    if (len > MAX_WINDOW_NAME_LENGTH) {
        snprintf(&cpy[MAX_WINDOW_NAME_LENGTH - 3], 4, "...");

Why 4 instead of sizeof(cpy)?

Copy link
Member Author

@iphydf iphydf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iphydf made 2 comments.
Reviewable status: 1 change requests, 0 of 1 approvals obtained (waiting on @JFreegman).


src/misc_tools.c line 491 at r2 (raw file):

Previously, JFreegman wrote…

The buffer size here (and in all the ones below) is TOX_MAX_NAME_LENGTH which is incidentally <= than TOXIC_MAX_NAME_LENGTH. Maybe we should pass the buffer size so there's less room for error.

Done.


src/misc_tools.c line 694 at r2 (raw file):

Previously, JFreegman wrote…

Why 4 instead of sizeof(cpy)?

Done.

@iphydf iphydf force-pushed the cleanup branch 2 times, most recently from bda3613 to df3b5a5 Compare January 22, 2026 19:34
…ings.

Replaces unsafe `strcpy` calls with `snprintf`, `memcpy`, or `strdup` to
mitigate potential buffer overflows. Also fixed `-Wdouble-promotion`
build warnings in `netprof.c` and `prompt.c` by using explicit `double`
casts and `sprintf` in `configdir.c`.
Copy link
Member

@JFreegman JFreegman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JFreegman reviewed 16 files and all commit messages, and resolved 2 discussions.
Reviewable status: :shipit: complete! 1 of 1 approvals obtained.

@toktok-releaser toktok-releaser merged commit 0b9ed3b into TokTok:master Jan 22, 2026
16 checks passed
@iphydf iphydf deleted the cleanup branch January 22, 2026 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Bug fix for the user, not a fix to a build script refactor Refactoring production code, eg. renaming a variable, not affecting semantics

Development

Successfully merging this pull request may close these issues.

3 participants