Security Operations

A shared logging library formats timestamps with a function that writes into one static buffer. Under concurrent requests, log lines show timestamps from other requests mixed in. Which fix addresses the cause?

Show the answer

Correct answerC. Call a reentrant version that uses a caller-supplied buffer

AWhy not this: Input validation checks request content; the corruption comes from threads sharing a buffer, not bad input.

BWhy not this: An atomic counter makes one value indivisible but leaves the shared static buffer unprotected.

CWhy this is right: Giving each caller its own buffer removes the shared state that concurrent threads were overwriting.

DWhy not this: Output encoding neutralizes characters for a rendering context; it cannot stop threads overwriting a buffer.

The function keeps shared state in a static buffer, so concurrent callers overwrite each other's results. A reentrant, thread-safe version uses caller-owned storage, so threads do not share data. An atomic counter protects a single value and does not protect a shared buffer.