From 192e2bf241ca4ca8bde8b229d2a38e95bdc80163 Mon Sep 17 00:00:00 2001 From: David Crosby Date: Wed, 27 May 2015 18:34:14 -0600 Subject: Remove unreachable return --- local.c | 1 - 1 file changed, 1 deletion(-) diff --git a/local.c b/local.c index 2728627..fa1685e 100644 --- a/local.c +++ b/local.c @@ -433,6 +433,5 @@ localcgi_post(char *uri, char *qstr, FormList *request, char *referer) fprintf(stderr, "execl(\"%s\", \"%s\", NULL): %s\n", file, cgi_basename, strerror(errno)); exit(1); - return NULL; #endif } -- cgit v1.2.3 From 3746ab24c71d199b62203f290fd3d71a97b8aa0b Mon Sep 17 00:00:00 2001 From: David Crosby Date: Tue, 30 Jun 2015 23:04:46 -0600 Subject: Free tmp --- cookie.c | 1 + 1 file changed, 1 insertion(+) diff --git a/cookie.c b/cookie.c index c11649c..b7ea016 100644 --- a/cookie.c +++ b/cookie.c @@ -105,6 +105,7 @@ make_portlist(Str port) pl->next = first; first = pl; } + Strfree(tmp); return first; } -- cgit v1.2.3 From 9cbcd21d8d845f3bd3ecf1485e0e6ca5c9e891dc Mon Sep 17 00:00:00 2001 From: David Crosby Date: Tue, 30 Jun 2015 23:10:29 -0600 Subject: Change total_dot_number to unsigned int --- cookie.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cookie.c b/cookie.c index b7ea016..cd0c38c 100644 --- a/cookie.c +++ b/cookie.c @@ -22,10 +22,10 @@ static int is_saved = 1; #define contain_no_dots(p, ep) (total_dot_number((p),(ep),1)==0) -static int +static unsigned int total_dot_number(char *p, char *ep, int max_count) { - int count = 0; + unsigned int count = 0; if (!ep) ep = p + strlen(p); @@ -325,7 +325,7 @@ add_cookie(ParsedURL *pu, Str name, Str value, if (version == 0) { /* [NETSCAPE] rule */ - int n = total_dot_number(domain->ptr, + unsigned int n = total_dot_number(domain->ptr, domain->ptr + domain->length, 3); if (n < 2) { -- cgit v1.2.3 From dba9fe97530e027be539cfc9022f88aab52517d3 Mon Sep 17 00:00:00 2001 From: David Crosby Date: Thu, 9 Jul 2015 20:11:38 -0600 Subject: Fix a divide-by-zero --- linein.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/linein.c b/linein.c index 572b015..d8f9023 100644 --- a/linein.c +++ b/linein.c @@ -714,7 +714,8 @@ _rdcompl(void) static void next_dcompl(int next) { - static int col, row, len; + static int col, row; + static unsigned int len; static Str d; int i, j, n, y; Str f; @@ -780,9 +781,10 @@ next_dcompl(int next) if (len < n) len = n; } - col = COLS / len; - if (col == 0) - col = 1; + if (len > 0 && COLS > len) + col = COLS / len; + else + col = 1; row = (NCFileBuf + col - 1) / col; disp_next: -- cgit v1.2.3 From 3120f496f7bca284535f0213bdbc4c72754f0867 Mon Sep 17 00:00:00 2001 From: David Crosby Date: Thu, 9 Jul 2015 20:34:04 -0600 Subject: Fix resource leak and a null return value dereference --- w3mbookmark.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/w3mbookmark.c b/w3mbookmark.c index fcbad11..4ffc630 100644 --- a/w3mbookmark.c +++ b/w3mbookmark.c @@ -81,6 +81,7 @@ print_bookmark_panel(char *bmark, char *url, char *title, char *charset) printf("\n"); } printf(bkmark_src2, html_quote(url), html_quote(title)); + fclose(f); } /* create new bookmark */ @@ -168,7 +169,10 @@ insert_bookmark(char *bmark, struct parsed_tagarg *data) /* In this case, a new bookmark is appeneded after the bookmark file */ return create_new_bookmark(bmark, section, title, url, "a"); } - f = fopen(bmark, "w"); + if ((f = fopen(bmark, "w")) == NULL) { + printf("\nCannot open bookmark %s\n", bmark); + return FALSE; + } while (tl->nitem) { fputs(popText(tl), f); } -- cgit v1.2.3 From 7187784234c13f12beab1d6a942ed3e6b3e8749f Mon Sep 17 00:00:00 2001 From: David Crosby Date: Thu, 9 Jul 2015 20:37:09 -0600 Subject: Fix resource leak --- w3mhelperpanel.c | 1 + 1 file changed, 1 insertion(+) diff --git a/w3mhelperpanel.c b/w3mhelperpanel.c index 110794b..96b60a0 100644 --- a/w3mhelperpanel.c +++ b/w3mhelperpanel.c @@ -115,6 +115,7 @@ printMailcapPanel(char *mailcap) printf("\n\n\n\ \n\n", MSG_DOIT); + fclose(f); } void -- cgit v1.2.3 From 4086117d9c11deb46992e6487fd1764eb0207c64 Mon Sep 17 00:00:00 2001 From: David Crosby Date: Thu, 9 Jul 2015 20:47:34 -0600 Subject: Fix resource leak --- frame.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frame.c b/frame.c index 48c2d72..c595c40 100644 --- a/frame.c +++ b/frame.c @@ -895,8 +895,10 @@ renderFrame(Buffer *Cbuf, int force_reload) /* * if (Cbuf->frameQ != NULL) fset = Cbuf->frameQ->frameset; else */ fset = Cbuf->frameset; - if (fset == NULL || createFrameFile(fset, f, Cbuf, 0, force_reload) < 0) + if (fset == NULL || createFrameFile(fset, f, Cbuf, 0, force_reload) < 0) { + fclose(f); return NULL; + } fclose(f); flag = RG_FRAME; if ((Cbuf->currentURL).is_nocache) -- cgit v1.2.3 From 80b38e6bc3fe5a2441ffaa6df68f8cfc87c4e681 Mon Sep 17 00:00:00 2001 From: David Crosby Date: Thu, 9 Jul 2015 20:55:19 -0600 Subject: Fix resource leak in load_cookies --- cookie.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/cookie.c b/cookie.c index cd0c38c..20dcb2a 100644 --- a/cookie.c +++ b/cookie.c @@ -518,36 +518,36 @@ load_cookies(void) cookie->commentURL = NULL; parseURL(readcol(&str)->ptr, &cookie->url, NULL); if (!*str) - return; + break; cookie->name = readcol(&str); if (!*str) - return; + break; cookie->value = readcol(&str); if (!*str) - return; + break; cookie->expires = (time_t) atol(readcol(&str)->ptr); if (!*str) - return; + break; cookie->domain = readcol(&str); if (!*str) - return; + break; cookie->path = readcol(&str); if (!*str) - return; + break; cookie->flag = atoi(readcol(&str)->ptr); if (!*str) - return; + break; cookie->version = atoi(readcol(&str)->ptr); if (!*str) - return; + break; cookie->comment = readcol(&str); if (cookie->comment->length == 0) cookie->comment = NULL; if (!*str) - return; + break; cookie->portl = make_portlist(readcol(&str)); if (!*str) - return; + break; cookie->commentURL = readcol(&str); if (cookie->commentURL->length == 0) cookie->commentURL = NULL; -- cgit v1.2.3 From 2582ffa39786739fcc49ee20799c2f4560a3e778 Mon Sep 17 00:00:00 2001 From: David Crosby Date: Thu, 9 Jul 2015 21:03:17 -0600 Subject: Fix resource leak in readBufferCache --- buffer.c | 1 + 1 file changed, 1 insertion(+) diff --git a/buffer.c b/buffer.c index 5afc26a..f67dd26 100644 --- a/buffer.c +++ b/buffer.c @@ -705,6 +705,7 @@ readBufferCache(Buffer *buf) cache = fopen(buf->savecache, "r"); if (cache == NULL || fread1(clnum, cache) || fread1(tlnum, cache)) { + fclose(cache); buf->savecache = NULL; return -1; } -- cgit v1.2.3 From 8c9b27b9540df0058afa40b4d11d2b00a6ec8df0 Mon Sep 17 00:00:00 2001 From: David Crosby Date: Thu, 9 Jul 2015 21:15:49 -0600 Subject: Fix resource leak in AuthDigestCred --- file.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/file.c b/file.c index df865a0..090a170 100644 --- a/file.c +++ b/file.c @@ -1228,6 +1228,7 @@ AuthDigestCred(struct http_auth *ha, Str uname, Str pw, ParsedURL *pu, unsigned char md5[MD5_DIGEST_LENGTH + 1]; Str uri = HTTPrequestURI(pu, hr); char nc[] = "00000001"; + FILE *fp; Str algorithm = qstr_unquote(get_auth_param(ha->param, "algorithm")); Str nonce = qstr_unquote(get_auth_param(ha->param, "nonce")); @@ -1310,10 +1311,11 @@ AuthDigestCred(struct http_auth *ha, Str uname, Str pw, ParsedURL *pu, /* A2 = Method ":" digest-uri-value ":" H(entity-body) */ if (request && request->body) { if (request->method == FORM_METHOD_POST && request->enctype == FORM_ENCTYPE_MULTIPART) { - FILE *fp = fopen(request->body, "r"); + fp = fopen(request->body, "r"); if (fp != NULL) { Str ebody; ebody = Strfgetall(fp); + fclose(fp); MD5(ebody->ptr, strlen(ebody->ptr), md5); } else { -- cgit v1.2.3 From 2d9d2494fc95de1c61f347a1a20297b8fa847fd3 Mon Sep 17 00:00:00 2001 From: David Crosby Date: Fri, 10 Jul 2015 00:02:12 -0600 Subject: Move fclose to fix dereference after null check (Coverity) --- w3mbookmark.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/w3mbookmark.c b/w3mbookmark.c index 4ffc630..a306f26 100644 --- a/w3mbookmark.c +++ b/w3mbookmark.c @@ -79,9 +79,9 @@ print_bookmark_panel(char *bmark, char *url, char *title, char *charset) } } printf("\n"); + fclose(f); } printf(bkmark_src2, html_quote(url), html_quote(title)); - fclose(f); } /* create new bookmark */ -- cgit v1.2.3 From 7e5b33c30ece6f265593cc442ff5a8579faef8ad Mon Sep 17 00:00:00 2001 From: David Crosby Date: Wed, 15 Jul 2015 08:55:08 -0600 Subject: Remove dead assignments flagged by Clang static analysis --- anchor.c | 2 -- file.c | 1 - istream.c | 2 -- main.c | 7 ------- menu.c | 1 - rc.c | 2 +- table.c | 2 -- terms.c | 2 -- url.c | 6 ++---- 9 files changed, 3 insertions(+), 22 deletions(-) diff --git a/anchor.c b/anchor.c index a353bb9..2d21bfa 100644 --- a/anchor.c +++ b/anchor.c @@ -643,7 +643,6 @@ addMultirowsForm(Buffer *buf, AnchorList *al) { int i, j, k, col, ecol, pos; Anchor a_form, *a; - FormItemList *fi; Line *l, *ls; if (al == NULL || al->nanchor == 0) @@ -670,7 +669,6 @@ addMultirowsForm(Buffer *buf, AnchorList *al) if (!ls) continue; } - fi = (FormItemList *)a_form.url; col = COLPOS(ls, a_form.start.pos); ecol = COLPOS(ls, a_form.end.pos); for (j = 0; l && j < a_form.rows; l = l->next, j++) { diff --git a/file.c b/file.c index 090a170..098fe00 100644 --- a/file.c +++ b/file.c @@ -7405,7 +7405,6 @@ loadBuffer(URLFile *uf, Buffer *volatile newBuf) if (newBuf == NULL) newBuf = newBuffer(INIT_BUFFER_WIDTH); - lineBuf2 = Strnew(); if (SETJMP(AbortLoading) != 0) { goto _end; diff --git a/istream.c b/istream.c index 3126142..1387307 100644 --- a/istream.c +++ b/istream.c @@ -475,8 +475,6 @@ ssl_check_cert_ident(X509 * x, char *hostname) /* FIXME: gettextize? */ ret = Sprintf("Bad cert ident %s from %s", buf, hostname); } - else - match_ident = TRUE; } return ret; } diff --git a/main.c b/main.c index 7c5780c..002c7f7 100644 --- a/main.c +++ b/main.c @@ -3071,7 +3071,6 @@ handleMailto(char *url) /* follow HREF link */ DEFUN(followA, GOTO_LINK, "Go to current link") { - Line *l; Anchor *a; ParsedURL u; #ifdef USE_IMAGE @@ -3081,7 +3080,6 @@ DEFUN(followA, GOTO_LINK, "Go to current link") if (Currentbuf->firstLine == NULL) return; - l = Currentbuf->currentLine; #ifdef USE_IMAGE a = retrieveCurrentImg(Currentbuf); @@ -3163,13 +3161,11 @@ bufferA(void) /* view inline image */ DEFUN(followI, VIEW_IMAGE, "View image") { - Line *l; Anchor *a; Buffer *buf; if (Currentbuf->firstLine == NULL) return; - l = Currentbuf->currentLine; a = retrieveCurrentImg(Currentbuf); if (a == NULL) @@ -3419,7 +3415,6 @@ followForm(void) static void _followForm(int submit) { - Line *l; Anchor *a, *a2; char *p; FormItemList *fi, *f2; @@ -3428,7 +3423,6 @@ _followForm(int submit) if (Currentbuf->firstLine == NULL) return; - l = Currentbuf->currentLine; a = retrieveCurrentForm(Currentbuf); if (a == NULL) @@ -3533,7 +3527,6 @@ _followForm(int submit) case FORM_INPUT_BUTTON: do_submit: tmp = Strnew(); - tmp2 = Strnew(); multipart = (fi->parent->method == FORM_METHOD_POST && fi->parent->enctype == FORM_ENCTYPE_MULTIPART); query_from_followform(&tmp, fi, multipart); diff --git a/menu.c b/menu.c index 2b8a6c2..e968034 100644 --- a/menu.c +++ b/menu.c @@ -361,7 +361,6 @@ geom_menu(Menu *menu, int x, int y, int mselect) if (win_w > COLS) { menu->width = COLS - 2 * FRAME_WIDTH; menu->width -= menu->width % FRAME_WIDTH; - win_w = menu->width + 2 * FRAME_WIDTH; } } menu->x = win_x + FRAME_WIDTH; diff --git a/rc.c b/rc.c index b85d50b..0cd7634 100644 --- a/rc.c +++ b/rc.c @@ -779,7 +779,7 @@ create_option_search_table() qsort(RC_search_table, RC_table_size, sizeof(struct rc_search_table), (int (*)(const void *, const void *))compare_table); - diff1 = diff2 = 0; + diff2 = 0; for (i = 0; i < RC_table_size - 1; i++) { p = RC_search_table[i].param->name; q = RC_search_table[i + 1].param->name; diff --git a/table.c b/table.c index d376284..1725d7b 100644 --- a/table.c +++ b/table.c @@ -429,7 +429,6 @@ visible_length(char *str) char *t, *r2; int amp_len = 0; - t = str; while (*str) { prev_status = status; if (next_status(*str, &status)) { @@ -3018,7 +3017,6 @@ feed_table_tag(struct table *tbl, char *line, struct table_mode *mode, break; case HTML_TABLE_ALT: id = -1; - w = 0; parsedtag_get_value(tag, ATTR_TID, &id); if (id >= 0 && id < tbl->ntable) { struct table *tbl1 = tbl->tables[id].ptr; diff --git a/terms.c b/terms.c index 2866e1d..3d2ffd7 100644 --- a/terms.c +++ b/terms.c @@ -1214,7 +1214,6 @@ addch(char pc) { l_prop *pr; int dest, i; - short *dirty; #ifdef USE_M17N static Str tmp = NULL; char **p; @@ -1236,7 +1235,6 @@ addch(char pc) return; p = ScreenImage[CurLine]->lineimage; pr = ScreenImage[CurLine]->lineprop; - dirty = &ScreenImage[CurLine]->isdirty; #ifndef USE_M17N /* Eliminate unprintables according to * iso-8859-*. diff --git a/url.c b/url.c index d4e5204..d346312 100644 --- a/url.c +++ b/url.c @@ -819,7 +819,7 @@ parseURL(char *url, ParsedURL *p_url, ParsedURL *current) /* scheme://user:pass@... */ p_url->user = copyPath(qq, q - 1 - qq, COPYPATH_SPC_IGNORE); p_url->pass = copyPath(q, p - q, COPYPATH_SPC_ALLOW); - q = ++p; + p++; goto analyze_url; } /* scheme://host:port/ */ @@ -832,7 +832,7 @@ parseURL(char *url, ParsedURL *p_url, ParsedURL *current) case '@': /* scheme://user@... */ p_url->user = copyPath(q, p - q, COPYPATH_SPC_IGNORE); - q = ++p; + p++; goto analyze_url; case '\0': /* scheme://host */ @@ -1419,7 +1419,6 @@ HTTPrequest(ParsedURL *pu, ParsedURL *current, HRequest *hr, TextList *extra) { Str tmp; TextListItem *i; - int seen_www_auth = 0; #ifdef USE_COOKIE Str cookie; #endif /* USE_COOKIE */ @@ -1435,7 +1434,6 @@ HTTPrequest(ParsedURL *pu, ParsedURL *current, HRequest *hr, TextList *extra) for (i = extra->first; i != NULL; i = i->next) { if (strncasecmp(i->ptr, "Authorization:", sizeof("Authorization:") - 1) == 0) { - seen_www_auth = 1; #ifdef USE_SSL if (hr->command == HR_COMMAND_CONNECT) continue; -- cgit v1.2.3 From d8883d384e21f79e5955f74c7cbe1730f3c797d3 Mon Sep 17 00:00:00 2001 From: David Crosby Date: Tue, 21 Jul 2015 19:54:46 -0600 Subject: Remove overflow on readlink --- local.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/local.c b/local.c index fa1685e..202e9c4 100644 --- a/local.c +++ b/local.c @@ -168,7 +168,7 @@ loadLocalDir(char *dname) else { #if defined(HAVE_LSTAT) && defined(HAVE_READLINK) if (S_ISLNK(lst.st_mode)) { - if ((l = readlink(fbuf->ptr, lbuf, sizeof(lbuf))) > 0) { + if ((l = readlink(fbuf->ptr, lbuf, sizeof(lbuf) - 1)) > 0) { lbuf[l] = '\0'; Strcat_m_charp(tmp, " -> ", html_quote(conv_from_system(lbuf)), NULL); -- cgit v1.2.3 From 6fe9e524afa7bc4e13d31708a628d16b6d263c6b Mon Sep 17 00:00:00 2001 From: David Crosby Date: Tue, 21 Jul 2015 22:00:42 -0600 Subject: Initialize new_tabwidth at declaration --- table.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/table.c b/table.c index 1725d7b..b77f0f8 100644 --- a/table.c +++ b/table.c @@ -1690,7 +1690,7 @@ renderTable(struct table *t, int max_width, struct html_feed_environ *h_env) { int i, j, w, r, h; Str renderbuf; - short new_tabwidth[MAXCOL]; + short new_tabwidth[MAXCOL] = { 0 }; #ifdef MATRIX int itr; VEC *newwidth; -- cgit v1.2.3 From a00c90930b3bbcc7f1681bd189cb74dbf6890255 Mon Sep 17 00:00:00 2001 From: David Crosby Date: Tue, 21 Jul 2015 22:24:00 -0600 Subject: use int for c --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index 002c7f7..f4399ac 100644 --- a/main.c +++ b/main.c @@ -1266,7 +1266,7 @@ static void dump_source(Buffer *buf) { FILE *f; - char c; + int c; if (buf->sourcefile == NULL) return; f = fopen(buf->sourcefile, "r"); -- cgit v1.2.3 From 73550486ffc0d7bae2b62ac49c879354aa977eff Mon Sep 17 00:00:00 2001 From: David Crosby Date: Tue, 21 Jul 2015 22:49:33 -0600 Subject: dup can give a negative value --- ftp.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ftp.c b/ftp.c index 0002abd..2ad829c 100644 --- a/ftp.c +++ b/ftp.c @@ -123,6 +123,7 @@ static int ftp_login(FTP ftp) { int sock, status; + int sock_wf; sock = openSocket(ftp->host, "ftp", 21); if (sock < 0) @@ -169,7 +170,10 @@ ftp_login(FTP ftp) } } ftp->rf = newInputStream(sock); - ftp->wf = fdopen(dup(sock), "wb"); + if ((sock_wf = dup(sock)) >= 0 ) + ftp->wf = fdopen(sock_wf, "wb"); + else + goto open_err; if (!ftp->rf || !ftp->wf) goto open_err; IStype(ftp->rf) |= IST_UNCLOSE; -- cgit v1.2.3 From dd9d2a9752b03453dccf09a0f6c9c4bb7f727830 Mon Sep 17 00:00:00 2001 From: David Crosby Date: Tue, 21 Jul 2015 23:05:54 -0600 Subject: Remove unused value --- file.c | 1 - 1 file changed, 1 deletion(-) diff --git a/file.c b/file.c index 098fe00..4e8e4d3 100644 --- a/file.c +++ b/file.c @@ -7208,7 +7208,6 @@ loadHTMLstream(URLFile *f, Buffer *newBuf, FILE * src, int internal) HTMLlineproc0(lineBuf2->ptr, &htmlenv1, internal); } if (obuf.status != R_ST_NORMAL) { - obuf.status = R_ST_EOL; HTMLlineproc0("\n", &htmlenv1, internal); } obuf.status = R_ST_NORMAL; -- cgit v1.2.3 From b1bf058d2a8b06aca24538ab58596117f3dece48 Mon Sep 17 00:00:00 2001 From: David Crosby Date: Sat, 25 Jul 2015 20:36:09 -0600 Subject: Check dup call for errors --- news.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/news.c b/news.c index 8a1f0e8..c0494b7 100644 --- a/news.c +++ b/news.c @@ -76,13 +76,15 @@ news_close(News * news) static int news_open(News * news) { - int sock, status; + int sock, status, fd; sock = openSocket(news->host, "nntp", news->port); if (sock < 0) goto open_err; news->rf = newInputStream(sock); - news->wf = fdopen(dup(sock), "wb"); + if ((fd = dup(sock)) < 0) + goto open_err; + news->wf = fdopen(fd, "wb"); if (!news->rf || !news->wf) goto open_err; IStype(news->rf) |= IST_UNCLOSE; -- cgit v1.2.3 From fc5b50353ec97ddd51c159b0d415c69e4a0e02f8 Mon Sep 17 00:00:00 2001 From: David Crosby Date: Sat, 25 Jul 2015 21:12:06 -0600 Subject: Adjust while loop --- main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index f4399ac..6609b49 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,7 @@ /* $Id: main.c,v 1.270 2010/08/24 10:11:51 htrb Exp $ */ #define MAINPROGRAM #include "fm.h" +#include #include #include #include @@ -1272,7 +1273,7 @@ dump_source(Buffer *buf) f = fopen(buf->sourcefile, "r"); if (f == NULL) return; - while (c = fgetc(f), !feof(f)) { + while ((c = fgetc(f)) != EOF) { putchar(c); } fclose(f); -- cgit v1.2.3 From 426e8b3799be260193150c5c0a8d7cbc41d7bf03 Mon Sep 17 00:00:00 2001 From: David Crosby Date: Sat, 25 Jul 2015 22:20:39 -0600 Subject: Check return value of rename --- history.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/history.c b/history.c index e9be09b..f2a00b4 100644 --- a/history.c +++ b/history.c @@ -60,6 +60,7 @@ saveHistory(Hist *hist, size_t size) FILE *f; HistItem *item; char *tmpf; + int rename_ret; if (hist == NULL || hist->list == NULL) return; @@ -79,7 +80,11 @@ saveHistory(Hist *hist, size_t size) disp_err_message("Can't save history", FALSE); return; } - rename(tmpf, rcFile(HISTORY_FILE)); + rename_ret = rename(tmpf, rcFile(HISTORY_FILE)); + if (rename_ret != 0) { + disp_err_message("Can't save history", FALSE); + return; + } } #endif /* USE_HISTORY */ -- cgit v1.2.3 From 6eb786644218c2d12e3ab635e35958757ab9bdfb Mon Sep 17 00:00:00 2001 From: David Crosby Date: Sat, 25 Jul 2015 22:46:36 -0600 Subject: Adjust len to size_t --- mailcap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mailcap.c b/mailcap.c index c0461df..f0c6242 100644 --- a/mailcap.c +++ b/mailcap.c @@ -72,7 +72,7 @@ searchMailcap(struct mailcap *table, char *type) } static int -matchMailcapAttr(char *p, char *attr, int len, Str *value) +matchMailcapAttr(char *p, char *attr, size_t len, Str *value) { int quoted; char *q = NULL; -- cgit v1.2.3 From c162b75317f93503eeab83caf86de6738c3220f4 Mon Sep 17 00:00:00 2001 From: David Crosby Date: Sat, 25 Jul 2015 22:47:24 -0600 Subject: Use fgetc in while loops, use int instead of char --- Str.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/Str.c b/Str.c index f819dbf..70e9957 100644 --- a/Str.c +++ b/Str.c @@ -530,11 +530,8 @@ Str Strfgets(FILE * f) { Str s = Strnew(); - char c; - while (1) { - c = fgetc(f); - if (feof(f) || ferror(f)) - break; + int c; + while ((c = fgetc(f)) != EOF) { Strcat_char(s, c); if (c == '\n') break; @@ -546,11 +543,8 @@ Str Strfgetall(FILE * f) { Str s = Strnew(); - char c; - while (1) { - c = fgetc(f); - if (feof(f) || ferror(f)) - break; + int c; + while ((c = fgetc(f)) != EOF) { Strcat_char(s, c); } return s; -- cgit v1.2.3 From a58671905ec1f718b21d14b8e315a1181772a0c2 Mon Sep 17 00:00:00 2001 From: David Crosby Date: Sat, 25 Jul 2015 23:13:31 -0600 Subject: Add missing comparision that made if always true --- libwc/iso2022.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libwc/iso2022.c b/libwc/iso2022.c index 33d9a19..385adde 100644 --- a/libwc/iso2022.c +++ b/libwc/iso2022.c @@ -463,7 +463,7 @@ wc_push_to_iso2022(Str os, wc_wchar_t cc, wc_status *st) cc.code = (wc_uint32)WC_REPLACE[0]; break; default: - if ((cc.ccs == WC_CCS_JOHAB || WC_CCS_JOHAB_1 || + if ((cc.ccs == WC_CCS_JOHAB || cc.ccs == WC_CCS_JOHAB_1 || cc.ccs == WC_CCS_JOHAB_2 || cc.ccs == WC_CCS_JOHAB_3) && cs94w_gmap[WC_F_KS_X_1001 - WC_F_ISO_BASE]) { wc_wchar_t cc2 = wc_johab_to_ksx1001(cc); -- cgit v1.2.3 From adcc02592c9641eb85d56526397f7af4166f81cc Mon Sep 17 00:00:00 2001 From: David Crosby Date: Sun, 26 Jul 2015 00:08:22 -0600 Subject: Use unsigned int for max_count --- cookie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cookie.c b/cookie.c index 20dcb2a..8a6f447 100644 --- a/cookie.c +++ b/cookie.c @@ -23,7 +23,7 @@ static int is_saved = 1; #define contain_no_dots(p, ep) (total_dot_number((p),(ep),1)==0) static unsigned int -total_dot_number(char *p, char *ep, int max_count) +total_dot_number(char *p, char *ep, unsigned int max_count) { unsigned int count = 0; if (!ep) -- cgit v1.2.3 From 14798c25c4bd58fcd906eac7a2df4578b00056ef Mon Sep 17 00:00:00 2001 From: David Crosby Date: Sun, 26 Jul 2015 00:08:52 -0600 Subject: Move sockent for splint --- ftp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ftp.c b/ftp.c index 2ad829c..2ca0247 100644 --- a/ftp.c +++ b/ftp.c @@ -140,7 +140,6 @@ ftp_login(FTP ftp) socklen_t socknamelen = sizeof(sockname); if (!getsockname(sock, (struct sockaddr *)&sockname, &socknamelen)) { - struct hostent *sockent; Str tmp = Strnew_charp(ftp->pass); #ifdef INET6 char hostbuf[NI_MAXHOST]; @@ -157,6 +156,7 @@ ftp_login(FTP ftp) Strcat_charp(tmp, "unknown"); #else + struct hostent *sockent; if ((sockent = gethostbyaddr((char *)&sockname.sin_addr, sizeof(sockname.sin_addr), sockname.sin_family))) -- cgit v1.2.3 From dac68e4d90d8259396f6f86d60becd39f7fd9cc5 Mon Sep 17 00:00:00 2001 From: David Crosby Date: Sun, 26 Jul 2015 00:12:16 -0600 Subject: Adjust UFclose to remove false positive of CWE-481 --- html.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html.h b/html.h index b4b3df9..c490655 100644 --- a/html.h +++ b/html.h @@ -12,7 +12,7 @@ #define StrmyUFgets(f) StrmyISgets((f)->stream) #define UFgetc(f) ISgetc((f)->stream) #define UFundogetc(f) ISundogetc((f)->stream) -#define UFclose(f) (void)(ISclose((f)->stream) == 0 && ((f)->stream = NULL)) +#define UFclose(f) if (ISclose((f)->stream) == 0) {(f)->stream = NULL ;} #define UFfileno(f) ISfileno((f)->stream) struct cmdtable { -- cgit v1.2.3 From 66036b0db62e8b9bdeb575109becc31fa3eff88a Mon Sep 17 00:00:00 2001 From: David Crosby Date: Sun, 26 Jul 2015 00:12:39 -0600 Subject: Check for presence of prevl before using --- buffer.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/buffer.c b/buffer.c index f67dd26..3b2352a 100644 --- a/buffer.c +++ b/buffer.c @@ -761,8 +761,10 @@ readBufferCache(Buffer *buf) } #endif } - buf->lastLine = prevl; - buf->lastLine->next = NULL; + if (prevl) { + buf->lastLine = prevl; + buf->lastLine->next = NULL; + } fclose(cache); unlink(buf->savecache); buf->savecache = NULL; -- cgit v1.2.3