123456789101112131415161718192021222324252627282930313233343536 |
- Description: Fix array out of bond access in process()
- Author: Christoph Biedl <debian.axhn@manchmal.in-ulm.de>
- Bug: https://bitbucket.org/ripencc/bgpdump/issue/19/
- Last-Update: 2016-07-13
- The current code happily assumes the state value is within the range
- of hard-coded values. Handle unknown values gracefully.
- --- a/bgpdump.c
- +++ b/bgpdump.c
- @@ -244,6 +244,15 @@
- NULL
- };
-
- +static const char *bgp_state_name_lookup(unsigned state, char *buffer) {
- + if (state >= sizeof(bgp_state_name)/sizeof(bgp_state_name[0])-1) {
- + sprintf(buffer, "Unknown-%u", state);
- + return buffer;
- + }
- + return bgp_state_name[state];
- +}
- +
- +
- void process(BGPDUMP_ENTRY *entry) {
-
- struct tm *date;
- @@ -926,7 +935,8 @@
- // printf(" N/A ");
- printf("AS%u\n",entry->body.zebra_state_change.source_as);
-
- - printf("STATE: %s/%s\n",bgp_state_name[entry->body.zebra_state_change.old_state],bgp_state_name[entry->body.zebra_state_change.new_state]);
- + char temp1[16], temp2[16];
- + printf("STATE: %s/%s\n",bgp_state_name_lookup(entry->body.zebra_state_change.old_state,temp1),bgp_state_name_lookup(entry->body.zebra_state_change.new_state,temp2));
- }
- else if (mode==1 || mode==2 ) //-m -M
- {
|