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

qcommon: fix potential buffer overflow in COM_StripFilename #350

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cgame/cg_sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,7 @@ qboolean CG_SpeakerEditor_NoiseEdit_KeyDown(panel_button_t *button, int key)
int i, numfiles, filelen;
char *fileptr;

COM_StripFilename(button->text, dirname);
COM_StripFilename(button->text, dirname, sizeof(dirname));
Q_strncpyz(filename, COM_SkipPath(button->text), sizeof(filename));

if (!Q_stricmp(button->text, dirname))
Expand Down
19 changes: 9 additions & 10 deletions src/qcommon/q_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,16 @@ void COM_FixPath(char *pathname)
*/
char *COM_SkipPath(char *pathname)
{
char *last = pathname;
char *last = strrchr(pathname, '/');

while (*pathname)
if (last)
{
if (*pathname == '/')
{
last = pathname + 1;
}
pathname++;
return last + 1;
}
else
{
return pathname;
}
return last;
}

/**
Expand Down Expand Up @@ -166,11 +165,11 @@ qboolean COM_CompareExtension(const char *in, const char *ext)
* @param[in] in
* @param[out] out
*/
void COM_StripFilename(const char *in, char *out)
void COM_StripFilename(const char *in, char *out, size_t outsize)
{
char *end;

Q_strncpyz(out, in, strlen(in) + 1);
Q_strncpyz(out, in, outsize);
end = COM_SkipPath(out);
*end = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/qcommon/q_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ void COM_FixPath(char *pathname);
const char *COM_GetExtension(const char *name);
void COM_StripExtension(const char *in, char *out, int destsize);
qboolean COM_CompareExtension(const char *in, const char *ext);
void COM_StripFilename(const char *in, char *out);
void COM_StripFilename(const char *in, char *out, size_t outsize);

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

Expand Down