Commit 0446b60
committed
Challenge 13: Verify safety of CStr
Verify all 14 items listed in the challenge specification.
14 Kani proof harnesses, 0 failures. Bounded verification with MAX_SIZE=32.
Part 1: Invariant trait for CStr (pre-existing).
Part 2: Harnesses for all 9 safe methods — from_bytes_until_nul,
from_bytes_with_nul, count_bytes, is_empty, to_bytes,
to_bytes_with_nul, bytes, to_str, as_ptr (pre-existing).
Part 3: Contracts and harnesses for all 3 unsafe functions —
from_ptr, from_bytes_with_nul_unchecked, strlen (pre-existing).
Part 4: New harnesses for trait implementations:
- check_index_range_from: verifies Index<RangeFrom<usize>> preserves
the CStr invariant when slicing from any valid start index.
- check_clone_to_uninit: verifies CloneToUninit copies correct bytes
to the destination with no undefined behavior.
Note: A formal #[requires] contract on CloneToUninit::clone_to_uninit
could not be added because the safety crate's proc macro does not
currently support methods inside unsafe impl Trait blocks. The
harness verifies safety via CBMC's built-in memory model checks.
Resolves #1501 parent 2840898 commit 0446b60
File tree
2 files changed
+97
-3
lines changed- doc/src/challenges
- library/core/src/ffi
2 files changed
+97
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
149 | | - | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
150 | 153 | | |
151 | 154 | | |
152 | 155 | | |
| |||
821 | 824 | | |
822 | 825 | | |
823 | 826 | | |
824 | | - | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
825 | 831 | | |
826 | 832 | | |
827 | 833 | | |
| |||
858 | 864 | | |
859 | 865 | | |
860 | 866 | | |
861 | | - | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
862 | 872 | | |
863 | 873 | | |
864 | 874 | | |
| |||
875 | 885 | | |
876 | 886 | | |
877 | 887 | | |
| 888 | + | |
878 | 889 | | |
879 | 890 | | |
880 | 891 | | |
| |||
1096 | 1107 | | |
1097 | 1108 | | |
1098 | 1109 | | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
1099 | 1152 | | |
0 commit comments