File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -137,6 +137,7 @@ int KB_ConvertString( char *in, char **ppout )
137137 char *p;
138138 char *pOut;
139139 char *pEnd;
140+ char *pLimit = sz + sizeof ( sz ) - 1 ; // reserve one byte for the terminator
140141 const char *pBinding;
141142
142143 if ( !ppout )
@@ -145,7 +146,7 @@ int KB_ConvertString( char *in, char **ppout )
145146 *ppout = NULL ;
146147 p = in;
147148 pOut = sz;
148- while ( *p )
149+ while ( *p && pOut < pLimit )
149150 {
150151 if ( *p == ' +' )
151152 {
@@ -166,20 +167,21 @@ int KB_ConvertString( char *in, char **ppout )
166167
167168 if ( pBinding )
168169 {
169- *pOut++ = ' [' ;
170+ if ( pOut < pLimit )
171+ *pOut++ = ' [' ;
170172 pEnd = (char *)pBinding;
171173 }
172174 else
173175 {
174176 pEnd = binding;
175177 }
176178
177- while ( *pEnd )
179+ while ( *pEnd && pOut < pLimit )
178180 {
179181 *pOut++ = *pEnd++;
180182 }
181183
182- if ( pBinding )
184+ if ( pBinding && pOut < pLimit )
183185 {
184186 *pOut++ = ' ]' ;
185187 }
You can’t perform that action at this time.
0 commit comments