diff --git a/mozglue/misc/StackWalk.cpp b/mozglue/misc/StackWalk.cpp index 78d452a7198f..c63b642c79eb 100644 --- a/mozglue/misc/StackWalk.cpp +++ b/mozglue/misc/StackWalk.cpp @@ -6,6 +6,7 @@ /* API for getting a stack trace of the C/C++ stack on the current thread */ +#include "mozilla/ArrayUtils.h" #include "mozilla/Assertions.h" #include "mozilla/IntegerPrintfMacros.h" #include "mozilla/StackWalk.h" @@ -800,11 +801,13 @@ MozDescribeCodeAddress(void* aPC, MozCodeAddressDetails* aDetails) if (modInfoRes) { strncpy(aDetails->library, modInfo.ModuleName, sizeof(aDetails->library)); + aDetails->library[mozilla::ArrayLength(aDetails->library) - 1] = '\0'; aDetails->loffset = (char*)aPC - (char*)modInfo.BaseOfImage; if (lineInfo.FileName) { strncpy(aDetails->filename, lineInfo.FileName, sizeof(aDetails->filename)); + aDetails->filename[mozilla::ArrayLength(aDetails->filename) - 1] = '\0'; aDetails->lineno = lineInfo.LineNumber; } } @@ -821,6 +824,7 @@ MozDescribeCodeAddress(void* aPC, MozCodeAddressDetails* aDetails) if (ok) { strncpy(aDetails->function, pSymbol->Name, sizeof(aDetails->function)); + aDetails->function[mozilla::ArrayLength(aDetails->function) - 1] = '\0'; aDetails->foffset = static_cast(displacement); } @@ -861,6 +865,7 @@ void DemangleSymbol(const char* aSymbol, if (demangled) { strncpy(aBuffer, demangled, aBufLen); + aBuffer[aBufLen - 1] = '\0'; free(demangled); } #endif // MOZ_DEMANGLE_SYMBOLS @@ -1050,6 +1055,7 @@ MozDescribeCodeAddress(void* aPC, MozCodeAddressDetails* aDetails) } strncpy(aDetails->library, info.dli_fname, sizeof(aDetails->library)); + aDetails->library[mozilla::ArrayLength(aDetails->library) - 1] = '\0'; aDetails->loffset = (char*)aPC - (char*)info.dli_fbase; const char* symbol = info.dli_sname; @@ -1062,6 +1068,7 @@ MozDescribeCodeAddress(void* aPC, MozCodeAddressDetails* aDetails) if (aDetails->function[0] == '\0') { // Just use the mangled symbol if demangling failed. strncpy(aDetails->function, symbol, sizeof(aDetails->function)); + aDetails->function[mozilla::ArrayLength(aDetails->function) - 1] = '\0'; } aDetails->foffset = (char*)aPC - (char*)info.dli_saddr;