aboutsummaryrefslogtreecommitdiffstats
path: root/FICS/adminproc.c
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2024-11-17 21:57:42 +0100
committerMarkus Uhlin <markus@nifty-networks.net>2024-11-17 21:57:42 +0100
commitc0230997efdfcdfbbca336f3ffaf519e307e5a2f (patch)
tree526eb460674748e4ccc3f999d59bd3f47805d4e5 /FICS/adminproc.c
parent190e6773c543c8dadece74062418de8e50f9e688 (diff)
Improved com_anews()
Diffstat (limited to 'FICS/adminproc.c')
-rw-r--r--FICS/adminproc.c40
1 files changed, 33 insertions, 7 deletions
diff --git a/FICS/adminproc.c b/FICS/adminproc.c
index 03e59cc..ac88afa 100644
--- a/FICS/adminproc.c
+++ b/FICS/adminproc.c
@@ -18,6 +18,8 @@
#include <sys/param.h>
+#include <err.h>
+
#include "adminproc.h"
#include "command.h"
#include "comproc.h"
@@ -378,6 +380,9 @@ com_anews(int p, param_list param)
return COM_OK;
}
+#define SCAN_JUNK "%ld %9s"
+ _Static_assert(9 < ARRAY_SIZE(count), "Array too small");
+
if (param[0].type == 0) {
/*
* No params - then just display index over news.
@@ -387,8 +392,18 @@ com_anews(int p, param_list param)
news_dir);
pprintf(p, "Index of recent admin news items:\n");
- fgets(junk, MAX_LINE_SIZE, fp);
- sscanf(junk, "%ld %s", &lval, count);
+
+ if (fgets(junk, sizeof junk, fp) == NULL) {
+ warnx("%s: fgets() error", __func__);
+ fclose(fp);
+ return COM_FAILED;
+ }
+ if (sscanf(junk, SCAN_JUNK, &lval, count) != 2) {
+ warnx("%s: sscanf() error: too few items", __func__);
+ fclose(fp);
+ return COM_FAILED;
+ }
+
rscan_news2(fp, p, 9);
junkp = junk;
@@ -406,8 +421,18 @@ com_anews(int p, param_list param)
*/
pprintf(p, "Index of all admin news items:\n");
- fgets(junk, MAX_LINE_SIZE, fp);
- sscanf(junk, "%ld %s", &lval, count);
+
+ if (fgets(junk, sizeof junk, fp) == NULL) {
+ warnx("%s: fgets() error", __func__);
+ fclose(fp);
+ return COM_FAILED;
+ }
+ if (sscanf(junk, SCAN_JUNK, &lval, count) != 2) {
+ warnx("%s: sscanf() error: too few items", __func__);
+ fclose(fp);
+ return COM_FAILED;
+ }
+
rscan_news(fp, p, 0);
junkp = junk;
@@ -421,13 +446,14 @@ com_anews(int p, param_list param)
} else {
while (!feof(fp) && !found) {
junkp = junk;
- fgets(junk, MAX_LINE_SIZE, fp);
- if (feof(fp))
+ if (fgets(junk, sizeof junk, fp) == NULL)
break;
if (strlen(junk) > 1) {
- sscanf(junkp, "%ld %s", &lval, count);
+ if (sscanf(junkp, SCAN_JUNK, &lval, count) != 2)
+ warnx("%s: sscanf() error...", __func__);
+
crtime = lval;
if (!strcmp(count, param[0].val.word)) {