Now checks that the line being read in does not exceed MAX_LINE_BUFFER_SIZE length, avoiding a crash whenever a long line is read in from a .tex file. An error is now generated if the line is too long, and line line is truncated at MAX_LINE_BUFFER_SIZE characters.
All error messages are now constructed with wxStrings rather than char arrays.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8989
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
buf[0] = 0;
while (ch != EOF && ch != 10)
{
buf[0] = 0;
while (ch != EOF && ch != 10)
{
- if (((i == 14) && (strncmp(buf, "\\end{verbatim}", 14) == 0)) ||
- ((i == 16) && (strncmp(buf, "\\end{toocomplex}", 16) == 0)))
+ if (bufIndex >= MAX_LINE_BUFFER_SIZE)
+ {
+ wxString errBuf;
+ errBuf.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
+ LineNumbers[CurrentInputIndex], (const char*) currentFileName.c_str(),MAX_LINE_BUFFER_SIZE);
+ OnError((char *)errBuf.c_str());
+ return FALSE;
+ }
+
+ if (((bufIndex == 14) && (strncmp(buf, "\\end{verbatim}", 14) == 0)) ||
+ ((bufIndex == 16) && (strncmp(buf, "\\end{toocomplex}", 16) == 0)))
readInVerbatim = FALSE;
ch = getc(Inputs[CurrentInputIndex]);
readInVerbatim = FALSE;
ch = getc(Inputs[CurrentInputIndex]);
if (rightCurly > leftCurly)
{
wxString errBuf;
if (rightCurly > leftCurly)
{
wxString errBuf;
- errBuf.Printf("An extra right Curly brace ('}') was detected at line %lu inside file %s",LineNumbers[CurrentInputIndex], (const char*) currentFileName.c_str());
+ errBuf.Printf("An extra right curly brace ('}') was detected at line %lu inside file %s",LineNumbers[CurrentInputIndex], (const char*) currentFileName.c_str());
OnError((char *)errBuf.c_str());
// Reduce the count of right curly braces, so the mismatched count
OnError((char *)errBuf.c_str());
// Reduce the count of right curly braces, so the mismatched count
if ((ch1 == 10) || (ch1 == 13))
{
// Eliminate newline (10) following DOS linefeed
if ((ch1 == 10) || (ch1 == 13))
{
// Eliminate newline (10) following DOS linefeed
- if (ch1 == 13) ch1 = getc(Inputs[CurrentInputIndex]);
- buf[i] = 0;
+ if (ch1 == 13)
+ ch1 = getc(Inputs[CurrentInputIndex]);
+ buf[bufIndex] = 0;
IncrementLineNumber();
// strcat(buf, "\\par\n");
// i += 6;
IncrementLineNumber();
// strcat(buf, "\\par\n");
// i += 6;
+ if (bufIndex+5 >= MAX_LINE_BUFFER_SIZE)
+ {
+ wxString errBuf;
+ errBuf.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
+ LineNumbers[CurrentInputIndex], (const char*) currentFileName.c_str(),MAX_LINE_BUFFER_SIZE);
+ OnError((char *)errBuf.c_str());
+ return FALSE;
+ }
}
else
{
ungetc(ch1, Inputs[CurrentInputIndex]);
}
else
{
ungetc(ch1, Inputs[CurrentInputIndex]);
+ if (bufIndex >= MAX_LINE_BUFFER_SIZE)
+ {
+ wxString errBuf;
+ errBuf.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
+ LineNumbers[CurrentInputIndex], (const char*) currentFileName.c_str(),MAX_LINE_BUFFER_SIZE);
+ OnError((char *)errBuf.c_str());
+ return FALSE;
+ }
+
+ buf[bufIndex] = ch;
+ bufIndex ++;
case 0xd6: // Ö
case 0xc4: // Ä
case 0xdc: // Ü
case 0xd6: // Ö
case 0xc4: // Ä
case 0xdc: // Ü
- buf[i++]='\\';
- buf[i++]='"';
- buf[i++]='{';
+ if (bufIndex+5 >= MAX_LINE_BUFFER_SIZE)
+ {
+ wxString errBuf;
+ errBuf.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
+ LineNumbers[CurrentInputIndex], (const char*) currentFileName.c_str(),MAX_LINE_BUFFER_SIZE);
+ OnError((char *)errBuf.c_str());
+ return FALSE;
+ }
+ buf[bufIndex++]='\\';
+ buf[bufIndex++]='"';
+ buf[bufIndex++]='{';
- case 0xf6:buf[i++]='o';break; // ö
- case 0xe4:buf[i++]='a';break; // ä
- case 0xfc:buf[i++]='u';break; // ü
- case 0xd6:buf[i++]='O';break; // Ö
- case 0xc4:buf[i++]='A';break; // Ä
- case 0xdc:buf[i++]='U';break; // Ü
+ case 0xf6:buf[bufIndex++]='o';break; // ö
+ case 0xe4:buf[bufIndex++]='a';break; // ä
+ case 0xfc:buf[bufIndex++]='u';break; // ü
+ case 0xd6:buf[bufIndex++]='O';break; // Ö
+ case 0xc4:buf[bufIndex++]='A';break; // Ä
+ case 0xdc:buf[bufIndex++]='U';break; // Ü
- buf[i++]='\\';
- buf[i++]='s';
- buf[i++]='s';
- buf[i++]='\\';
- buf[i++]='/';
+ if (bufIndex+5 >= MAX_LINE_BUFFER_SIZE)
+ {
+ wxString errBuf;
+ errBuf.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
+ LineNumbers[CurrentInputIndex], (const char*) currentFileName.c_str(),MAX_LINE_BUFFER_SIZE);
+ OnError((char *)errBuf.c_str());
+ return FALSE;
+ }
+ buf[bufIndex++]='\\';
+ buf[bufIndex++]='s';
+ buf[bufIndex++]='s';
+ buf[bufIndex++]='\\';
+ buf[bufIndex++]='/';
+ if (bufIndex >= MAX_LINE_BUFFER_SIZE)
+ {
+ wxString errBuf;
+ errBuf.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
+ LineNumbers[CurrentInputIndex], (const char*) currentFileName.c_str(),MAX_LINE_BUFFER_SIZE);
+ OnError((char *)errBuf.c_str());
+ return FALSE;
+ }
+ buf[bufIndex++] = ch;
+ } // switch
+ } // else
fclose(Inputs[CurrentInputIndex]);
Inputs[CurrentInputIndex] = NULL;
if (CurrentInputIndex > 0)
fclose(Inputs[CurrentInputIndex]);
Inputs[CurrentInputIndex] = NULL;
if (CurrentInputIndex > 0)
if (ch == 10)
IncrementLineNumber();
}
if (ch == 10)
IncrementLineNumber();
}
// Strip out comment environment
if (strncmp(buf, "\\begin{comment}", 15) == 0)
// Strip out comment environment
if (strncmp(buf, "\\begin{comment}", 15) == 0)
int wordLen = 14;
char *fileName = buf + wordLen + 1;
int wordLen = 14;
char *fileName = buf + wordLen + 1;
buf[j] = 0;
// thing}\par -- eliminate the \par!
buf[j] = 0;
// thing}\par -- eliminate the \par!
- if (buf[j-1] == '}') buf[j-1] = 0; // Ignore final brace
+ if (buf[j-1] == '}')
+ buf[j-1] = 0; // Ignore final brace
wxString actualFile = TexPathList.FindValidPath(fileName);
currentFileName = actualFile;
if (actualFile == "")
{
wxString actualFile = TexPathList.FindValidPath(fileName);
currentFileName = actualFile;
if (actualFile == "")
{
- char errBuf[300];
- strcpy(errBuf, "Could not find file: ");
- strncat(errBuf, fileName, 100);
- OnError(errBuf);
+ wxString errBuf;
+ errBuf.Printf("Could not find file: %s",fileName);
+ OnError((char *)errBuf.c_str());
informStr.Printf("Processing: %s",actualFile.c_str());
OnInform((char *)informStr.c_str());
CurrentInputIndex ++;
informStr.Printf("Processing: %s",actualFile.c_str());
OnInform((char *)informStr.c_str());
CurrentInputIndex ++;
Inputs[CurrentInputIndex] = fopen(actualFile, "r");
LineNumbers[CurrentInputIndex] = 1;
if (FileNames[CurrentInputIndex])
Inputs[CurrentInputIndex] = fopen(actualFile, "r");
LineNumbers[CurrentInputIndex] = 1;
if (FileNames[CurrentInputIndex])
char *fileName = buf + wordLen + 1;
char *fileName = buf + wordLen + 1;
buf[j] = 0;
// \input{thing}\par -- eliminate the \par!
buf[j] = 0;
// \input{thing}\par -- eliminate the \par!
- if (buf[j-1] == '}') buf[j-1] = 0; // Ignore final brace
+ if (buf[j-1] == '}')
+ buf[j-1] = 0; // Ignore final brace
// Remove backslashes from name
wxString fileNameStr(fileName);
// Remove backslashes from name
wxString fileNameStr(fileName);
- char errBuf[300];
- strcpy(errBuf, "Could not find file: ");
- strncat(errBuf, fileName, 100);
- OnError(errBuf);
+ wxString errBuf;
+ errBuf.Printf("Could not find file: %s",fileName);
+ OnError((char *)errBuf.c_str());
informStr.Printf("Processing: %s",actualFile.c_str());
OnInform((char *)informStr.c_str());
CurrentInputIndex ++;
informStr.Printf("Processing: %s",actualFile.c_str());
OnInform((char *)informStr.c_str());
CurrentInputIndex ++;
Inputs[CurrentInputIndex] = fopen(actualFile, "r");
LineNumbers[CurrentInputIndex] = 1;
if (FileNames[CurrentInputIndex])
Inputs[CurrentInputIndex] = fopen(actualFile, "r");
LineNumbers[CurrentInputIndex] = 1;
if (FileNames[CurrentInputIndex])
if (!Inputs[CurrentInputIndex])
{
if (!Inputs[CurrentInputIndex])
{
- char errBuf[300];
- sprintf(errBuf, "Could not open include file %s", (const char*) actualFile);
+ wxString errBuf;
+ errBuf.Printf("Could not open include file %s", (const char*) actualFile);
+ OnError((char *)errBuf.c_str());
}
}
bool succ = read_a_line(buf);
}
}
bool succ = read_a_line(buf);
#endif
return (ch == EOF);
#endif
return (ch == EOF);
void MacroError(char *buffer)
{
void MacroError(char *buffer)
{
char macroBuf[200];
macroBuf[0] = '\\';
int i = 1;
char macroBuf[200];
macroBuf[0] = '\\';
int i = 1;
if (i > 20)
macroBuf[20] = 0;
if (i > 20)
macroBuf[20] = 0;
- sprintf(errBuf, "Could not find macro: %s at line %d, file %s",
+ errBuf.Printf("Could not find macro: %s at line %d, file %s",
macroBuf, (int)(LineNumbers[CurrentInputIndex]-1), FileNames[CurrentInputIndex]);
macroBuf, (int)(LineNumbers[CurrentInputIndex]-1), FileNames[CurrentInputIndex]);
+ OnError((char *)errBuf.c_str());
while (!eof && (strncmp(buffer, "\\end{verbatim}", 14) != 0) &&
(strncmp(buffer, "\\end{toocomplex}", 16) != 0)
)
while (!eof && (strncmp(buffer, "\\end{verbatim}", 14) != 0) &&
(strncmp(buffer, "\\end{toocomplex}", 16) != 0)
)
strcat(BigBuffer, buffer);
buf_ptr += strlen(buffer);
eof = read_a_line(buffer);
strcat(BigBuffer, buffer);
buf_ptr += strlen(buffer);
eof = read_a_line(buffer);
eof = read_a_line(buffer);
buf_ptr = 0;
eof = read_a_line(buffer);
buf_ptr = 0;
if (line_buffer)
delete line_buffer;
if (line_buffer)
delete line_buffer;
-#ifdef __WXMSW__
- line_buffer = new char[600];
-#else
- line_buffer = new char[11000];
-#endif
+
+ line_buffer = new char[MAX_LINE_BUFFER_SIZE];
Inputs[0] = fopen(filename, "r");
LineNumbers[0] = 1;
Inputs[0] = fopen(filename, "r");
LineNumbers[0] = 1;
{
if (!ReadBib((char*) (const char*) actualFile))
{
{
if (!ReadBib((char*) (const char*) actualFile))
{
- char buf[300];
- sprintf(buf, ".bib file %s not found or malformed", (const char*) actualFile);
- OnError(buf);
+ wxString errBuf;
+ errBuf.Printf(".bib file %s not found or malformed", (const char*) actualFile);
+ OnError((char *)errBuf.c_str());
- char buf[300];
- sprintf(buf, ".bib file %s not found", fileBuf);
- OnError(buf);
+ wxString errBuf;
+ errBuf.Printf(".bib file %s not found", fileBuf);
+ OnError((char *)errBuf.c_str());
}
bibFile = ParseMultifieldString(allFiles, &pos);
}
}
bibFile = ParseMultifieldString(allFiles, &pos);
}