Skip to content

linux: don't count the last environ read twice - #2136

Closed
Uzaaft wants to merge 1 commit into
htop-dev:mainfrom
Uzaaft:push-vvqlyprquxnv
Closed

Uzaaft wants to merge 1 commit into
htop-dev:mainfrom
Uzaaft:push-vvqlyprquxnv

Conversation

@Uzaaft

@Uzaaft Uzaaft commented Oct 15, 2026

Copy link
Copy Markdown

Platform_getProcessEnv() reads /proc/PID/environ in a loop that adds each fread() result to size as it goes. After the loop it added the last result once more, so whenever the environment ended partway through the buffer, the block it returned was too long by that many bytes.

EnvScreen then parsed the uninitialised heap memory past the real data as more variables, which shows up as junk entries, often rendered as U+FFFD, on the environment screen.

The loop already counts every byte it reads, so the extra addition is simply removed.

Found while fuzzing htop's UI with https://github.com/antithesishq/bombadil.

Platform_getProcessEnv() reads /proc/PID/environ in a loop that adds
each fread() result to size as it goes. After the loop it added the
last result once more, so whenever the environment ended partway
through the buffer, the block it returned was too long by that many
bytes. EnvScreen then parsed the uninitialised heap memory past the
real data as more variables, which shows up as junk entries, often
rendered as U+FFFD, on the environment screen.

The loop already counts every byte it reads, so the extra addition is
simply removed.

Found while fuzzing htop's UI with Bombadil.
@coderabbitai

coderabbitai Bot commented Oct 15, 2026

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 9637f826-c5a6-4f0b-91d7-2957e705084d
📥 Commits

Reviewing files that changed from the base of the PR and between 44a59cf and 0f60818.

📒 Files selected for processing: 1
  • linux/Platform.c
💤 Files with no reviewable changes: 1
  • linux/Platform.c

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

📝 Walkthrough

Platform_getProcessEnv no longer adds the final fread result to size. The returned environment buffer is sized and terminated without accounting for those bytes.

Priority: ➖ Normal

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 0f608

The environment buffer retains its final read and terminators. No actionable merge risk remains beyond normal checks.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A final read returns its bytes,
The size no longer counts their weight.
The buffer ends before that sum,
A small change alters what comes.
One read, one size, one altered path.

Comment @coderabbitai help to get the list of available commands.

@BenBE BenBE added bug 🐛 Something isn't working code quality ♻️ Code quality enhancement Linux 🐧 Linux related issues labels Oct 16, 2026
@BenBE

BenBE commented Oct 16, 2026

Copy link
Copy Markdown
Member

Superseeded by cb613e6.

Thank you for reporting the bug. While looking at the PR I noticed a few other things about this function that I wanted to address while touching this code anyway.

@BenBE BenBE closed this Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🐛 Something isn't working code quality ♻️ Code quality enhancement Linux 🐧 Linux related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants