Skip to content

Commit

Permalink
Merge pull request #202 from FGasper/issue_201_use_after_free
Browse files Browse the repository at this point in the history
Fix ldns_rdf2buffer_str_wks not to use after free.

Ack. Makes sense. Thanks for finding and reporting this.
  • Loading branch information
wtoorop authored Jan 12, 2023
2 parents 1ce94b1 + 0d2d9b3 commit 1564b4f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions host2str.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,10 +835,6 @@ ldns_rdf2buffer_str_wks(ldns_buffer *output, const ldns_rdf *rdf)
ldns_buffer_printf(output, "%u ", protocol_nr);
}

#ifdef HAVE_ENDPROTOENT
endprotoent();
#endif

for (current_service = 0;
current_service < (ldns_rdf_size(rdf)-1)*8; current_service++) {
if (ldns_get_bit(&(ldns_rdf_data(rdf)[1]), current_service)) {
Expand All @@ -856,6 +852,11 @@ ldns_rdf2buffer_str_wks(ldns_buffer *output, const ldns_rdf *rdf)
/* exit from loop before integer overflow */
if(current_service == 65535) { break; }
}

#ifdef HAVE_ENDPROTOENT
endprotoent();
#endif

return ldns_buffer_status(output);
}

Expand Down

0 comments on commit 1564b4f

Please sign in to comment.