From ab0eb2c722872ecf33c1449e74468e362a879ba4 Mon Sep 17 00:00:00 2001 From: Kenpachi Developer Date: Sat, 8 Feb 2020 00:42:11 +0100 Subject: Update ACMD(reloadnpc) path verification --- src/map/atcommand.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 0d84dd46e..c92995977 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -4526,30 +4526,32 @@ ACMD(unloadnpc) **/ ACMD(reloadnpc) { - char file_path[100] = {'\0'}; + char format[20]; + + snprintf(format, sizeof(format), "%%%ds %%1d", MAX_DIR_PATH); + + char file_path[MAX_DIR_PATH + 1] = {'\0'}; int flag = 1; - if (*message == '\0' || (sscanf(message, "%99s %1d", file_path, &flag) < 1)) { + if (*message == '\0' || (sscanf(message, format, file_path, &flag) < 1)) { clif->message(fd, msg_fd(fd, 1516)); /// Usage: @reloadnpc {} return false; } - const char *dot = strrchr(file_path, '.'); - - if (dot == NULL) { - clif->message(fd, msg_fd(fd, 1518)); /// No file extension specified. + if (!exists(file_path)) { + clif->message(fd, msg_fd(fd, 1387)); /// File not found. return false; } - if (strlen(dot) < 4 || strncmp(dot, ".txt", 4) != 0) { - clif->message(fd, msg_fd(fd, 1519)); /// Not a TXT file. + if (!is_file(file_path)) { + clif->message(fd, msg_fd(fd, 1518)); /// Not a file. return false; } FILE *fp = fopen(file_path, "r"); if (fp == NULL) { - clif->message(fd, msg_fd(fd, 1387)); /// File not found. + clif->message(fd, msg_fd(fd, 1519)); /// Can't open file. return false; } -- cgit v1.2.3-70-g09d2