arm-trusted-firmware/include/lib/libc/string.h
Jit Loon Lim eb088894dc feat(lib): implement strnlen secure and strcpy secure function
Implement safer version of 'strnlen' function
to handle NULL terminated strings with additional
bound checking and secure version of string copy function
to support better security and avoid destination
buffer overflow.

Change-Id: I93916f003b192c1c6da6a4f78a627c8885db11d9
Signed-off-by: Jit Loon Lim <jit.loon.lim@altera.com>
Signed-off-by: Girisha Dengi <girisha.dengi@intel.com>
2025-03-19 12:57:35 +08:00

36 lines
1.3 KiB
C

/*
* Copyright (c) 2012-2017 Roberto E. Vargas Caballero
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*
* Portions copyright (c) 2018-2020, Arm Limited and Contributors.
* Portions copyright (c) 2023, Intel Corporation. All rights reserved.
* All rights reserved.
*/
#ifndef STRING_H
#define STRING_H
#include <stddef.h>
void *memcpy(void *dst, const void *src, size_t len);
int memcpy_s(void *dst, size_t dsize, void *src, size_t ssize);
void *memmove(void *dst, const void *src, size_t len);
int memcmp(const void *s1, const void *s2, size_t len);
int strcmp(const char *s1, const char *s2);
int strncmp(const char *s1, const char *s2, size_t n);
void *memchr(const void *src, int c, size_t len);
void *memrchr(const void *src, int c, size_t len);
char *strchr(const char *s, int c);
void *memset(void *dst, int val, size_t count);
size_t strlen(const char *s);
size_t strnlen(const char *s, size_t maxlen);
char *strrchr(const char *p, int ch);
size_t strlcpy(char * dst, const char * src, size_t dsize);
size_t strlcat(char * dst, const char * src, size_t dsize);
char *strtok_r(char *s, const char *delim, char **last);
size_t strnlen_secure(const char *str, size_t maxlen);
int strcpy_secure(char *restrict dest, size_t dest_size, const char *restrict src);
#endif /* STRING_H */