diff options
author | Markus Uhlin <markus@nifty-networks.net> | 2025-07-28 17:16:37 +0200 |
---|---|---|
committer | Markus Uhlin <markus@nifty-networks.net> | 2025-07-28 17:16:37 +0200 |
commit | d5d694114aefd691c053ca794ef139e4bc80b679 (patch) | |
tree | c12a556ca0a46ac1df859a984c265c16dce3bc8f /FICS/utils.c | |
parent | 73dbfcd1e2022b9522813cf0cdf80495da6f5ee7 (diff) |
truncate_file: restricted file permissions upon creation
Diffstat (limited to 'FICS/utils.c')
-rw-r--r-- | FICS/utils.c | 13 |
1 files changed, 11 insertions, 2 deletions
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; } |