From d77955652d472e8f0ade91ffa5cf51dd1c7a3f14 Mon Sep 17 00:00:00 2001 From: kreatordxx <> Date: Sat, 19 Jan 2008 00:30:02 +0000 Subject: [PATCH] fix potential bad memory access in change_filename_extension --- CHANGELOG.txt | 1 + misc/strutil.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index bdd28583f..7c5f0619b 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -5,6 +5,7 @@ D2X-Rebirth Changelog main/network.c: fix typo causing compiler error on bigendian computers 2d/font.c: make sure a font header only takes up sizeof(grs_font) memory, not sizeof(grs_font) squared arch/ogl/gr.c, arch/ogl/include/internal.h, arch/ogl/sdlgl.c, include/args.h, main/inferno.c, main/menu.c, main/newdemo.c, main/newmenu.c, misc/args.c: Removed SDL Gammaramp code (obsolete); Improvements on Demo code +misc/strutil.c: fix potential bad memory access in change_filename_extension 20080108 -------- diff --git a/misc/strutil.c b/misc/strutil.c index e6ee69a39..2d58ce67a 100644 --- a/misc/strutil.c +++ b/misc/strutil.c @@ -142,11 +142,13 @@ void change_filename_extension( char *dest, char *src, char *ext ) p = strrchr(dest, '.'); if (!p) { + if (strlen(dest) > FILENAME_LEN - 5) + return; // a non-opened file is better than a bad memory access + p = dest + strlen(dest); *p = '.'; } - Assert((p + strlen(ext)) - dest < FILENAME_LEN); strcpy(p+1,ext); }