void* __memchr_chk(constvoid* s, int c, size_t n, size_t actual_size) {
__check_buffer_access("memchr", "read from", n, actual_size); returnconst_cast<void*>(memchr(s, c, n));
}
// Runtime implementation of __builtin____memmove_chk (used directly by compiler, not in headers). extern"C"void* __memmove_chk(void* dst, constvoid* src, size_t len, size_t dst_len) {
__check_buffer_access("memmove", "write into", len, dst_len); return memmove(dst, src, len);
}
// memcpy is performance-critical enough that we have assembler __memcpy_chk implementations. // This function is used to give better diagnostics than we can easily do from assembler. extern"C"void* __memcpy_chk_fail(void* /*dst*/, const void* /*src*/, size_t count, size_t dst_len) {
__check_count("memcpy", "count", count);
__check_buffer_access("memcpy", "write into", count, dst_len);
abort(); // One of the above is supposed to have failed, otherwise we shouldn't have been called.
}
void* __memrchr_chk(constvoid* s, int c, size_t n, size_t actual_size) {
__check_buffer_access("memrchr", "read from", n, actual_size); return memrchr(const_cast<void *>(s), c, n);
}
// memset is performance-critical enough that we have assembler __memset_chk implementations. // This function is used to give better diagnostics than we can easily do from assembler. extern"C"void* __memset_chk_fail(void* /*dst*/, int /*byte*/, size_t count, size_t dst_len) {
__check_count("memset", "count", count);
__check_buffer_access("memset", "write into", count, dst_len);
abort(); // One of the above is supposed to have failed, otherwise we shouldn't have been called.
}
int __poll_chk(pollfd* fds, nfds_t fd_count, int timeout, size_t fds_size) {
__check_pollfd_array("poll", fds_size, fd_count); return poll(fds, fd_count, timeout);
}
// Runtime implementation of __builtin____stpcpy_chk (used directly by compiler, not in headers).. extern"C"char* __stpcpy_chk(char* dst, constchar* src, size_t dst_len) {
size_t src_len = strlen(src) + 1;
__check_buffer_access("stpcpy", "write into", src_len, dst_len); // stpcpy() returns a pointer to the NUL, but mempcpy() returns a pointer _past_ the last byte. returnstatic_cast<char*>(mempcpy(dst, src, src_len)) - 1;
}
// Runtime implementation of __builtin____stpncpy_chk (used directly by compiler, not in headers). extern"C"char* __stpncpy_chk(char* dst, constchar* src, size_t len, size_t dst_len) {
__check_buffer_access("stpncpy", "write into", len, dst_len); return stpncpy(dst, src, len);
}
// This is a variant of __stpncpy_chk, but it also checks to make // sure we don't read beyond the end of "src". The code for this is // based on the original version of stpncpy, but modified to check // how much we read from "src" during the copy operation. char* __stpncpy_chk2(char* dst, constchar* src, size_t n, size_t dst_len, size_t src_len) {
__check_buffer_access("stpncpy", "write into", n, dst_len); if (n != 0) { char* d = dst; constchar* s = src;
do {
size_t s_copy_len = static_cast<size_t>(s - src); if (__predict_false(s_copy_len >= src_len)) {
__fortify_fatal("stpncpy: detected read past end of %zu-byte buffer", src_len);
}
if ((*d++ = *s++) == 0) { // NUL pad the remaining n-1 bytes. while (--n != 0) {
*d++ = 0;
} break;
}
} while (--n != 0);
}
return dst;
}
// strcat is performance-critical enough that we have assembler __strcat_chk implementations. // This function is used to give better diagnostics than we can easily do from assembler. extern"C"void __strcat_chk_fail(size_t dst_buf_size) {
__fortify_fatal("strcat: prevented write past end of %zu-byte buffer", dst_buf_size);
}
char* __strchr_chk(constchar* p, int ch, size_t s_len) { for (;; ++p, s_len--) { if (__predict_false(s_len == 0)) {
__fortify_fatal("strchr: prevented read past end of buffer");
} if (*p == static_cast<char>(ch)) { returnconst_cast<char*>(p);
} if (*p == '\0') { return nullptr;
}
}
}
// strcpy is performance-critical enough that we have assembler __strcpy_chk implementations. // This function is used to give better diagnostics than we can easily do from assembler. extern"C"void __strcpy_chk_fail(size_t dst_buf_size) {
__fortify_fatal("strcpy: prevented write past end of %zu-byte buffer", dst_buf_size);
}
size_t __strlen_chk(constchar* s, size_t s_len) { // TODO: "prevented" here would be a lie because this strlen can run off the end. // strlen is too important to be expensive, so we wanted to be able to call the optimized // implementation, but I think we need to implement optimized assembler __strlen_chk routines.
size_t ret = strlen(s); if (__predict_false(ret >= s_len)) {
__fortify_fatal("strlen: detected read past end of buffer");
} return ret;
}
// Runtime implementation of __builtin____strncat_chk (used directly by compiler, not in headers). extern"C"char* __strncat_chk(char* dst, constchar* src, size_t len, size_t dst_buf_size) { if (len == 0) { return dst;
}
while (*src != '\0') {
*d++ = *src++;
len--; dst_buf_size--;
if (__predict_false(dst_buf_size == 0)) {
__fortify_fatal("strncat: prevented write past end of buffer");
}
if (len == 0) { break;
}
}
*d = '\0'; return dst;
}
// Runtime implementation of __builtin____strncpy_chk (used directly by compiler, not in headers). extern"C"char* __strncpy_chk(char* dst, constchar* src, size_t len, size_t dst_len) {
__check_buffer_access("strncpy", "write into", len, dst_len); return strncpy(dst, src, len);
}
// This is a variant of __strncpy_chk, but it also checks to make // sure we don't read beyond the end of "src". The code for this is // based on the original version of strncpy, but modified to check // how much we read from "src" during the copy operation. char* __strncpy_chk2(char* dst, constchar* src, size_t n, size_t dst_len, size_t src_len) {
__check_buffer_access("strncpy", "write into", n, dst_len); if (n != 0) { char* d = dst; constchar* s = src;
do {
size_t s_copy_len = static_cast<size_t>(s - src); if (__predict_false(s_copy_len >= src_len)) {
__fortify_fatal("strncpy: detected read past end of %zu-byte buffer", src_len);
}
if ((*d++ = *s++) == 0) { // NUL pad the remaining n-1 bytes. while (--n != 0) {
*d++ = 0;
} break;
}
} while (--n != 0);
}
return dst;
}
char* __strrchr_chk(constchar* p, int ch, size_t s_len) { for (constchar* save = nullptr;; ++p, s_len--) { if (s_len == 0) {
__fortify_fatal("strrchr: prevented read past end of buffer");
} if (*p == static_cast<char>(ch)) {
save = p;
} if (!*p) { returnconst_cast<char*>(save);
}
}
}
mode_t __umask_chk(mode_t mode) { if (__predict_false((mode & 0777) != mode)) {
__fortify_fatal("umask: called with invalid mask %o", mode);
}
return umask(mode);
}
// Runtime implementation of __builtin____vsnprintf_chk (used directly by compiler, not in headers). extern"C"int __vsnprintf_chk(char* dst, size_t supplied_size, int/*flags*/,
size_t dst_len_from_compiler, constchar* format, va_list va) {
__check_buffer_access("vsnprintf", "write into", supplied_size, dst_len_from_compiler); return vsnprintf(dst, supplied_size, format, va);
}
// Runtime implementation of __builtin____snprintf_chk (used directly by compiler, not in headers). extern"C"int __snprintf_chk(char* dst, size_t supplied_size, int flags,
size_t dst_len_from_compiler, constchar* format, ...) {
va_list va;
va_start(va, format); int result = __vsnprintf_chk(dst, supplied_size, flags, dst_len_from_compiler, format, va);
va_end(va); return result;
}
// Runtime implementation of __builtin____vsprintf_chk (used directly by compiler, not in headers). extern"C"int __vsprintf_chk(char* dst, int/*flags*/,
size_t dst_len_from_compiler, constchar* format, va_list va) { // The compiler uses SIZE_MAX to mean "no idea", but our vsnprintf rejects sizes that large. int result = vsnprintf(dst,
dst_len_from_compiler == SIZE_MAX ? SSIZE_MAX : dst_len_from_compiler,
format, va);
// Try to catch failures after the fact...
__check_buffer_access("vsprintf", "write into", result + 1, dst_len_from_compiler); return result;
}
// Runtime implementation of __builtin____sprintf_chk (used directly by compiler, not in headers). extern"C"int __sprintf_chk(char* dst, int flags, size_t dst_len_from_compiler, constchar* format, ...) {
va_list va;
va_start(va, format); int result = __vsprintf_chk(dst, flags, dst_len_from_compiler, format, va);
va_end(va); return result;
}
// Runtime implementation of __builtin____strcat_chk (used directly by compiler, not in headers). extern"C"char* __STRCAT_CHK(char* dst, constchar* src, size_t dst_buf_size) { char* save = dst;
size_t dst_len = __strlen_chk(dst, dst_buf_size);
dst += dst_len;
dst_buf_size -= dst_len;
while ((*dst++ = *src++) != '\0') {
dst_buf_size--; if (__predict_false(dst_buf_size == 0)) {
__fortify_fatal("strcat: prevented write past end of %zu-byte buffer", dst_buf_size);
}
}
// Runtime implementation of __builtin____strcpy_chk (used directly by compiler, not in headers). extern"C"char* __STRCPY_CHK(char* dst, constchar* src, size_t dst_len) {
size_t src_len = strlen(src) + 1;
__check_buffer_access("strcpy", "write into", src_len, dst_len); returnstatic_cast<char*>(memcpy(dst, src, src_len));
}
// Runtime implementation of __mempcpy_chk (used directly by compiler, not in headers). extern"C"void* __mempcpy_chk(void* dst, constvoid* src, size_t count, size_t dst_len) {
__check_count("mempcpy", "count", count);
__check_buffer_access("mempcpy", "write into", count, dst_len); return mempcpy(dst, src, count);
}
Messung V0.5 in Prozent
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.4Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-06-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.