[PATCH] D16466: [ELF] - fix possible UB when dereferencing null

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 22 07:44:32 PST 2016


grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.

In InputSection.cpp it was possible to dereference null.
Had to change signature of relocateTlsOptimize to accept pointer instead of reference.

http://reviews.llvm.org/D16466

Files:
  ELF/InputSection.cpp
  ELF/Target.cpp
  ELF/Target.h

Index: ELF/Target.h
===================================================================
--- ELF/Target.h
+++ ELF/Target.h
@@ -81,7 +81,7 @@
   virtual bool needsCopyRel(uint32_t Type, const SymbolBody &S) const;
   virtual unsigned relocateTlsOptimize(uint8_t *Loc, uint8_t *BufEnd,
                                        uint32_t Type, uint64_t P, uint64_t SA,
-                                       const SymbolBody &S) const;
+                                       const SymbolBody *S) const;
   virtual ~TargetInfo();
 
 protected:
Index: ELF/Target.cpp
===================================================================
--- ELF/Target.cpp
+++ ELF/Target.cpp
@@ -105,7 +105,7 @@
   bool isTlsOptimized(unsigned Type, const SymbolBody *S) const override;
   unsigned relocateTlsOptimize(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type,
                                uint64_t P, uint64_t SA,
-                               const SymbolBody &S) const override;
+                               const SymbolBody *S) const override;
   bool isGotRelative(uint32_t Type) const override;
 
 private:
@@ -141,7 +141,7 @@
   bool isSizeReloc(uint32_t Type) const override;
   unsigned relocateTlsOptimize(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type,
                                uint64_t P, uint64_t SA,
-                               const SymbolBody &S) const override;
+                               const SymbolBody *S) const override;
 
 private:
   void relocateTlsLdToLe(uint8_t *Loc, uint8_t *BufEnd, uint64_t P,
@@ -294,7 +294,7 @@
 
 unsigned TargetInfo::relocateTlsOptimize(uint8_t *Loc, uint8_t *BufEnd,
                                          uint32_t Type, uint64_t P, uint64_t SA,
-                                         const SymbolBody &S) const {
+                                         const SymbolBody *S) const {
   return 0;
 }
 
@@ -483,10 +483,10 @@
 unsigned X86TargetInfo::relocateTlsOptimize(uint8_t *Loc, uint8_t *BufEnd,
                                             uint32_t Type, uint64_t P,
                                             uint64_t SA,
-                                            const SymbolBody &S) const {
+                                            const SymbolBody *S) const {
   switch (Type) {
   case R_386_TLS_GD:
-    if (canBePreempted(&S, true))
+    if (canBePreempted(S, true))
       relocateTlsGdToIe(Loc, BufEnd, P, SA);
     else
       relocateTlsGdToLe(Loc, BufEnd, P, SA);
@@ -858,16 +858,16 @@
 unsigned X86_64TargetInfo::relocateTlsOptimize(uint8_t *Loc, uint8_t *BufEnd,
                                                uint32_t Type, uint64_t P,
                                                uint64_t SA,
-                                               const SymbolBody &S) const {
+                                               const SymbolBody *S) const {
   switch (Type) {
   case R_X86_64_DTPOFF32:
     relocateOne(Loc, BufEnd, R_X86_64_TPOFF32, P, SA);
     return 0;
   case R_X86_64_GOTTPOFF:
     relocateTlsIeToLe(Loc, BufEnd, P, SA);
     return 0;
   case R_X86_64_TLSGD: {
-    if (canBePreempted(&S, true))
+    if (canBePreempted(S, true))
       relocateTlsGdToIe(Loc, BufEnd, P, SA);
     else
       relocateTlsGdToLe(Loc, BufEnd, P, SA);
Index: ELF/InputSection.cpp
===================================================================
--- ELF/InputSection.cpp
+++ ELF/InputSection.cpp
@@ -180,7 +180,7 @@
       // relocations that immediately follow TLS relocations. This function
       // knows how many slots we need to skip.
       I += Target->relocateTlsOptimize(BufLoc, BufEnd, Type, AddrLoc, SymVA,
-                                       *Body);
+                                       Body);
       continue;
     }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16466.45688.patch
Type: text/x-patch
Size: 3731 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160122/0f97b13b/attachment.bin>


More information about the llvm-commits mailing list