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) if (src)
newBuf->header_source = tmpf; newBuf->header_source = tmpf;
} }
while ((tmp = StrmyUFgets(uf))->length) { while ((tmp = StrmyUFgets(uf)) && tmp->length) {
#ifdef USE_NNTP #ifdef USE_NNTP
if (uf->scheme == SCM_NEWS && tmp->ptr[0] == '.') if (uf->scheme == SCM_NEWS && tmp->ptr[0] == '.')
Strshrinkfirst(tmp, 1); Strshrinkfirst(tmp, 1);
@@ -6328,7 +6328,7 @@ file_feed()
{ {
Str s; Str s;
s = StrISgets(_file_lp2); s = StrISgets(_file_lp2);
if (s->length == 0) { if (s && s->length == 0) {
ISclose(_file_lp2); ISclose(_file_lp2);
return NULL; return NULL;
} }
@@ -7339,7 +7339,7 @@ loadHTMLstream(URLFile *f, Buffer *newBuf, FILE * src, int internal)
#endif #endif
if (IStype(f->stream) != IST_ENCODED) if (IStype(f->stream) != IST_ENCODED)
f->stream = newEncodedStream(f->stream, f->encoding); f->stream = newEncodedStream(f->stream, f->encoding);
while ((lineBuf2 = StrmyUFgets(f))->length) { while ((lineBuf2 = StrmyUFgets(f)) && lineBuf2->length) {
#ifdef USE_NNTP #ifdef USE_NNTP
if (f->scheme == SCM_NEWS && lineBuf2->ptr[0] == '.') { if (f->scheme == SCM_NEWS && lineBuf2->ptr[0] == '.') {
Strshrinkfirst(lineBuf2, 1); Strshrinkfirst(lineBuf2, 1);
@@ -7496,7 +7496,7 @@ loadGopherDir0(URLFile *uf, ParsedURL *pu)
pre = 0; pre = 0;
while (1) { while (1) {
if (lbuf = StrUFgets(uf), lbuf->length == 0) if (!(lbuf = StrUFgets(uf)) || lbuf->length == 0)
break; break;
if (lbuf->ptr[0] == '.' && if (lbuf->ptr[0] == '.' &&
(lbuf->ptr[1] == '\n' || lbuf->ptr[1] == '\r')) (lbuf->ptr[1] == '\n' || lbuf->ptr[1] == '\r'))
@@ -7666,7 +7666,7 @@ loadBuffer(URLFile *uf, Buffer *volatile newBuf)
nlines = 0; nlines = 0;
if (IStype(uf->stream) != IST_ENCODED) if (IStype(uf->stream) != IST_ENCODED)
uf->stream = newEncodedStream(uf->stream, uf->encoding); uf->stream = newEncodedStream(uf->stream, uf->encoding);
while ((lineBuf2 = StrmyISgets(uf->stream))->length) { while ((lineBuf2 = StrmyISgets(uf->stream)) && lineBuf2->length) {
#ifdef USE_NNTP #ifdef USE_NNTP
if (uf->scheme == SCM_NEWS && lineBuf2->ptr[0] == '.') { if (uf->scheme == SCM_NEWS && lineBuf2->ptr[0] == '.') {
Strshrinkfirst(lineBuf2, 1); Strshrinkfirst(lineBuf2, 1);
@@ -8090,7 +8090,8 @@ getNextPage(Buffer *buf, int plen)
init_stream(&uf, SCM_UNKNOWN, NULL); init_stream(&uf, SCM_UNKNOWN, NULL);
for (i = 0; i < plen; i++) { for (i = 0; i < plen; i++) {
lineBuf2 = StrmyISgets(buf->pagerSource); if (!(lineBuf2 = StrmyISgets(buf->pagerSource)))
return NULL;
if (lineBuf2->length == 0) { if (lineBuf2->length == 0) {
/* Assume that `cmd == buf->filename' */ /* Assume that `cmd == buf->filename' */
if (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")) { !strcasecmp(frame.body->type, "text/plain")) {
Str tmp; Str tmp;
fprintf(f1, "<pre>\n"); fprintf(f1, "<pre>\n");
while ((tmp = StrmyUFgets(&f2))->length) { while ((tmp = StrmyUFgets(&f2)) && tmp->length) {
tmp = convertLine(NULL, tmp, HTML_MODE, &charset, tmp = convertLine(NULL, tmp, HTML_MODE, &charset,
doc_charset); doc_charset);
fprintf(f1, "%s", html_quote(tmp->ptr)); fprintf(f1, "%s", html_quote(tmp->ptr));
@@ -549,7 +549,7 @@ createFrameFile(struct frameset *f, FILE * f1, Buffer *current, int level,
do { do {
if (*p == '\0') { if (*p == '\0') {
Str tmp = StrmyUFgets(&f2); Str tmp = StrmyUFgets(&f2);
if (tmp->length == 0) if (!tmp || tmp->length == 0)
break; break;
tmp = convertLine(NULL, tmp, HTML_MODE, &charset, tmp = convertLine(NULL, tmp, HTML_MODE, &charset,
doc_charset); doc_charset);
+4 -2
View File
@@ -70,7 +70,8 @@ ftp_command(FTP ftp, char *cmd, char *arg, int *status)
if (!status) if (!status)
return NULL; return NULL;
*status = -1; /* error */ *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]) && if (IS_DIGIT(tmp->ptr[0]) && IS_DIGIT(tmp->ptr[1]) &&
IS_DIGIT(tmp->ptr[2]) && tmp->ptr[3] == ' ') IS_DIGIT(tmp->ptr[2]) && tmp->ptr[3] == ' ')
sscanf(tmp->ptr, "%d", status); 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>, * with the same code, followed immediately by Space <SP>,
* optionally some text, and the Telnet end-of-line code. */ * optionally some text, and the Telnet end-of-line code. */
while (1) { while (1) {
tmp = StrISgets(ftp->rf); if (!(tmp = StrISgets(ftp->rf)))
break;
if (IS_DIGIT(tmp->ptr[0]) && IS_DIGIT(tmp->ptr[1]) && if (IS_DIGIT(tmp->ptr[0]) && IS_DIGIT(tmp->ptr[1]) &&
IS_DIGIT(tmp->ptr[2]) && tmp->ptr[3] == ' ') { IS_DIGIT(tmp->ptr[2]) && tmp->ptr[3] == ' ') {
sscanf(tmp->ptr, "%d", status); 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; return NULL;
*status = -1; *status = -1;
tmp = StrISgets(news->rf); tmp = StrISgets(news->rf);
if (tmp->length) if (tmp && tmp->length)
sscanf(tmp->ptr, "%d", status); sscanf(tmp->ptr, "%d", status);
return tmp; return tmp;
} }
@@ -396,7 +396,8 @@ loadNewsgroup0(ParsedURL *pu)
if (status == 224) { if (status == 224) {
f.scheme = SCM_NEWS; f.scheme = SCM_NEWS;
while (1) { while (1) {
tmp = StrISgets(current_news.rf); if (!(tmp = StrISgets(current_news.rf)))
break;
if (NEWS_ENDLINE(tmp->ptr)) if (NEWS_ENDLINE(tmp->ptr))
break; break;
if (sscanf(tmp->ptr, "%d", &i) != 1) if (sscanf(tmp->ptr, "%d", &i) != 1)
@@ -474,7 +475,8 @@ loadNewsgroup0(ParsedURL *pu)
if (status != 215) if (status != 215)
goto news_end; goto news_end;
while (1) { while (1) {
tmp = StrISgets(current_news.rf); if (!(tmp = StrISgets(current_news.rf)))
break;
if (NEWS_ENDLINE(tmp->ptr)) if (NEWS_ENDLINE(tmp->ptr))
break; break;
if (flag < 2) { if (flag < 2) {