bzero - Man Page

zero a byte string

Library

Standard C library (libc, -lc)

Synopsis

#include <strings.h>

void bzero(void s[.n], size_t n);

#include <string.h>

void explicit_bzero(void s[.n], size_t n);

Description

The bzero() function erases the data in the n bytes of the memory starting at the location pointed to by s, by writing zeros (bytes containing '\0') to that area.

The explicit_bzero() function performs the same task as bzero(). It differs from bzero() in that it guarantees that compiler optimizations will not remove the erase operation if the compiler deduces that the operation is "unnecessary".

Return Value

None.

Attributes

For an explanation of the terms used in this section, see attributes(7).

InterfaceAttributeValue
bzero(), explicit_bzero()Thread safetyMT-Safe

Standards

None.

History

explicit_bzero()

glibc 2.25.

The explicit_bzero() function is a nonstandard extension that is also present on some of the BSDs. Some other implementations have a similar function, such as memset_explicit() or memset_s().

bzero()

4.3BSD.

Marked as LEGACY in POSIX.1-2001. Removed in POSIX.1-2008.

Notes

The explicit_bzero() function addresses a problem that security-conscious applications may run into when using bzero(): if the compiler can deduce that the location to be zeroed will never again be touched by a correct program, then it may remove the bzero() call altogether. This is a problem if the intent of the bzero() call was to erase sensitive data (e.g., passwords) to prevent the possibility that the data was leaked by an incorrect or compromised program. Calls to explicit_bzero() are never optimized away by the compiler.

The explicit_bzero() function does not solve all problems associated with erasing sensitive data:

Note that declaring the sensitive variable with the volatile qualifier does not eliminate the above problems. Indeed, it will make them worse, since, for example, it may force a variable that would otherwise have been optimized into a register to instead be maintained in (more vulnerable) RAM for its entire lifetime.

Notwithstanding the above details, for security-conscious applications, using explicit_bzero() is generally preferable to not using it. The developers of explicit_bzero() anticipate that future compilers will recognize calls to explicit_bzero() and take steps to ensure that all copies of the sensitive data are erased, including copies in registers or in "scratch" stack areas.

See Also

bstring(3), memset(3), swab(3)

Referenced By

bstring(3), memset(3), reallocarray.3bsd(3), string_copying(7).

The man page explicit_bzero(3) is an alias of bzero(3).

2023-10-31 Linux man-pages 6.06