[llvm-commits] [llvm] r129214 - /llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp
Benjamin Kramer
benny.kra at googlemail.com
Sat Apr 9 07:06:12 PDT 2011
Author: d0k
Date: Sat Apr 9 09:06:12 2011
New Revision: 129214
URL: http://llvm.org/viewvc/llvm-project?rev=129214&view=rev
Log:
Fix potential buffer overflow on win32.
Modified:
llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp
Modified: llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp?rev=129214&r1=129213&r2=129214&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp (original)
+++ llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp Sat Apr 9 09:06:12 2011
@@ -128,9 +128,9 @@
} // namespace
//
-// LLVMDisasmInstruction() disassmbles a single instruction using the
+// LLVMDisasmInstruction() disassembles a single instruction using the
// disassembler context specified in the parameter DC. The bytes of the
-// instuction are specified in the parameter Bytes, and contains at least
+// instruction are specified in the parameter Bytes, and contains at least
// BytesSize number of bytes. The instruction is at the address specified by
// the PC parameter. If a valid instruction can be disassembled its string is
// returned indirectly in OutString which whos size is specified in the
@@ -155,16 +155,13 @@
std::string InsnStr;
raw_string_ostream OS(InsnStr);
- raw_ostream &Out = OS;
- IP->printInst(&Inst, Out);
+ IP->printInst(&Inst, OS);
+ OS.flush();
+
+ size_t OutputSize = std::min(OutStringSize-1, InsnStr.size());
+ std::memcpy(OutString, InsnStr.data(), OutputSize);
+ OutString[OutputSize] = '\0'; // Terminate string.
- std::string p;
- p = OS.str();
-#ifdef LLVM_ON_WIN32
- sprintf(OutString, "%s", p.c_str());
-#else
- snprintf(OutString, OutStringSize, "%s", p.c_str());
-#endif
return Size;
}
More information about the llvm-commits
mailing list