Description
write_profile() in src/exporter/ddprof_exporter.cc (line 62-68) checks the wrong return value from write():
DDRes write_profile(const ddog_ByteSlice *buffer, int fd) {
if (write(fd, buffer->ptr, buffer->len) == 0) { // BUG: should check == -1
DDRES_RETURN_ERROR_LOG(DD_WHAT_EXPORTER,
"Failed to write byte buffer to stdout! %s\n",
strerror(errno));
}
return {};
}
write() returns -1 on error, not 0. The current check:
- Misses all real errors (ENOSPC, EIO, EPIPE, etc.) — returns success when the write actually failed
- False-alarms on legitimate 0-byte writes (empty buffer) — returns error when nothing is wrong
- Doesn't handle short writes —
write() may return less than buffer->len
Impact
Profile data is silently lost on disk errors. This causes invisible profiling gaps with no diagnostic signal, making it difficult to debug missing profiles in production.
Fix
Check for == -1 (or < 0) instead of == 0. Ideally also handle short writes with a loop.
Classification
- CWE-253: Incorrect Check of Function Return Value
Description
write_profile()insrc/exporter/ddprof_exporter.cc(line 62-68) checks the wrong return value fromwrite():write()returns-1on error, not0. The current check:write()may return less thanbuffer->lenImpact
Profile data is silently lost on disk errors. This causes invisible profiling gaps with no diagnostic signal, making it difficult to debug missing profiles in production.
Fix
Check for
== -1(or< 0) instead of== 0. Ideally also handle short writes with a loop.Classification