Unified · Split
| @@ -490,7 +490,7 @@ void __bound_new_region(void *p, unsigned long size) · 489 unmodified lines | ||
| 490 | 490 | } |
| 491 | 491 | } |
| 492 | 492 | /* last page */ |
| 493 | − page = get_page(t2_end); | |
| 493 | + page = get_page(t1_end); | |
| 494 | 494 | e2 = (BoundEntry *)((char *)page + t2_end); |
| 495 | 495 | for(e=page;e<e2;e++) { |
| 496 | 496 | e->start = start; |
| @@ -795,7 +795,7 @@ void *__bound_memcpy(void *dst, const void *src, size_t size) · 298 unmodified lines | ||
| 795 | 795 | __bound_check(src, size); |
| 796 | 796 | /* check also region overlap */ |
| 797 | 797 | if (src >= dst && src < dst + size) |
| 798 | − bound_error(get_caller_pc(1), "memcpy: overlapping regions"); | |
| 798 | + bound_error(get_caller_pc(1), "overlapping regions in memcpy()"); | |
| 799 | 799 | return memcpy(dst, src, size); |
| 800 | 800 | } |
| 801 | 801 | |
| @@ -812,6 +812,31 @@ void *__bound_memset(void *dst, int c, size_t size) · 10 unmodified lines | ||
| 812 | 812 | return memset(dst, c, size); |
| 813 | 813 | } |
| 814 | 814 | |
| 815 | +/* XXX: could be optimized */ | |
| 816 | +int __bound_strlen(const char *s) | |
| 817 | +{ | |
| 818 | + const char *p; | |
| 819 | + int len; | |
| 820 | + | |
| 821 | + len = 0; | |
| 822 | + for(;;) { | |
| 823 | + p = __bound_ptr_indir1((char *)s, len); | |
| 824 | + if (p == INVALID_POINTER) | |
| 825 | + bound_error(get_caller_pc(1), "bad pointer in strlen()"); | |
| 826 | + if (*p == '\0') | |
| 827 | + break; | |
| 828 | + len++; | |
| 829 | + } | |
| 830 | + return len; | |
| 831 | +} | |
| 832 | + | |
| 833 | +char *__bound_strcpy(char *dst, const char *src) | |
| 834 | +{ | |
| 835 | + int len; | |
| 836 | + len = __bound_strlen(src); | |
| 837 | + return __bound_memcpy(dst, src, len + 1); | |
| 838 | +} | |
| 839 | + | |
| 815 | 840 | /* resolve bound check syms */ |
| 816 | 841 | typedef struct BCSyms { |
| 817 | 842 | char *str; |
| @@ -822,6 +847,8 @@ static BCSyms bcheck_syms[] = { · 4 unmodified lines | ||
| 822 | 847 | { "memcpy", __bound_memcpy }, |
| 823 | 848 | { "memmove", __bound_memmove }, |
| 824 | 849 | { "memset", __bound_memset }, |
| 850 | + { "strlen", __bound_strlen }, | |
| 851 | + { "strcpy", __bound_strcpy }, | |
| 825 | 852 | { NULL, NULL }, |
| 826 | 853 | }; |
| 827 | 854 | |