Skip to content

Commit 2e06260

Browse files
committed
client: fix ConvertString overflow
1 parent 135e984 commit 2e06260

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

cl_dll/input.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)