Skip to content

Commit 5d58367

Browse files
author
Pavel Kosov
committed
[LNT] Fixed possible crash or junk data in cPerf
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. OS Laboratory. Huawei Russian Research Institute. Saint-Petersburg Reviewed By: thopre Differential Revision: https://reviews.llvm.org/D112782
1 parent 28b6eb3 commit 5d58367

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lnt/testing/profile/cPerf.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ class ObjdumpOutput {
365365

366366
void reset(Map *M, uint64_t Start, uint64_t Stop) {
367367
ThisAddress = 0;
368+
ThisText = "";
368369
if (Stream) {
369370
fclose(Stream);
370371
wait(NULL);
@@ -396,6 +397,7 @@ class ObjdumpOutput {
396397
ssize_t Len = getline(&Line, &LineLen, Stream);
397398
if (Len == -1) {
398399
ThisAddress = EndAddress;
400+
ThisText = "";
399401
return;
400402
}
401403
char *TokBuf;
@@ -757,10 +759,9 @@ void PerfReader::emitSymbol(
757759
uint64_t Adjust) {
758760
ObjdumpOutput Dump(Objdump, BinaryCacheRoot);
759761
Dump.reset(&M, Sym.Start, Sym.End);
760-
Dump.next();
761762

762763
emitFunctionStart(Sym.Name);
763-
for (uint64_t I = Sym.Start; I < Sym.End; I = Dump.next()) {
764+
for (uint64_t I = Dump.next(); I < Sym.End; I = Dump.next()) {
764765
auto PC = Event->first - Adjust;
765766

766767
auto Text = Dump.getText();

0 commit comments

Comments
 (0)