MCPcopy Create free account
hub / github.com/F-Stack/f-stack / redzone_check

Function redzone_check

freebsd/vm/redzone.c:129–184  ·  view source on GitHub ↗

* Verify redzones. * This function is called on free() and realloc(). */

Source from the content-addressed store, hash-verified

127 * This function is called on free() and realloc().
128 */
129void
130redzone_check(caddr_t naddr)
131{
132 struct stack ast, fst;
133 caddr_t haddr, faddr;
134 u_int ncorruptions;
135 u_long nsize;
136 int i;
137
138 haddr = naddr - REDZONE_HSIZE;
139 bcopy(haddr, &ast, sizeof(ast));
140 haddr += sizeof(ast);
141 bcopy(haddr, &nsize, sizeof(nsize));
142 haddr += sizeof(nsize);
143
144 atomic_subtract_long(&redzone_extra_mem,
145 redzone_size_ntor(nsize) - nsize);
146
147 /* Look for buffer underflow. */
148 ncorruptions = 0;
149 for (i = 0; i < REDZONE_CHSIZE; i++, haddr++) {
150 if (*(u_char *)haddr != 0x42)
151 ncorruptions++;
152 }
153 if (ncorruptions > 0) {
154 printf("REDZONE: Buffer underflow detected. %u byte%s "
155 "corrupted before %p (%lu bytes allocated).\n",
156 ncorruptions, ncorruptions == 1 ? "" : "s", naddr, nsize);
157 printf("Allocation backtrace:\n");
158 stack_print_ddb(&ast);
159 printf("Free backtrace:\n");
160 stack_save(&fst);
161 stack_print_ddb(&fst);
162 if (redzone_panic)
163 panic("Stopping here.");
164 }
165 faddr = naddr + nsize;
166 /* Look for buffer overflow. */
167 ncorruptions = 0;
168 for (i = 0; i < REDZONE_CFSIZE; i++, faddr++) {
169 if (*(u_char *)faddr != 0x42)
170 ncorruptions++;
171 }
172 if (ncorruptions > 0) {
173 printf("REDZONE: Buffer overflow detected. %u byte%s corrupted "
174 "after %p (%lu bytes allocated).\n", ncorruptions,
175 ncorruptions == 1 ? "" : "s", naddr + nsize, nsize);
176 printf("Allocation backtrace:\n");
177 stack_print_ddb(&ast);
178 printf("Free backtrace:\n");
179 stack_save(&fst);
180 stack_print_ddb(&fst);
181 if (redzone_panic)
182 panic("Stopping here.");
183 }
184}

Callers 1

free_dbgFunction · 0.85

Calls 6

atomic_subtract_longFunction · 0.85
redzone_size_ntorFunction · 0.85
stack_print_ddbFunction · 0.85
printfFunction · 0.50
stack_saveFunction · 0.50
panicFunction · 0.50

Tested by

no test coverage detected