From b5bc47ea2f9ccc9d5439b4df8ea86c003e0a723b Mon Sep 17 00:00:00 2001 From: SarahW Date: Tue, 14 Jul 2020 19:42:20 +0100 Subject: [PATCH] Fix buffer overflow warnings in OpenGL 3.0 video display file handling Patch from davefiddes. Original commit message : This fixes issues reported by gcc 10 with the size of various filename buffers when concatenating strings into them. Tests: - Build cleanly with gcc 10 - Run a Pentium MMX Win98 machine and use custom GLSLP shader --- src/wx-glslp-parser.c | 4 ++-- src/wx-glslp-parser.h | 2 +- src/wx-sdl2-video-gl3.c | 2 +- src/wx-sdl2.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/wx-glslp-parser.c b/src/wx-glslp-parser.c index dd1fec1..387918a 100644 --- a/src/wx-glslp-parser.c +++ b/src/wx-glslp-parser.c @@ -163,9 +163,9 @@ void get_glslp_name(const char* f, char* s, int size) glslp_t* glslp_parse(const char* f) { int i, j, len, sublen; - char s[512], t[512], z[512]; + char s[512], t[512], z[540]; - s[511] = 0; + memset(s, 0, sizeof(s)); if (endswith(f, ".glsl")) return glsl_parse(f); diff --git a/src/wx-glslp-parser.h b/src/wx-glslp-parser.h index 59ae315..970eb35 100644 --- a/src/wx-glslp-parser.h +++ b/src/wx-glslp-parser.h @@ -22,7 +22,7 @@ struct texture { }; struct shader { - char shader_fn[512]; + char shader_fn[1024]; char* shader_program; char alias[64]; int filter_linear; diff --git a/src/wx-sdl2-video-gl3.c b/src/wx-sdl2-video-gl3.c index f8895b3..3ce76e1 100644 --- a/src/wx-sdl2-video-gl3.c +++ b/src/wx-sdl2-video-gl3.c @@ -559,7 +559,7 @@ static glsl_t* load_glslp(glsl_t* glsl, int num_shader, const char* f) if (p) { char path[512]; - char file[512]; + char file[1024]; int failed = 0; strcpy(path, f); char* filename = get_filename(path); diff --git a/src/wx-sdl2.c b/src/wx-sdl2.c index d230416..aedfb44 100644 --- a/src/wx-sdl2.c +++ b/src/wx-sdl2.c @@ -504,7 +504,7 @@ int pc_main(int argc, char** argv) paths_init(); #ifdef __linux__ - char s[512]; + char s[1024]; /* create directories if they don't exist */ if (!wx_setup(pcem_path)) return FALSE;