sfeed

simple feed reader - forked from git.codemadness.org/sfeed
git clone git://src.gearsix.net/sfeed
Log | Files | Refs | Atom | README | LICENSE

commit 20686256dbc94fd693607abd5165ecc9901dd1e3
parent 790a941eb0c78867f744d0551ac20b421b6c75e2
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Thu, 13 Jan 2022 23:59:21 +0100

sfeed_curses: pedantic fix for UB with an empty URL file

When a new URL file is used with no URL entries then NULL is passed to qsort()
and bsearch(). This is reported by clang UBsan as undefined behaviour
(debatable), but no issue in practise with many implementations. Fix it anyway.

To reproduce with clang UBsan:
Compile with clang or gcc with CFLAGS and LDFLAGS -fsanitize=undefined
touch /tmp/urls # new file which should be empty.
SFEED_URL_FILE=/tmp/urls sfeed_curses 2>/tmp/log
^D
q
cat /tmp/log

Diffstat:
Msfeed_curses.c | 6++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/sfeed_curses.c b/sfeed_curses.c @@ -1886,7 +1886,8 @@ urls_cmp(const void *v1, const void *v2) int urls_isnew(const char *url) { - return bsearch(&url, urls, nurls, sizeof(char *), urls_cmp) == NULL; + return (!nurls || + bsearch(&url, urls, nurls, sizeof(char *), urls_cmp) == NULL); } void @@ -1928,7 +1929,8 @@ urls_read(void) fclose(fp); free(line); - qsort(urls, nurls, sizeof(char *), urls_cmp); + if (nurls > 0) + qsort(urls, nurls, sizeof(char *), urls_cmp); } int