Source: nn Version: 6.7.3-14 Severity: normal Tags: patch Dear Maintainer,
>From 4bbc72a38a25a19afdce68bdb7e4f3d394afbf16 Mon Sep 17 00:00:00 2001 >From: Bjarni Ingi Gislason <bjarn...@rhi.hi.is> >Date: Sat, 27 Feb 2021 00:59:50 +0000 >Subject: [PATCH] aux.c: changes in the file Use named constants instead of a number for the declaration of number of array elements. Use "snprintf()" instead of "sprintf()". Add information to some output. Fix a warning: aux.c:359:16: warning: comparison with string literal results in unspecified behavior [-Waddress] 359 | if (action != "send") { | ^~ Fix a warning by turning the line into a comment: aux.c:472:7: warning: the address of 'lookfor' will always evaluate as 'true' [-Waddress] 472 | if (lookfor); /* grep for lookfor */ | ^~~~~~~ Fix a warning by turning the line into a comment: aux.c:557:7: warning: the address of 'fname' will always evaluate as 'true' [-Waddress] 557 | if (fname) Maybe the test should be to test, if "fname" is not empty? Signed-off-by: Bjarni Ingi Gislason <bjarn...@rhi.hi.is> --- aux.c | 58 ++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/aux.c b/aux.c index 7802288..5ce9271 100644 --- a/aux.c +++ b/aux.c @@ -26,6 +26,8 @@ extern char *temp_file; extern int novice; extern char delayed_msg[]; +/* number for array delayed_msg[] in"master.c" and "menu.c" */ +extern const size_t ndelayed_msg; extern char *pager; extern char *inews_program; extern int inews_pipe_input; @@ -102,8 +104,9 @@ aux_sh(article_header * ah, char *script, char *prog, char *action, char *record * find the .param file, can't always look in $HOME/.nn */ if (!getenv("NNDIR")) { - char ebuf[FILENAME + 8]; - sprintf(ebuf, "NNDIR=%s", nn_directory); +#define NEBUF FILENAME + 8; + char ebuf[NEBUF]; + snprintf(ebuf, NEBUF, "NNDIR=%s", nn_directory); putenv(ebuf); } if (strcmp(prog, "cancel") == 0) { @@ -175,10 +178,10 @@ no_params: *ap++ = NULL; if (execute(SHELL, args, 1)) { - sprintf(delayed_msg, sent_fmt, " not"); + snprintf(delayed_msg, ndelayed_msg, sent_fmt, " not"); return 1; } - sprintf(delayed_msg, sent_fmt, ""); + snprintf(delayed_msg, ndelayed_msg, sent_fmt, ""); return 0; } @@ -192,7 +195,7 @@ tempsuffix(char *name, char *suffix) { static char concat_name[FILENAME]; - sprintf(concat_name, "%s%s", name, suffix); + snprintf(concat_name, FILENAME, "%s%s", name, suffix); return concat_name; } @@ -293,8 +296,10 @@ aux_sh(article_header * ah, char *script, char *prog, char *action, char *record char route[512], *poster = NULL; int goodsigntype = 0; int loop = 1, prmpt = 0; - char cc[256], pr[80], pr1[80], fname[FILENAME], buf[80]; - char buf2[10]; +#define NBUF 80 +#define NBUF2 10 + char cc[256], pr[80], pr1[80], fname[FILENAME], buf[NBUF]; + char buf2[NBUF2]; char lookfor[16], send[8], sent[8], sendpr[8], message[8]; int x, act = response_dflt_answer[0]; struct stat statb; @@ -334,7 +339,7 @@ aux_sh(article_header * ah, char *script, char *prog, char *action, char *record fprintf(temp, "\n"); fprintf(temp, "cancel %s in newsgroup %s\n", action, record); fprintf(temp, "\n"); - fprintf(temp, "This article was cancelled from within %s\n", version_id); + fprintf(temp, "This article was cancelled from within nn %s\n", version_id); fprintf(temp, "\n"); fclose(temp); x = (nntp_post(temp_file)); @@ -356,7 +361,7 @@ aux_sh(article_header * ah, char *script, char *prog, char *action, char *record strcpy(message, "letter"); } - if (action != "send") { + if (strcmp(action, "send") != 0) { strcpy(copy, tempsuffix(temp_file, "C")); copy_file(temp_file, copy, 0); } @@ -447,7 +452,7 @@ aux_sh(article_header * ah, char *script, char *prog, char *action, char *record strncpy(buf, editor_program, 50); if (use_ed_line) { - sprintf(buf2, " +%d", ed_line); + snprintf(buf2, NBUF2, " +%d", ed_line); strcat(buf, buf2); } strcat(buf, " "); @@ -457,19 +462,22 @@ aux_sh(article_header * ah, char *script, char *prog, char *action, char *record nn_raw(); if (stat(temp_file, &statb) < 0 || statb.st_size == 0) { - sprintf(delayed_msg, sent_fmt, " not"); + snprintf(delayed_msg, ndelayed_msg, sent_fmt, " not"); unlink(temp_file); unlink(copy); return (22); } if (empty_answer_check) if (cmp_file(temp_file, copy) != 1) { - sprintf(delayed_msg, sent_fmt, " not"); + snprintf(delayed_msg, ndelayed_msg, sent_fmt, " not"); unlink(temp_file); unlink(copy); return (22); } - if (lookfor); /* grep for lookfor */ ++/* ++ aux.c:...: warning: the address of 'lookfor' will always evaluate as 'true' ++*/ +/* if (lookfor); */ /* grep for lookfor */ break; @@ -554,7 +562,10 @@ aux_sh(article_header * ah, char *script, char *prog, char *action, char *record prompt_line = Lines - 1; prompt("Append %s to file: ", message); strcpy(fname, get_s((char *) NULL, (char *) NULL, (char *) NULL, NULL_FCT)); - if (fname) +/* +aux.c:...: warning: the address of 'fname' will always evaluate as 'true' +*/ +/* if (fname) */ copy_file(temp_file, fname, 1); break; @@ -568,20 +579,20 @@ aux_sh(article_header * ah, char *script, char *prog, char *action, char *record strcpy(hdrs, tempsuffix(temp_file, "H")); strcpy(bdy, tempsuffix(temp_file, "B")); strcpy(sgn, tempsuffix(temp_file, "S")); - sprintf(buf, "sed -e \'/^$/q\' < %s > %s", temp_file, hdrs); + snprintf(buf, NBUF, "sed -e \'/^$/q\' < %s > %s", temp_file, hdrs); system(buf); - sprintf(buf, "awk \'{if (S== 1) print $0; if ($0 == \"\") S=1}\' < %s > %s", temp_file, bdy); + snprintf(buf, NBUF, "awk \'{if (S== 1) print $0; if ($0 == \"\") S=1}\' < %s > %s", temp_file, bdy); system(buf); if (strcmp(sign_type, "pgp") == 0) { - sprintf(buf, "pgp -stfaw < %s > %s", bdy, sgn); + snprintf(buf, NBUF, "pgp -stfaw < %s > %s", bdy, sgn); goodsigntype = 1; } else if (strcmp(sign_type, "gpg") == 0) { - sprintf(buf, "gpg -sta < %s > %s", bdy, sgn); + snprintf(buf, NBUF, "gpg -sta < %s > %s", bdy, sgn); goodsigntype = 1; } if (goodsigntype) { system(buf); - sprintf(buf, "cat %s %s > %s", hdrs, sgn, temp_file); + snprintf(buf, NBUF, "cat %s %s > %s", hdrs, sgn, temp_file); system(buf); } else msg("sign-type must be either pgp or gpg"); @@ -598,7 +609,7 @@ aux_sh(article_header * ah, char *script, char *prog, char *action, char *record tempf = open_file(final, OPEN_CREATE); x = fprintf(tempf, "To: %s\n", cc); fclose(tempf); - sprintf(buf, "sed -e \"s/^To:/X-To:/\" -e \"/^Orig-To:/d\" %s >> %s", + snprintf(buf, NBUF, "sed -e \"s/^To:/X-To:/\" -e \"/^Orig-To:/d\" %s >> %s", temp_file, final); system(buf); if (mailer_pipe_input) { @@ -681,7 +692,7 @@ aux_sh(article_header * ah, char *script, char *prog, char *action, char *record system(buf); } if (mailer_pipe_input) { - sprintf(buf, "%s < %s", mailer_program, temp_file); + snprintf(buf, NBUF, "%s < %s", mailer_program, temp_file); x = system(buf); } else { strncpy(buf, mailer_program, 50); @@ -696,6 +707,9 @@ aux_sh(article_header * ah, char *script, char *prog, char *action, char *record copy_file(temp_file, relative(home_directory, "dead.letter"), 1); msg("failed post saved in dead.letter"); user_delay(2); + unlink(temp_file); + unlink(copy); + unlink(final); return (1); } } else { @@ -708,7 +722,7 @@ aux_sh(article_header * ah, char *script, char *prog, char *action, char *record unlink(temp_file); unlink(copy); unlink(final); - sprintf(delayed_msg, sent_fmt, ""); + snprintf(delayed_msg, ndelayed_msg, sent_fmt, ""); return (0); } -- 2.30.0 -- 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