From d5d694114aefd691c053ca794ef139e4bc80b679 Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Mon, 28 Jul 2025 17:16:37 +0200 Subject: truncate_file: restricted file permissions upon creation --- FICS/utils.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'FICS/utils.c') diff --git a/FICS/utils.c b/FICS/utils.c index 785d1a1..24cdcd7 100644 --- a/FICS/utils.c +++ b/FICS/utils.c @@ -855,8 +855,17 @@ truncate_file(char *file, int lines) fclose(fp); if (trunc) { - if ((fp = fopen(file, "w")) == NULL) { - warn("%s: fopen", __func__); + int fd; + + errno = 0; + fd = open(file, O_WRONLY|O_CREAT, S_IWUSR|S_IRUSR); + + if (fd < 0) { + warn("%s: open", __func__); + return 1; + } else if ((fp = fdopen(fd, "w")) == NULL) { + warn("%s: fdopen", __func__); + close(fd); return 1; } -- cgit v1.2.3