Skip to content

Commit

Permalink
fix null dereference in author parsing arising from malformed input
Browse files Browse the repository at this point in the history
  • Loading branch information
amin committed Jun 13, 2023
1 parent 1ba4843 commit 0e84098
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ descr_end()

printf(".TL\n%s\n", descr.title);
al = descr.authors;
if(al == 0)
goto ret;
if(al->a)
puts(".AU");
while(1) {
Expand All @@ -177,8 +179,9 @@ descr_end()
else
break;
}
free(descr.title);
ret: free(descr.title);
freeauthors(descr.authors);
descr.authors = 0;
return;
}

Expand All @@ -189,6 +192,8 @@ author_st()

if(isin(&els, "document-info"))
return;
if(descr.authors == 0)
return;
for(al = descr.authors; al->next; al = al->next);
if(al->a == 0) {
al->a= emalloc(sizeof(Author));
Expand Down Expand Up @@ -218,7 +223,11 @@ firstname_dat(char *data)

if(isin(&els, "document-info"))
return;
if(descr.authors == 0)
return;
for(al = descr.authors; al->next; al = al->next);
if(al->a == 0)
return;
al->a->first = emalloc(strlen(data) + 1);
strcpy(al->a->first, data);
return;
Expand All @@ -231,7 +240,11 @@ midname_dat(char *data)

if(isin(&els, "document-info"))
return;
if(descr.authors == 0)
return;
for(al = descr.authors; al->next; al = al->next);
if(al->a == 0)
return;
al->a->middle = emalloc(strlen(data) + 1);
strcpy(al->a->middle, data);
return;
Expand All @@ -244,7 +257,11 @@ lastname_dat(char *data)

if(isin(&els, "document-info"))
return;
if(descr.authors == 0)
return;
for(al = descr.authors; al->next; al = al->next);
if(al->a == 0)
return;
al->a->last = emalloc(strlen(data) + 1);
strcpy(al->a->last, data);
return;
Expand All @@ -257,7 +274,11 @@ nickname_dat(char *data)

if(isin(&els, "document-info"))
return;
if(descr.authors == 0)
return;
for(al = descr.authors; al->next; al = al->next);
if(al->a == 0)
return;
al->a->nick = emalloc(strlen(data) + 1);
strcpy(al->a->nick, data);
return;
Expand Down

0 comments on commit 0e84098

Please sign in to comment.