Skip to content
This repository was archived by the owner on May 16, 2020. It is now read-only.

Commit 13326e2

Browse files
committed
qcommon: fix potential buffer overflow in COM_StripFilename
1 parent fba998d commit 13326e2

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/cgame/cg_sound.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,7 @@ qboolean CG_SpeakerEditor_NoiseEdit_KeyDown(panel_button_t *button, int key)
13271327
int i, numfiles, filelen;
13281328
char *fileptr;
13291329

1330-
COM_StripFilename(button->text, dirname);
1330+
COM_StripFilename(button->text, dirname, sizeof(dirname));
13311331
Q_strncpyz(filename, COM_SkipPath(button->text), sizeof(filename));
13321332

13331333
if (!Q_stricmp(button->text, dirname))

src/qcommon/q_shared.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,11 @@ qboolean COM_CompareExtension(const char *in, const char *ext)
166166
* @param[in] in
167167
* @param[out] out
168168
*/
169-
void COM_StripFilename(const char *in, char *out)
169+
void COM_StripFilename(const char *in, char *out, size_t outsize)
170170
{
171171
char *end;
172172

173-
Q_strncpyz(out, in, strlen(in) + 1);
173+
Q_strncpyz(out, in, outsize);
174174
end = COM_SkipPath(out);
175175
*end = 0;
176176
}

src/qcommon/q_shared.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ void COM_FixPath(char *pathname);
610610
const char *COM_GetExtension(const char *name);
611611
void COM_StripExtension(const char *in, char *out, int destsize);
612612
qboolean COM_CompareExtension(const char *in, const char *ext);
613-
void COM_StripFilename(const char *in, char *out);
613+
void COM_StripFilename(const char *in, char *out, size_t outsize);
614614

615615
void COM_DefaultExtension(char *path, size_t maxSize, const char *extension);
616616

0 commit comments

Comments
 (0)