From b7b4269455d7102075785539d33705dbf567d4e1 Mon Sep 17 00:00:00 2001 From: Lassi Kortela Date: Fri, 9 Aug 2019 20:14:42 +0300 Subject: [PATCH] Replace strcpy() and strcat() with safer functions --- c/flisp.c | 2 +- c/flmain.c | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/c/flisp.c b/c/flisp.c index b920d45..d9b4f86 100644 --- a/c/flisp.c +++ b/c/flisp.c @@ -283,7 +283,7 @@ static struct symbol *mk_symbol(char *str) } sym->type = sym->dlcache = NULL; sym->hash = memhash32(str, len) ^ 0xAAAAAAAA; - strcpy(&sym->name[0], str); + memcpy(&sym->name[0], str, len + 1); return sym; } diff --git a/c/flmain.c b/c/flmain.c index d1f1258..506fed8 100644 --- a/c/flmain.c +++ b/c/flmain.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -39,17 +40,19 @@ extern value_t fl_file(value_t *args, uint32_t nargs); int main(int argc, char *argv[]) { char fname_buf[1024]; + const char *bootfile = "flisp.boot"; fl_init(512 * 1024); fname_buf[0] = '\0'; value_t str = symbol_value(symbol("*install-dir*")); char *exedir = (str == UNBOUND ? NULL : cvalue_data(str)); - if (exedir != NULL) { - strcat(fname_buf, exedir); - strcat(fname_buf, PATHSEPSTRING); + if (exedir == NULL) { + snprintf(fname_buf, sizeof(fname_buf), "%s", bootfile); + } else { + snprintf(fname_buf, sizeof(fname_buf), "%s%s%s", exedir, + PATHSEPSTRING, bootfile); } - strcat(fname_buf, "flisp.boot"); value_t args[2]; fl_gc_handle(&args[0]);