Apply a single security rule: validate arity, lengths, ranges, and invariants before using inputs to index arrays, dereference pointers, compute derived pointers, or persist/serialize into security-sensitive targets.
Practical checklist:
argv out of bounds.Example (arity defense-in-depth):
// In an ACL permission path that inspects argv for keys/channels
if (!commandCheckArity(cmd, argc, NULL)) {
if (idxptr) *idxptr = 0;
return ACL_DENIED_CMD;
}
// Also keep boundary checks in shared key-extraction helpers,
// even if callers already validated.
Example (invariant assertion before derived pointer):
serverAssert(metaId < KEY_META_ID_MAX && (bits & (1u << metaId)));
Example (string control-char validation at persistence boundary):
if (sentinelStringContainsControlChars(val->ptr, sdslen(val->ptr))) {
addReplyError(c, "value must not contain control characters");
goto bad;
}
Enter the URL of a public GitHub repository