diff options
author | 2009-06-01 22:57:14 +0000 | |
---|---|---|
committer | 2009-06-01 22:57:14 +0000 | |
commit | 8c6fe208668137bcd073676b0056ae4721d31d7e (patch) | |
tree | 4b40aff9c3c347fc24aa3b33d4116f0e63996573 | |
parent | Do not call the upcall twice on some prefixes. Move the upcall back to (diff) | |
download | wireguard-openbsd-8c6fe208668137bcd073676b0056ae4721d31d7e.tar.xz wireguard-openbsd-8c6fe208668137bcd073676b0056ae4721d31d7e.zip |
Fix fgets handling.
1. Skip blank lines instead of dereferencing NULL-1.
2. If bufr is a blank line don't pass bufr+1 as a pointer.
OK millert
-rw-r--r-- | games/hack/hack.pager.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/games/hack/hack.pager.c b/games/hack/hack.pager.c index 507371d2c93..553a8ad9e45 100644 --- a/games/hack/hack.pager.c +++ b/games/hack/hack.pager.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hack.pager.c,v 1.15 2009/06/01 09:07:56 ray Exp $ */ +/* $OpenBSD: hack.pager.c,v 1.16 2009/06/01 22:57:14 ray Exp $ */ /* * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica, @@ -62,7 +62,7 @@ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: hack.pager.c,v 1.15 2009/06/01 09:07:56 ray Exp $"; +static const char rcsid[] = "$OpenBSD: hack.pager.c,v 1.16 2009/06/01 22:57:14 ray Exp $"; #endif /* not lint */ /* This file contains the command routine dowhatis() and a pager. */ @@ -87,6 +87,7 @@ dowhatis() FILE *fp; char bufr[BUFSZ+6]; char *buf = &bufr[6], *ep, q; + size_t len; extern char readchar(); if (!(fp = fopen(DATAFILE, "r"))) @@ -97,18 +98,20 @@ dowhatis() if (q != '\t') while (fgets(buf,BUFSZ,fp)) if (*buf == q) { - ep = strchr(buf, '\n'); - if (ep) - *ep = 0; - /* else: bad data file */ + len = strcspn(buf, "\n"); + /* bad data file */ + if (len == 0) + continue; + buf[len] = '\0'; /* Expand tab 'by hand' */ if (buf[1] == '\t'){ buf = bufr; buf[0] = q; (void) strncpy(buf+1, " ", 7); + len = strlen(buf); } pline(buf); - if (ep[-1] == ';') { + if (buf[len - 1] == ';') { pline("More info? "); if (readchar() == 'y') { page_more(fp,1); /* does fclose() */ @@ -146,7 +149,7 @@ page_more(FILE *fp, int strip) while (fgets(bufr, CO, fp) && (!strip || *bufr == '\t') && !got_intrup) { bufr[strcspn(bufr, "\n")] = '\0'; - if(page_line(bufr+strip)) { + if (*bufr == '\0' || page_line(bufr+strip)) { set_pager(2); goto ret; } |