Skip to content

Commit 41a6f42

Browse files
committed
THelpTopic: prevent out-of-bounds accesses in TParagraph::text
Valgrind reports the 'text' field of TParagraph being read one byte beyond the allocated memory in functions like scan() and isBlank(), for no obvious reason. The implementation is probably assuming strings are null-terminated when they are not. I guess the easiest workaround is to force a null terminator.
1 parent b3f703e commit 41a6f42

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

source/tvision/helpbase.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,16 @@ void THelpTopic::readParagraphs( ipstream& s )
103103

104104
s >> i;
105105
pp = &paragraphs;
106-
while ( i > 0)
106+
while (i > 0)
107107
{
108108
s >> size;
109109
*pp = new TParagraph;
110-
(*pp)->text = new char[size];
110+
(*pp)->text = new char[size + 1];
111111
(*pp)->size = (ushort) size;
112-
s >> temp;
112+
s >> temp;
113113
(*pp)->wrap = Boolean(temp);
114114
s.readBytes((*pp)->text, (*pp)->size);
115+
(*pp)->text[(*pp)->size] = '\0';
115116
pp = &((*pp)->next);
116117
--i;
117118
}

0 commit comments

Comments
 (0)