Skip to content

Commit

Permalink
Check for malloc failing in pcap_ether_aton().
Browse files Browse the repository at this point in the history
That also means that the lexical analyzer, which calls
pcap_ether_aton(), needs to check for pcap_ether_aton() failing.
  • Loading branch information
guyharris committed Apr 14, 2013
1 parent 8a90ccf commit c8e2d55
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nametoaddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ pcap_ether_aton(const char *s)
register u_int d;

e = ep = (u_char *)malloc(6);
if (e == NULL)
return (NULL);

while (*s) {
if (*s == ':' || *s == '.' || *s == '-')
Expand Down
4 changes: 4 additions & 0 deletions scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,12 @@ sls return SLS;
"<<" return LSH;
">>" return RSH;
${B} { yylval.e = pcap_ether_aton(((char *)yytext)+1);
if (yylval.e == NULL)
bpf_error("malloc");
return AID; }
{MAC} { yylval.e = pcap_ether_aton((char *)yytext);
if (yylval.e == NULL)
bpf_error("malloc");
return EID; }
{N} { yylval.i = stoi((char *)yytext); return NUM; }
({N}\.{N})|({N}\.{N}\.{N})|({N}\.{N}\.{N}\.{N}) {
Expand Down

0 comments on commit c8e2d55

Please sign in to comment.