llvm.org GIT mirror llvm / 802a1be
ExceptionDemo: remove some undefined behaviour The casting based reading of the LSDA could attempt to read unsuitably aligned data. Avoid that case by explicitly using a memcpy. A similar approach is used in libc++abi to address the same UB. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287479 91177308-0d34-0410-b5e6-96231b3b80d8 Saleem Abdulrasool 4 years ago
1 changed file(s) with 17 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
218218 // Runtime C Library functions
219219 //
220220
221 namespace {
222 template
223 uintptr_t ReadType(const uint8_t *&p) {
224 Type_ value;
225 memcpy(&value, p, sizeof(Type_));
226 p += sizeof(Type_);
227 return static_cast(value);
228 }
229 }
230
221231 // Note: using an extern "C" block so that static functions can be used
222232 extern "C" {
223233
408418 // first get value
409419 switch (encoding & 0x0F) {
410420 case llvm::dwarf::DW_EH_PE_absptr:
411 result = *((uintptr_t*)p);
412 p += sizeof(uintptr_t);
421 result = ReadType(p);
413422 break;
414423 case llvm::dwarf::DW_EH_PE_uleb128:
415424 result = readULEB128(&p);
419428 result = readSLEB128(&p);
420429 break;
421430 case llvm::dwarf::DW_EH_PE_udata2:
422 result = *((uint16_t*)p);
423 p += sizeof(uint16_t);
431 result = ReadType(p);
424432 break;
425433 case llvm::dwarf::DW_EH_PE_udata4:
426 result = *((uint32_t*)p);
427 p += sizeof(uint32_t);
434 result = ReadType(p);
428435 break;
429436 case llvm::dwarf::DW_EH_PE_udata8:
430 result = *((uint64_t*)p);
431 p += sizeof(uint64_t);
437 result = ReadType(p);
432438 break;
433439 case llvm::dwarf::DW_EH_PE_sdata2:
434 result = *((int16_t*)p);
435 p += sizeof(int16_t);
440 result = ReadType(p);
436441 break;
437442 case llvm::dwarf::DW_EH_PE_sdata4:
438 result = *((int32_t*)p);
439 p += sizeof(int32_t);
443 result = ReadType(p);
440444 break;
441445 case llvm::dwarf::DW_EH_PE_sdata8:
442 result = *((int64_t*)p);
443 p += sizeof(int64_t);
446 result = ReadType(p);
444447 break;
445448 default:
446449 // not supported