BuildROMS: Cleanup potential buffer overrun and execution with MinGW

As discussed in  #717
This commit is contained in:
Mark Pizzolato 2019-07-12 13:44:31 -07:00
parent 5e8f48034d
commit 2991ae067d
2 changed files with 12 additions and 9 deletions

View file

@ -887,7 +887,7 @@ ifeq ($(WIN32),) #*nix Environments (&& cygwin)
NETWORK_OPT = $(NETWORK_CCDEFS)
endif
ifneq (binexists,$(shell if $(TEST) -e BIN/buildtools; then echo binexists; fi))
MKDIRBIN = mkdir -p BIN/buildtools
MKDIRBIN = @mkdir -p BIN/buildtools
endif
ifeq (commit-id-exists,$(shell if $(TEST) -e .git-commit-id; then echo commit-id-exists; fi))
GIT_COMMIT_ID=$(shell grep 'SIM_GIT_COMMIT_ID' .git-commit-id | awk '{ print $$2 }')
@ -1003,8 +1003,10 @@ else
OS_CCDEFS += -fms-extensions $(PTHREADS_CCDEFS)
OS_LDFLAGS += -lm -lwsock32 -lwinmm $(PTHREADS_LDFLAGS)
EXE = .exe
ifneq (binexists,$(shell if exist BIN\buildtools echo binexists))
MKDIRBIN = if not exist BIN mkdir BIN\buildtools
ifneq (clean,$(MAKECMDGOALS))
ifneq (buildtoolsexists,$(shell if exist BIN\buildtools (echo buildtoolsexists) else (mkdir BIN\buildtools)))
MKDIRBIN=
endif
endif
ifneq ($(USE_NETWORK),)
NETWORK_OPT += -DUSE_SHARED
@ -2022,11 +2024,10 @@ ${BUILD_ROMS} :
${MKDIRBIN}
ifeq ($(WIN32),)
@if $(TEST) \( ! -e $@ \) -o \( sim_BuildROMs.c -nt $@ \) ; then ${CC} sim_BuildROMs.c $(CC_OUTSPEC); fi
@$@
else
if not exist $@ ${CC} sim_BuildROMs.c $(CC_OUTSPEC)
$(@D)\$(@F)
@if not exist $@ ${CC} sim_BuildROMs.c $(CC_OUTSPEC)
endif
@$@
#
# Individual builds

View file

@ -83,6 +83,7 @@ struct ROM_File_Descriptor {
#include <sys/utime.h>
#define utimbuf _utimbuf
#define utime _utime
#define snprintf _snprintf
#else
#include <utime.h>
#endif
@ -206,11 +207,12 @@ if ((c = strchr (array_name, '.')))
*c = '_';
if ((c = strchr (array_name, '/')))
*c = '_';
sprintf (include_filename, "%s.h", cleaned_rom_filename);
include_filename[sizeof (include_filename) - 1] = '\0';
snprintf (include_filename, sizeof (include_filename) - 1, "%s.h", cleaned_rom_filename);
if ((c = strrchr (include_filename, '/')))
sprintf (c+1, "%s.h", array_name);
else
sprintf (include_filename, "%s.h", array_name);
snprintf (include_filename, sizeof (include_filename) - 1, "%s.h", array_name);
printf ("The ROMs array entry for this new ROM image file should look something like:\n");
printf ("{\"%s\", \"%s\", %d, 0x%08X, \"%s\"}\n",
rom_filename, include_filename, (int)(statb.st_size), checksum, array_name);