From 9ddfc63fb8efeb84c9a9ff16396b689c1565b4a6 Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Mon, 28 Jul 2025 18:26:06 +0200 Subject: Restricted file permissions upon creation --- FICS/ratings.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'FICS/ratings.c') diff --git a/FICS/ratings.c b/FICS/ratings.c index 9410429..0ac1d9c 100644 --- a/FICS/ratings.c +++ b/FICS/ratings.c @@ -410,12 +410,20 @@ save_ratings(void) { FILE *fp; char fname[MAX_FILENAME_SIZE] = { '\0' }; + int fd; snprintf(fname, sizeof fname, "%s/newratingsV%d_data", stats_dir, STATS_VERSION); - if ((fp = fopen(fname, "w")) == NULL) { + errno = 0; + fd = open(fname, O_WRONLY|O_CREAT, S_IWUSR|S_IRUSR); + + if (fd < 0) { + warn("%s: can't write ratings data", __func__); + return; + } else if ((fp = fdopen(fd, "w")) == NULL) { warn("%s: can't write ratings data", __func__); + close(fd); return; } -- cgit v1.2.3