[PATCH] D112782: [LNT] Fixed possible crash or junk data in cPerf

Pavel Kosov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 29 01:25:44 PDT 2021


kpdev42 created this revision.
kpdev42 added reviewers: cmatthews, thopre, danilaml.
kpdev42 added a project: LLVM.
Herald added a subscriber: dkolesnichenko.
kpdev42 requested review of this revision.

The return value of the first call of Dump.next() was not checked. Dump.getText() returned an uninitialized string (a junk string) if the objdump did not return an usable data for the specified address range. It caused a crash or inconsistent profile data.


Repository:
  rLNT LNT

https://reviews.llvm.org/D112782

Files:
  lnt/testing/profile/cPerf.cpp


Index: lnt/testing/profile/cPerf.cpp
===================================================================
--- lnt/testing/profile/cPerf.cpp
+++ lnt/testing/profile/cPerf.cpp
@@ -365,6 +365,7 @@
 
   void reset(Map *M, uint64_t Start, uint64_t Stop) {
     ThisAddress = 0;
+    ThisText = "";
     if (Stream) {
       fclose(Stream);
       wait(NULL);
@@ -396,6 +397,7 @@
       ssize_t Len = getline(&Line, &LineLen, Stream);
       if (Len == -1) {
         ThisAddress = EndAddress;
+        ThisText = "";
         return;
       }
       char *TokBuf;
@@ -757,10 +759,9 @@
     uint64_t Adjust) {
   ObjdumpOutput Dump(Objdump, BinaryCacheRoot);
   Dump.reset(&M, Sym.Start, Sym.End);
-  Dump.next();
 
   emitFunctionStart(Sym.Name);
-  for (uint64_t I = Sym.Start; I < Sym.End; I = Dump.next()) {
+  for (uint64_t I = Dump.next(); I < Sym.End; I = Dump.next()) {
     auto PC = Event->first - Adjust;
 
     auto Text = Dump.getText();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112782.383249.patch
Type: text/x-patch
Size: 944 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211029/0024ab11/attachment-0001.bin>


More information about the llvm-commits mailing list