From: Pavel Sanda Date: Sat, 6 Mar 2010 14:57:16 +0000 (+0000) Subject: Fix unsafe use of fixed width arrays. X-Git-Tag: 2.0.0~3895 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=a7b921aeeba67805a4057eba1cadac45e480e855;p=features.git Fix unsafe use of fixed width arrays. Fix crash when MathMatrix has more than 80 columns Patch from John McCabe-Dansted, approved from Andre. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33641 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/VSpace.cpp b/src/VSpace.cpp index 19f6af41a1..06799263f4 100644 --- a/src/VSpace.cpp +++ b/src/VSpace.cpp @@ -246,14 +246,14 @@ bool isValidGlueLength(string const & data, GlueLength * result) int pattern_index = 0; int table_index = 0; - char pattern[20]; + char pattern[22]; // 20 + 1 for pattern[20], + 1 for '\0' number_index = 1; unit_index = 1; // entries at index 0 are sentinels // construct "pattern" from "data" while (!isEndOfData(buffer)) { - if (pattern_index > 20) + if (pattern_index > (sizeof(pattern) - 2)) return false; pattern[pattern_index] = nextToken(buffer); if (pattern[pattern_index] == 'E') diff --git a/src/frontends/qt4/GuiAlert.cpp b/src/frontends/qt4/GuiAlert.cpp index 2a8affa33a..f4d4309f70 100644 --- a/src/frontends/qt4/GuiAlert.cpp +++ b/src/frontends/qt4/GuiAlert.cpp @@ -108,8 +108,9 @@ static docstring const formatted(docstring const & text) void noAppDialog(QString const & title, QString const & msg, QMessageBox::Icon mode) { int argc = 1; - char * argv[1]; - QApplication app(argc, argv); + const char *argv[] = { "lyx", 0 }; + + QApplication app(argc, (char**)argv); switch (mode) { case QMessageBox::Information: QMessageBox::information(0, title, msg); break; diff --git a/src/frontends/qt4/GuiMathMatrix.cpp b/src/frontends/qt4/GuiMathMatrix.cpp index 25555f7b01..6be67b333a 100644 --- a/src/frontends/qt4/GuiMathMatrix.cpp +++ b/src/frontends/qt4/GuiMathMatrix.cpp @@ -66,13 +66,8 @@ GuiMathMatrix::GuiMathMatrix(GuiView & lv) void GuiMathMatrix::columnsChanged(int) { - char h_align_str[80] = "c"; int const nx = int(columnsSB->value()); - for (int i = 0; i < nx; ++i) - h_align_str[i] = 'c'; - - h_align_str[nx] = '\0'; - halignED->setText(h_align_str); + halignED->setText(QString(nx, 'c')); } diff --git a/src/support/filetools.cpp b/src/support/filetools.cpp index 48ba7ef785..7f00ebfb8c 100644 --- a/src/support/filetools.cpp +++ b/src/support/filetools.cpp @@ -739,8 +739,7 @@ docstring const makeDisplayPath(string const & path, unsigned int threshold) bool readLink(FileName const & file, FileName & link) { #ifdef HAVE_READLINK - char linkbuffer[512]; - // Should be PATH_MAX but that needs autconf support + char linkbuffer[PATH_MAX + 1]; string const encoded = file.toFilesystemEncoding(); int const nRead = ::readlink(encoded.c_str(), linkbuffer, sizeof(linkbuffer) - 1);