Showing the changes to lib (1 of 6 files). Show all
Unified · Split
| @@ -292,7 +292,9 @@ DLL_EXPORT char *__bound_strncpy(char *dst, const char *src, size_t n); · 291 unmodified lines | ||
| 292 | 292 | DLL_EXPORT int __bound_strcmp(const char *s1, const char *s2); |
| 293 | 293 | DLL_EXPORT int __bound_strncmp(const char *s1, const char *s2, size_t n); |
| 294 | 294 | DLL_EXPORT char *__bound_strcat(char *dest, const char *src); |
| 295 | +DLL_EXPORT char *__bound_strncat(char *dest, const char *src, size_t n); | |
| 295 | 296 | DLL_EXPORT char *__bound_strchr(const char *string, int ch); |
| 297 | +DLL_EXPORT char *__bound_strrchr(const char *string, int ch); | |
| 296 | 298 | DLL_EXPORT char *__bound_strdup(const char *s); |
| 297 | 299 | |
| 298 | 300 | #if defined(__arm__) && defined(__ARM_EABI__) |
| @@ -424,7 +426,9 @@ static unsigned long long bound_strncpy_count; · 125 unmodified lines | ||
| 424 | 426 | static unsigned long long bound_strcmp_count; |
| 425 | 427 | static unsigned long long bound_strncmp_count; |
| 426 | 428 | static unsigned long long bound_strcat_count; |
| 429 | +static unsigned long long bound_strncat_count; | |
| 427 | 430 | static unsigned long long bound_strchr_count; |
| 431 | +static unsigned long long bound_strrchr_count; | |
| 428 | 432 | static unsigned long long bound_strdup_count; |
| 429 | 433 | static unsigned long long bound_not_found; |
| 430 | 434 | #define INCR_COUNT(x) ++x |
| @@ -1259,7 +1263,9 @@ void __attribute__((destructor)) __bound_exit(void) · 828 unmodified lines | ||
| 1259 | 1263 | fprintf (stderr, "bound_strcmp_count %llu\n", bound_strcmp_count); |
| 1260 | 1264 | fprintf (stderr, "bound_strncmp_count %llu\n", bound_strncmp_count); |
| 1261 | 1265 | fprintf (stderr, "bound_strcat_count %llu\n", bound_strcat_count); |
| 1266 | + fprintf (stderr, "bound_strncat_count %llu\n", bound_strncat_count); | |
| 1262 | 1267 | fprintf (stderr, "bound_strchr_count %llu\n", bound_strchr_count); |
| 1268 | + fprintf (stderr, "bound_strrchr_count %llu\n", bound_strrchr_count); | |
| 1263 | 1269 | fprintf (stderr, "bound_strdup_count %llu\n", bound_strdup_count); |
| 1264 | 1270 | fprintf (stderr, "bound_not_found %llu\n", bound_not_found); |
| 1265 | 1271 | #endif |
| @@ -1940,6 +1946,24 @@ char *__bound_strcat(char *dest, const char *src) · 674 unmodified lines | ||
| 1940 | 1946 | return strcat(r, s); |
| 1941 | 1947 | } |
| 1942 | 1948 | |
| 1949 | +char *__bound_strncat(char *dest, const char *src, size_t n) | |
| 1950 | +{ | |
| 1951 | + char *r = dest; | |
| 1952 | + const char *s = src; | |
| 1953 | + size_t len = n; | |
| 1954 | + | |
| 1955 | + dprintf(stderr, "%s, %s(): %p, %p, 0x%lx\n", | |
| 1956 | + __FILE__, __FUNCTION__, dest, src, (unsigned long)n); | |
| 1957 | + INCR_COUNT(bound_strncat_count); | |
| 1958 | + while (*dest++); | |
| 1959 | + while (len-- && *src++); | |
| 1960 | + __bound_check(r, (dest - r) + (src - s) - 1, "strncat dest"); | |
| 1961 | + __bound_check(s, src - s, "strncat src"); | |
| 1962 | + if (check_overlap(r, (dest - r) + (src - s) - 1, s, src - s, "strncat")) | |
| 1963 | + return dest; | |
| 1964 | + return strncat(r, s, n); | |
| 1965 | +} | |
| 1966 | + | |
| 1943 | 1967 | char *__bound_strchr(const char *s, int c) |
| 1944 | 1968 | { |
| 1945 | 1969 | const unsigned char *str = (const unsigned char *) s; |
| @@ -1957,6 +1981,24 @@ char *__bound_strchr(const char *s, int c) · 11 unmodified lines | ||
| 1957 | 1981 | return *str == ch ? (char *) str : NULL; |
| 1958 | 1982 | } |
| 1959 | 1983 | |
| 1984 | +char *__bound_strrchr(const char *s, int c) | |
| 1985 | +{ | |
| 1986 | + const unsigned char *str = (const unsigned char *) s; | |
| 1987 | + unsigned char ch = c; | |
| 1988 | + | |
| 1989 | + dprintf(stderr, "%s, %s(): %p, %d\n", | |
| 1990 | + __FILE__, __FUNCTION__, s, ch); | |
| 1991 | + INCR_COUNT(bound_strrchr_count); | |
| 1992 | + while (*str++); | |
| 1993 | + __bound_check(s, (const char *)str - s, "strrchr"); | |
| 1994 | + while (str != (const unsigned char *)s) { | |
| 1995 | + if (*--str == ch) | |
| 1996 | + break; | |
| 1997 | + } | |
| 1998 | + __bound_check(s, (const char *)str - s, "strrchr"); | |
| 1999 | + return *str == ch ? (char *) str : NULL; | |
| 2000 | +} | |
| 2001 | + | |
| 1960 | 2002 | char *__bound_strdup(const char *s) |
| 1961 | 2003 | { |
| 1962 | 2004 | const char *p = s; |