fix-bgp-state-out-of-bonds.patch 1.2 KB

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