diff --git a/Makefile b/Makefile index dd205f1b70..32c396b50a 100644 --- a/Makefile +++ b/Makefile @@ -971,13 +971,15 @@ else $(EXE): $(O_FILES) $(MIO0_FILES:.mio0=.o) $(ULTRA_O_FILES) $(GODDARD_O_FILES) $(LD) -L $(BUILD_DIR) -o $@ $(O_FILES) $(ULTRA_O_FILES) $(GODDARD_O_FILES) $(LDFLAGS) - # Copying the dynamically linked DLL files + # Copying the dynamically linked DLL files (Windows only) + ifeq ($(TARGET_WINDOWS),1) $(shell a=$(PATH); b=$${a%%:*}; cp "$${b}/SDL2.dll" "$(BUILD_DIR)/SDL2.dll") ifeq ($(TARGET_32BIT),1) $(shell a=$(PATH); b=$${a%%:*}; cp "$${b}/libgcc_s_dw2-1.dll" "$(BUILD_DIR)/libgcc_s_dw2-1.dll") $(shell a=$(PATH); b=$${a%%:*}; cp "$${b}/libwinpthread-1.dll" "$(BUILD_DIR)/libwinpthread-1.dll") endif + endif endif .PHONY: all clean distclean default diff test load libultra diff --git a/src/pc/gfx/gfx_pc.c b/src/pc/gfx/gfx_pc.c index 6487ef507d..f450429cb1 100644 --- a/src/pc/gfx/gfx_pc.c +++ b/src/pc/gfx/gfx_pc.c @@ -844,7 +844,12 @@ static void import_texture(int tile) { #ifdef TARGET_MACOS _NSGetExecutablePath(exec_path, &size); #else - readlink("/proc/self/exe", exec_path, size); + ssize_t len = readlink("/proc/self/exe", exec_path, size - 1); + if (len >= 0) { + exec_path[len] = '\0'; + } else { + exec_path[0] = '\0'; + } #endif dir = dirname(exec_path); const char gfx_path[1024]; diff --git a/tools/skyconv.c b/tools/skyconv.c index 4a4389aa46..7509108098 100644 --- a/tools/skyconv.c +++ b/tools/skyconv.c @@ -230,16 +230,35 @@ void write_tiles() { exit(EXIT_FAILURE); } - strcat(buffer, "/"); + size_t dirLength = strlen(buffer); + if (dirLength + 1 >= sizeof(buffer)) { + fprintf(stderr, "err: Image dir path too long\n"); + exit(EXIT_FAILURE); + } + + buffer[dirLength++] = '/'; + buffer[dirLength] = '\0'; switch(type) { case Skybox: + if (dirLength + strlen(skyboxName) >= sizeof(buffer)) { + fprintf(stderr, "err: Skybox name path too long\n"); + exit(EXIT_FAILURE); + } strcat(buffer, skyboxName); break; case Cake: + if (dirLength + strlen("cake") >= sizeof(buffer)) { + fprintf(stderr, "err: Cake path too long\n"); + exit(EXIT_FAILURE); + } strcat(buffer, "cake"); break; case CakeEU: + if (dirLength + strlen("cake_eu") >= sizeof(buffer)) { + fprintf(stderr, "err: Cake path too long\n"); + exit(EXIT_FAILURE); + } strcat(buffer, "cake_eu"); break; default: @@ -247,12 +266,22 @@ void write_tiles() { break; } - int dirLength = strlen(buffer); + dirLength = strlen(buffer); char *filename = buffer + dirLength; + size_t remaining = sizeof(buffer) - dirLength; + if (remaining == 0) { + fprintf(stderr, "err: Image dir path too long\n"); + exit(EXIT_FAILURE); + } + for (int i = 0; i < props.numRows * props.numCols; i++) { if (!tiles[i].useless) { *filename = 0; - snprintf(filename, PATH_MAX, ".%d.rgba16.png", tiles[i].pos); + int written = snprintf(filename, remaining, ".%d.rgba16.png", tiles[i].pos); + if (written < 0 || (size_t) written >= remaining) { + fprintf(stderr, "err: Tile filename too long\n"); + exit(EXIT_FAILURE); + } rgba2png(buffer, tiles[i].px, props.tileWidth, props.tileHeight); } } @@ -676,4 +705,4 @@ int main(int argc, char *argv[]) { return EXIT_SUCCESS; -} \ No newline at end of file +}