You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.3 KiB

  1. From 8614cf0ad4a017184285e814a704322f59a28869 Mon Sep 17 00:00:00 2001
  2. From: Michael Heimpold <mhei@heimpold.de>
  3. Date: Wed, 12 Apr 2017 23:36:17 +0200
  4. Subject: [PATCH] dataxfer.c: fix possible buffer overruns caused by
  5. gai_strerror
  6. This fixes a possible buffer overrun that could occur due to
  7. gai_strerror() returning a string which is longer than the portbuff
  8. array, i.e. longer than 32 byte.
  9. Reported-by: David Thornley <david.thornley@touchstargroup.com>
  10. Signed-off-by: Michael Heimpold <mhei@heimpold.de>
  11. Signed-off-by: Corey Minyard <cminyard@mvista.com>
  12. diff --git a/dataxfer.c b/dataxfer.c
  13. index 3d1e713..988f4e4 100644
  14. --- a/dataxfer.c
  15. +++ b/dataxfer.c
  16. @@ -3702,18 +3702,20 @@ showshortport(struct controller_info *cntlr, port_info_t *port)
  17. portbuff, sizeof(portbuff),
  18. NI_NUMERICHOST | NI_NUMERICSERV);
  19. if (err) {
  20. - strcpy(buffer, "*err*");
  21. - sprintf(portbuff, "%s", gai_strerror(err));
  22. + snprintf(buffer, sizeof(buffer), "*err*,%s", gai_strerror(err));
  23. + count = controller_outputf(cntlr, "%s", buffer);
  24. + } else {
  25. + count = controller_outputf(cntlr, "%s,%s", buffer, portbuff);
  26. }
  27. - bytes_recv = netcon->bytes_received;
  28. - bytes_sent = netcon->bytes_sent;
  29. - count = controller_outputf(cntlr, "%s,%s", buffer, portbuff);
  30. while (count < 23) {
  31. controller_outs(cntlr, " ");
  32. count++;
  33. }
  34. + bytes_recv = netcon->bytes_received;
  35. + bytes_sent = netcon->bytes_sent;
  36. +
  37. controller_outputf(cntlr, "%-22s ", port->io.devname);
  38. controller_outputf(cntlr, "%-14s ", state_str[port->net_to_dev_state]);
  39. controller_outputf(cntlr, "%-14s ", state_str[port->dev_to_net_state]);
  40. @@ -3758,11 +3760,12 @@ showport(struct controller_info *cntlr, port_info_t *port)
  41. portbuff, sizeof(portbuff),
  42. NI_NUMERICHOST | NI_NUMERICSERV);
  43. if (err) {
  44. - strcpy(buffer, "*err*");
  45. - sprintf(portbuff, "%s", gai_strerror(err));
  46. + snprintf(buffer, sizeof(buffer), "*err*,%s", gai_strerror(err));
  47. + controller_outputf(cntlr, " connected to: %s\r\n", buffer);
  48. + } else {
  49. + controller_outputf(cntlr, " connected to: %s,%s\r\n",
  50. + buffer, portbuff);
  51. }
  52. - controller_outputf(cntlr, " connected to: %s,%s\r\n",
  53. - buffer, portbuff);
  54. controller_outputf(cntlr, " bytes read from TCP: %d\r\n",
  55. netcon->bytes_received);
  56. controller_outputf(cntlr, " bytes written to TCP: %d\r\n",
  57. --
  58. 2.7.4