Skip to content

Fix inverted write() error check in profile exporter#501

Open
xroche wants to merge 1 commit intoDataDog:mainfrom
algolia:fix/exporter-write-error-check
Open

Fix inverted write() error check in profile exporter#501
xroche wants to merge 1 commit intoDataDog:mainfrom
algolia:fix/exporter-write-error-check

Conversation

@xroche
Copy link

@xroche xroche commented Feb 27, 2026

What does this PR do?

Fix write_profile() in src/exporter/ddprof_exporter.cc which checked write() == 0 instead of write() < 0.

write() returns -1 on error, not 0. The previous check:

  • Missed all real errors (ENOSPC, EIO, EPIPE) — returned success when the write failed
  • False-alarmed on legitimate 0-byte writes — returned error when nothing was wrong

The fix also handles short writes with a loop, since write() may return less than the requested length.

Motivation

Profile data was silently lost on disk errors, causing invisible profiling gaps with no diagnostic signal.

How to test the change?

Write to a full filesystem or a closed pipe — the error should now be detected and reported instead of silently ignored.

Classification

  • CWE-253: Incorrect Check of Function Return Value

Fixes #498

write() returns -1 on error, not 0. The previous check:
- Missed all real errors (ENOSPC, EIO, EPIPE)
- False-alarmed on legitimate 0-byte writes

Also handle short writes with a loop, since write() may return
less than the requested length.

Fixes DataDog#498
@xroche xroche marked this pull request as ready for review February 27, 2026 20:12
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.

write() error check inverted in profile exporter

1 participant