]> git.lyx.org Git - features.git/commitdiff
Fix unsafe use of fixed width arrays.
authorPavel Sanda <sanda@lyx.org>
Sat, 6 Mar 2010 14:57:16 +0000 (14:57 +0000)
committerPavel Sanda <sanda@lyx.org>
Sat, 6 Mar 2010 14:57:16 +0000 (14:57 +0000)
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

src/VSpace.cpp
src/frontends/qt4/GuiAlert.cpp
src/frontends/qt4/GuiMathMatrix.cpp
src/support/filetools.cpp

index 19f6af41a1f638d282263e6f6be1ef01ccdf19a3..06799263f4e01a2049ff40d51e3941a6d446d978 100644 (file)
@@ -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')
index 2a8affa33a6cfc1b2927bf28d23695d49487892c..f4d4309f702d6e405e85d9d3bb3752ebf7475b50 100644 (file)
@@ -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;
index 25555f7b01d76a2a740598d4467b264dc0181ab9..6be67b333aa15d9bdeb0d1b557521dbade761a13 100644 (file)
@@ -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'));
 }
 
 
index 48ba7ef785ba00463e1df7126883a0fac3abf780..7f00ebfb8cb1fbae95a0ee1b6d55feb5f7463d95 100644 (file)
@@ -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);