OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/render_frame_impl.h" | 5 #include "content/renderer/render_frame_impl.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 return ds->originalRequest().url(); | 195 return ds->originalRequest().url(); |
196 } | 196 } |
197 | 197 |
198 NOINLINE static void CrashIntentionally() { | 198 NOINLINE static void CrashIntentionally() { |
199 // NOTE(shess): Crash directly rather than using NOTREACHED() so | 199 // NOTE(shess): Crash directly rather than using NOTREACHED() so |
200 // that the signature is easier to triage in crash reports. | 200 // that the signature is easier to triage in crash reports. |
201 volatile int* zero = NULL; | 201 volatile int* zero = NULL; |
202 *zero = 0; | 202 *zero = 0; |
203 } | 203 } |
204 | 204 |
| 205 #if defined(SYZYASAN) |
| 206 // This code triggers a C4509 warning as we're using an object with a destructor |
| 207 // in a function with SEH. We can safely disable this as no exception will |
| 208 // actually be thrown. |
| 209 #pragma warning(push) |
| 210 #pragma warning(disable: 4509) |
| 211 NOINLINE static void CorruptMemoryBlock() { |
| 212 // NOTE(sebmarchand): We intentionally corrupt a memory block here in order to |
| 213 // trigger an Address Sanitizer (ASAN) error report. |
| 214 static const int kArraySize = 5; |
| 215 scoped_ptr<int[]> array(new int[kArraySize]); |
| 216 // Encapsulate the invalid memory access into a try-catch statement to prevent |
| 217 // this function from being instrumented. This way the underflow won't be |
| 218 // detected but the corruption will (as the allocator will still be hooked). |
| 219 __try { |
| 220 int dummy = array[-1]--; |
| 221 // Make sure the assignments to the dummy value aren't optimized away. |
| 222 base::debug::Alias(&array); |
| 223 } __except (EXCEPTION_EXECUTE_HANDLER) { |
| 224 return; |
| 225 } |
| 226 } |
| 227 #pragma warning(pop) |
| 228 #endif |
| 229 |
205 #if defined(ADDRESS_SANITIZER) || defined(SYZYASAN) | 230 #if defined(ADDRESS_SANITIZER) || defined(SYZYASAN) |
206 NOINLINE static void MaybeTriggerAsanError(const GURL& url) { | 231 NOINLINE static void MaybeTriggerAsanError(const GURL& url) { |
207 // NOTE(rogerm): We intentionally perform an invalid heap access here in | 232 // NOTE(rogerm): We intentionally perform an invalid heap access here in |
208 // order to trigger an Address Sanitizer (ASAN) error report. | 233 // order to trigger an Address Sanitizer (ASAN) error report. |
209 static const char kCrashDomain[] = "crash"; | 234 static const char kCrashDomain[] = "crash"; |
210 static const char kHeapOverflow[] = "/heap-overflow"; | 235 static const char kHeapOverflow[] = "/heap-overflow"; |
211 static const char kHeapUnderflow[] = "/heap-underflow"; | 236 static const char kHeapUnderflow[] = "/heap-underflow"; |
212 static const char kUseAfterFree[] = "/use-after-free"; | 237 static const char kUseAfterFree[] = "/use-after-free"; |
| 238 #if defined(SYZYASAN) |
| 239 static const char kCorruptHeapBlock[] = "/corrupt-heap-block"; |
| 240 #endif |
213 static const int kArraySize = 5; | 241 static const int kArraySize = 5; |
214 | 242 |
215 if (!url.DomainIs(kCrashDomain, sizeof(kCrashDomain) - 1)) | 243 if (!url.DomainIs(kCrashDomain, sizeof(kCrashDomain) - 1)) |
216 return; | 244 return; |
217 | 245 |
218 if (!url.has_path()) | 246 if (!url.has_path()) |
219 return; | 247 return; |
220 | 248 |
221 scoped_ptr<int[]> array(new int[kArraySize]); | 249 scoped_ptr<int[]> array(new int[kArraySize]); |
222 std::string crash_type(url.path()); | 250 std::string crash_type(url.path()); |
223 int dummy = 0; | 251 int dummy = 0; |
224 if (crash_type == kHeapOverflow) { | 252 if (crash_type == kHeapOverflow) { |
225 dummy = array[kArraySize]; | 253 dummy = array[kArraySize]; |
226 } else if (crash_type == kHeapUnderflow ) { | 254 } else if (crash_type == kHeapUnderflow ) { |
227 dummy = array[-1]; | 255 dummy = array[-1]; |
228 } else if (crash_type == kUseAfterFree) { | 256 } else if (crash_type == kUseAfterFree) { |
229 int* dangling = array.get(); | 257 int* dangling = array.get(); |
230 array.reset(); | 258 array.reset(); |
231 dummy = dangling[kArraySize / 2]; | 259 dummy = dangling[kArraySize / 2]; |
| 260 #if defined(SYZYASAN) |
| 261 } else if (crash_type == kCorruptHeapBlock) { |
| 262 CorruptMemoryBlock(); |
| 263 #endif |
232 } | 264 } |
233 | 265 |
234 // Make sure the assignments to the dummy value aren't optimized away. | 266 // Make sure the assignments to the dummy value aren't optimized away. |
235 base::debug::Alias(&dummy); | 267 base::debug::Alias(&dummy); |
236 } | 268 } |
237 #endif // ADDRESS_SANITIZER || SYZYASAN | 269 #endif // ADDRESS_SANITIZER || SYZYASAN |
238 | 270 |
239 static void MaybeHandleDebugURL(const GURL& url) { | 271 static void MaybeHandleDebugURL(const GURL& url) { |
240 if (!url.SchemeIs(kChromeUIScheme)) | 272 if (!url.SchemeIs(kChromeUIScheme)) |
241 return; | 273 return; |
(...skipping 2927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3169 selection_text_offset_ = offset; | 3201 selection_text_offset_ = offset; |
3170 selection_range_ = range; | 3202 selection_range_ = range; |
3171 // This IPC is dispatched by RenderWidetHost, so use its routing ID. | 3203 // This IPC is dispatched by RenderWidetHost, so use its routing ID. |
3172 Send(new ViewHostMsg_SelectionChanged( | 3204 Send(new ViewHostMsg_SelectionChanged( |
3173 GetRenderWidget()->routing_id(), text, offset, range)); | 3205 GetRenderWidget()->routing_id(), text, offset, range)); |
3174 } | 3206 } |
3175 GetRenderWidget()->UpdateSelectionBounds(); | 3207 GetRenderWidget()->UpdateSelectionBounds(); |
3176 } | 3208 } |
3177 | 3209 |
3178 } // namespace content | 3210 } // namespace content |
OLD | NEW |