History

new_region() fix - added bounded strlen and strcpy

bellard committed 24 years ago

Commit 2d948c71 parent dbb999f1 file · +29 −2Browse files

Unified · Split

bcheck.c+29−2
@@ -490,7 +490,7 @@ void __bound_new_region(void *p, unsigned long size) · 489 unmodified lines
490490 }
491491 }
492492 /* last page */
493− page = get_page(t2_end);
493+ page = get_page(t1_end);
494494 e2 = (BoundEntry *)((char *)page + t2_end);
495495 for(e=page;e<e2;e++) {
496496 e->start = start;
@@ -795,7 +795,7 @@ void *__bound_memcpy(void *dst, const void *src, size_t size) · 298 unmodified lines
795795 __bound_check(src, size);
796796 /* check also region overlap */
797797 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()");
799799 return memcpy(dst, src, size);
800800 }
801801
@@ -812,6 +812,31 @@ void *__bound_memset(void *dst, int c, size_t size) · 10 unmodified lines
812812 return memset(dst, c, size);
813813 }
814814
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+
815840 /* resolve bound check syms */
816841 typedef struct BCSyms {
817842 char *str;
@@ -822,6 +847,8 @@ static BCSyms bcheck_syms[] = { · 4 unmodified lines
822847 { "memcpy", __bound_memcpy },
823848 { "memmove", __bound_memmove },
824849 { "memset", __bound_memset },
850+ { "strlen", __bound_strlen },
851+ { "strcpy", __bound_strcpy },
825852 { NULL, NULL },
826853 };
827854

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t