Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

security boundaries — concept C23

A security boundary validates lengths, ranges, encoding, and authorization before using external data; fixed format strings, checked size arithmetic, and ordered cleanup reduce overflows and memory errors.

Version: C23

Syntax

security boundaries

A security boundary validates lengths, ranges, encoding, and authorization before using external data; fixed format strings, checked size arithmetic, and ordered cleanup reduce overflows and memory errors.

At an untrusted-data boundary, first limit length, check count * size, validate encoding, and only then allocate or copy. Use a fixed format such as printf("%s", input) and pass capacity to every writing function.

Test negative numbers converted to size_t, a missing terminator, a partial read, and a file changing between check and use. Secrets may remain in copies and an optimizer may remove ordinary memset; use an explicit-clearing facility guaranteed by the selected revision and implementation.

Examples

#include <stdio.h>

int main(void) { char buffer[8]; int written = snprintf(buffer, sizeof buffer, "%s", "0123456789"); printf("%d %s\n", written, buffer); return 0; }

Result

10 0123456

A security boundary validates lengths, ranges, encoding, and authorization before using external data; fixed format strings, checked size arithmetic, and ordered cleanup reduce overflows and memory errors.

Sources