Check return value of Str... functions

All these functions, StrmyUFgets, StrISgets, etc. can potentially return
NULL. Add a check for it.
This commit is contained in:
Rene Kita
2022-04-15 12:42:24 +02:00
parent d33a522936
commit 9eaf044c02
4 changed files with 18 additions and 13 deletions
+7 -6
View File
@@ -608,7 +608,7 @@ readHeader(URLFile *uf, Buffer *newBuf, int thru, ParsedURL *pu)
if (src)
newBuf->header_source = tmpf;
}
while ((tmp = StrmyUFgets(uf))->length) {
while ((tmp = StrmyUFgets(uf)) && tmp->length) {
#ifdef USE_NNTP
if (uf->scheme == SCM_NEWS && tmp->ptr[0] == '.')
Strshrinkfirst(tmp, 1);
@@ -6328,7 +6328,7 @@ file_feed()
{
Str s;
s = StrISgets(_file_lp2);
if (s->length == 0) {
if (s && s->length == 0) {
ISclose(_file_lp2);
return NULL;
}
@@ -7339,7 +7339,7 @@ loadHTMLstream(URLFile *f, Buffer *newBuf, FILE * src, int internal)
#endif
if (IStype(f->stream) != IST_ENCODED)
f->stream = newEncodedStream(f->stream, f->encoding);
while ((lineBuf2 = StrmyUFgets(f))->length) {
while ((lineBuf2 = StrmyUFgets(f)) && lineBuf2->length) {
#ifdef USE_NNTP
if (f->scheme == SCM_NEWS && lineBuf2->ptr[0] == '.') {
Strshrinkfirst(lineBuf2, 1);
@@ -7496,7 +7496,7 @@ loadGopherDir0(URLFile *uf, ParsedURL *pu)
pre = 0;
while (1) {
if (lbuf = StrUFgets(uf), lbuf->length == 0)
if (!(lbuf = StrUFgets(uf)) || lbuf->length == 0)
break;
if (lbuf->ptr[0] == '.' &&
(lbuf->ptr[1] == '\n' || lbuf->ptr[1] == '\r'))
@@ -7666,7 +7666,7 @@ loadBuffer(URLFile *uf, Buffer *volatile newBuf)
nlines = 0;
if (IStype(uf->stream) != IST_ENCODED)
uf->stream = newEncodedStream(uf->stream, uf->encoding);
while ((lineBuf2 = StrmyISgets(uf->stream))->length) {
while ((lineBuf2 = StrmyISgets(uf->stream)) && lineBuf2->length) {
#ifdef USE_NNTP
if (uf->scheme == SCM_NEWS && lineBuf2->ptr[0] == '.') {
Strshrinkfirst(lineBuf2, 1);
@@ -8090,7 +8090,8 @@ getNextPage(Buffer *buf, int plen)
init_stream(&uf, SCM_UNKNOWN, NULL);
for (i = 0; i < plen; i++) {
lineBuf2 = StrmyISgets(buf->pagerSource);
if (!(lineBuf2 = StrmyISgets(buf->pagerSource)))
return NULL;
if (lineBuf2->length == 0) {
/* Assume that `cmd == buf->filename' */
if (buf->filename)
+2 -2
View File
@@ -532,7 +532,7 @@ createFrameFile(struct frameset *f, FILE * f1, Buffer *current, int level,
!strcasecmp(frame.body->type, "text/plain")) {
Str tmp;
fprintf(f1, "<pre>\n");
while ((tmp = StrmyUFgets(&f2))->length) {
while ((tmp = StrmyUFgets(&f2)) && tmp->length) {
tmp = convertLine(NULL, tmp, HTML_MODE, &charset,
doc_charset);
fprintf(f1, "%s", html_quote(tmp->ptr));
@@ -549,7 +549,7 @@ createFrameFile(struct frameset *f, FILE * f1, Buffer *current, int level,
do {
if (*p == '\0') {
Str tmp = StrmyUFgets(&f2);
if (tmp->length == 0)
if (!tmp || tmp->length == 0)
break;
tmp = convertLine(NULL, tmp, HTML_MODE, &charset,
doc_charset);
+4 -2
View File
@@ -70,7 +70,8 @@ ftp_command(FTP ftp, char *cmd, char *arg, int *status)
if (!status)
return NULL;
*status = -1; /* error */
tmp = StrISgets(ftp->rf);
if (!(tmp = StrISgets(ftp->rf)))
return NULL;
if (IS_DIGIT(tmp->ptr[0]) && IS_DIGIT(tmp->ptr[1]) &&
IS_DIGIT(tmp->ptr[2]) && tmp->ptr[3] == ' ')
sscanf(tmp->ptr, "%d", status);
@@ -87,7 +88,8 @@ ftp_command(FTP ftp, char *cmd, char *arg, int *status)
* with the same code, followed immediately by Space <SP>,
* optionally some text, and the Telnet end-of-line code. */
while (1) {
tmp = StrISgets(ftp->rf);
if (!(tmp = StrISgets(ftp->rf)))
break;
if (IS_DIGIT(tmp->ptr[0]) && IS_DIGIT(tmp->ptr[1]) &&
IS_DIGIT(tmp->ptr[2]) && tmp->ptr[3] == ' ') {
sscanf(tmp->ptr, "%d", status);
+5 -3
View File
@@ -51,7 +51,7 @@ news_command(News * news, char *cmd, char *arg, int *status)
return NULL;
*status = -1;
tmp = StrISgets(news->rf);
if (tmp->length)
if (tmp && tmp->length)
sscanf(tmp->ptr, "%d", status);
return tmp;
}
@@ -396,7 +396,8 @@ loadNewsgroup0(ParsedURL *pu)
if (status == 224) {
f.scheme = SCM_NEWS;
while (1) {
tmp = StrISgets(current_news.rf);
if (!(tmp = StrISgets(current_news.rf)))
break;
if (NEWS_ENDLINE(tmp->ptr))
break;
if (sscanf(tmp->ptr, "%d", &i) != 1)
@@ -474,7 +475,8 @@ loadNewsgroup0(ParsedURL *pu)
if (status != 215)
goto news_end;
while (1) {
tmp = StrISgets(current_news.rf);
if (!(tmp = StrISgets(current_news.rf)))
break;
if (NEWS_ENDLINE(tmp->ptr))
break;
if (flag < 2) {