Skip to content

fix: v0.5.38 — realpath buffer overflow in cmd_init on ubuntu-22.04#58

Merged
SoundMatt merged 2 commits into
mainfrom
fix/realpath-buffer-overflow
Jul 26, 2026
Merged

fix: v0.5.38 — realpath buffer overflow in cmd_init on ubuntu-22.04#58
SoundMatt merged 2 commits into
mainfrom
fix/realpath-buffer-overflow

Conversation

@SoundMatt

Copy link
Copy Markdown
Owner

Summary

  • cmd_init.c called realpath(dir, resolved) with a 512-byte stack buffer; glibc's __realpath_chk (enabled by _FORTIFY_SOURCE=2 at -O2 on ubuntu-22.04) requires the destination to be at least PATH_MAX (4096 bytes), triggering *** buffer overflow detected ***: terminated
  • Switched to realpath(dir, NULL) + free(), the same pattern already used in cmd_check.c, cmd_report.c, and cmd_trace.c
  • Root-caused via Docker-based gdb backtrace on Ubuntu 22.04 arm64

Test plan

  • All 56 CLI tests pass on ubuntu-22.04 Release build
  • CI green on this PR

Signed-off-by: SoundMatt <SoundMatt@users.noreply.github.com>

Signed-off-by: Matt Jones <47545907+SoundMatt@users.noreply.github.com>
Comment thread cmd/cfusa/cmd_init.c Fixed
Without #define _GNU_SOURCE, realpath() is not declared from <stdlib.h>
on strict POSIX/C99 builds. clang-15 failed with an undeclared-function
error; gcc compiled with an implicit int-returning declaration which
truncates the 64-bit pointer return value, causing free() to segfault.

All other cmd/*.c files already carry the guard — align cmd_init.c.

Signed-off-by: SoundMatt <SoundMatt@users.noreply.github.com>

Signed-off-by: Matt Jones <47545907+SoundMatt@users.noreply.github.com>
Comment thread cmd/cfusa/cmd_init.c
const char *slash = strrchr(abs, '/');
strncpy(dir_basename, slash ? slash + 1 : abs, sizeof(dir_basename) - 1);
project = dir_basename;
free(resolved);
Comment thread cmd/cfusa/cmd_init.c
const char *slash = strrchr(abs, '/');
strncpy(dir_basename, slash ? slash + 1 : abs, sizeof(dir_basename) - 1);
project = dir_basename;
free(resolved);
@SoundMatt
SoundMatt merged commit d754b97 into main Jul 26, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants