Source: nn Version: 6.7.3-14 Severity: normal Tags: patch Dear Maintainer,
>From 7ec8452cf4e3903c75f359a20abbde3cf1e6c4c6 Mon Sep 17 00:00:00 2001 >From: Bjarni Ingi Gislason <bjarn...@rhi.hi.is> >Date: Sun, 28 Feb 2021 19:42:50 +0000 >Subject: [PATCH] db.c: add two variables, information to the output, and some arguments to functions Add size of an array to the argument list of some functions. Use "snprintf()" instead of "sprintf()". Add variable "source" for a file name. Add some output with information. Add variable "count" to count number of groups. Signed-off-by: Bjarni Ingi Gislason <bjarn...@rhi.hi.is> --- db.c | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/db.c b/db.c index 51ac2e6..2306c71 100644 --- a/db.c +++ b/db.c @@ -850,20 +850,20 @@ art_collected(group_header * gh, article_number art_num) #ifndef NOV char * -db_data_path(char *namebuf, group_header * gh, char d_or_x) +db_data_path(char *namebuf, size_t nnamebuf, group_header * gh, char d_or_x) { register char *cp, *np; if (db_data_directory != NULL) { #ifdef DB_LONG_NAMES - sprintf(namebuf, "%s/%s.%c", db_data_directory, gh->group_name, d_or_x); + snprintf(namebuf, nnamebuf, "%s/%s.%c", db_data_directory, gh->group_name, d_or_x); #else if (db_data_subdirs) - sprintf(namebuf, "%s/%ld/%ld.%c", db_data_directory, + snprintf(namebuf, nnamebuf, "%s/%ld/%ld.%c", db_data_directory, gh->group_num / 100, gh->group_num, d_or_x); else - sprintf(namebuf, "%s/%ld.%c", db_data_directory, gh->group_num, d_or_x); + snprintf(namebuf, nnamebuf, "%s/%ld.%c", db_data_directory, gh->group_num, d_or_x); #endif /* DB_LONG_NAMES */ } else { np = namebuf; @@ -892,7 +892,7 @@ open_data_file(group_header * gh, char d_or_x, int mode) FILE *f; char data_file[FILENAME]; - db_data_path(data_file, gh, d_or_x); + db_data_path(data_file, FILENAME, gh, d_or_x); if (mode == -1) { if (unlink(data_file) < 0 && errno != ENOTDIR && errno != ENOENT) @@ -1009,6 +1009,7 @@ err: #ifdef NOV + static void readactfile(void) { @@ -1029,13 +1030,16 @@ readactfile(void) #ifdef NNTP if (use_nntp) { actfp = nntp_fopen_list("LIST"); - } else + source = nntp_server; + } else { #endif /* NNTP */ - actfp = fopen(relative(news_lib_directory, "active"), "r"); + source = relative(news_lib_directory, "active"); + actfp = fopen(source, "r"); + } if (actfp == NULL) { - nn_exitmsg(1, "could not fetch active file\n"); + nn_exitmsg(1, "could not fetch active file from %s\n", source); } /* @@ -1068,10 +1072,12 @@ readactfile(void) if ( (nntp_debug || keep_active_file) && (f_user != NULL)) fprintf(f_user, "%s\n", actline); - stlist_t *stnew = (stlist_t *) strkeep(actline, sizeof(stlisthdr_t), POOL_ACT); + stlist_t *stnew = (stlist_t *) strkeep(actline, sizeof(stlisthdr_t), POOL_ACT); + if (stnew == NULL) { - nn_exitmsg(1, "out of mem for active file (at line %d)\n", count + 1); + nn_exitmsg(1, "Out of memory for active file (at line %d)\n", count + 1); } + if (sthead != NULL) { stp->n.next = stnew; stp = stnew; @@ -1088,6 +1094,7 @@ readactfile(void) actlist = (char **) calloc(count + 1, sizeof(char *)); grplist = (char **) calloc(count + 1, sizeof(char *)); + if (grplist == NULL) { nn_exitmsg(1, "can't create active or group list (%d entries)\n", count + 1); @@ -1097,6 +1104,7 @@ readactfile(void) * Second pass (in core): Put active lines and group names into string * arrays. */ + for (i = 0, stp = sthead; stp && i < count; stp = stp->n.next, i++) { char *p = strchr(stp->str, ' '); @@ -1108,13 +1116,13 @@ readactfile(void) } grplist[i] = strkeep(stp->str, 0, POOL_GRP); } + tprintf("done. %d groups.\n\n", count); actlist[count] = NULL; grplist[count] = NULL; /* init the master struct */ clearobj(&master, sizeof(master), 1); master.number_of_groups = count; - } @@ -1186,7 +1194,7 @@ readpartactfile(void) /* tprintf("%s\n", actline); nn_exitmsg(1, "Testing ask_server\n"); */ - stlist_t *stnew = (stlist_t *) strkeep(actline, sizeof(stlisthdr_t), POOL_ACT); + stlist_t *stnew = (stlist_t *) strkeep(actline, sizeof(stlisthdr_t), POOL_ACT); if (stnew == NULL) { nn_exitmsg(1, "Out of memory for active file (at line %d)\n", count + 1); } @@ -1381,6 +1389,7 @@ readtimfile(void) char timline[512]; FILE *timfp; unsigned hsize; + unsigned int count = 0; if (timtbl != NULL) return; @@ -1405,6 +1414,8 @@ readtimfile(void) /* alt.fan.marla-thrift 736668095 netn...@ccc.amdahl.com */ + tprintf("Reading the \"active.times\" file ... "); + fflush(stdout); #ifdef NNTP while (use_nntp ? nntp_fgets(timline, sizeof timline) : fgets(timline, sizeof timline, timfp)) @@ -1422,8 +1433,10 @@ readtimfile(void) if (!hashstore(timtbl, line, p)) { nn_exitmsg(1, "nn: time hashstore failed\n"); } + count++; } + tprintf("done. %u groups.\n", count); if (!use_nntp) (void) fclose(timfp); @@ -1662,6 +1675,7 @@ db_init_active(register group_header * gh) register char *p; p = actlist[gh->group_num]; +/* p contains "high low {"y", "m" or "=<group name>"} and a newline */ if (p != NULL) { while (isspace(*p)) ++p; @@ -1672,10 +1686,13 @@ db_init_active(register group_header * gh) gh->first_a_article = atol(++p); p = strchr(p, ' '); if (*++p == '=') { /* an alias */ +/* remove newline at end of string */ + if (*(p + strlen(p) - 1) == NL ) + *(p + strlen(p) - 1) = NUL; gh1 = lookup_no_alias(++p); if (gh1 == NULL) { - log_entry('R', "Group %s aliased to unknown group (%s)", - gh->group_name, p); + log_entry('R', "%s: Group %s aliased to unknown group (%s)", + __FILE__, gh->group_name, p); /* ah well! leave it be */ } else { gh->master_flag |= M_ALIASED; @@ -2056,7 +2073,7 @@ db_write_offset(FILE * f, long *offset) #ifdef NOV /* These are strictly temporary. They will go away. */ char * -db_data_path(char *namebuf, group_header * gh, char d_or_x) +db_data_path(char *namebuf, size_t nnamebuf, group_header * gh, char d_or_x) { nn_exitmsg(50, "STUB ROUTINE CALLED: db_data_path\n"); return NULL; -- 2.30.1 -- System Information: Debian Release: bullseye/sid APT prefers testing APT policy: (500, 'testing'), (500, 'stable') Architecture: amd64 (x86_64) Kernel: Linux 5.10.9-1 (SMP w/2 CPU threads) Locale: LANG=is_IS.iso88591, LC_CTYPE=is_IS.iso88591 (charmap=ISO-8859-1), LANGUAGE not set Shell: /bin/sh linked to /bin/dash Init: sysvinit (via /sbin/init) -- debconf information excluded -- Bjarni I. Gislason