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
1.9 KiB

  1. From 0bc1c0ae7ce61a7ac8a8e9a9b2086268f011abf0 Mon Sep 17 00:00:00 2001
  2. From: Steve Dickson <steved@redhat.com>
  3. Date: Tue, 9 Oct 2018 09:19:50 -0400
  4. Subject: [PATCH] rpcinfo: Fix stack buffer overflow
  5. buffer overflow detected: rpcinfo terminated
  6. ======= Backtrace: =========
  7. /lib64/libc.so.6(+0x721af)[0x7ff24c4451af]
  8. /lib64/libc.so.6(__fortify_fail+0x37)[0x7ff24c4ccdc7]
  9. /lib64/libc.so.6(+0xf8050)[0x7ff24c4cb050]
  10. rpcinfo(+0x435f)[0xef3be2635f]
  11. rpcinfo(+0x1c62)[0xef3be23c62]
  12. /lib64/libc.so.6(__libc_start_main+0xf5)[0x7ff24c3f36e5]
  13. rpcinfo(+0x2739)[0xef3be24739]
  14. ======= Memory map: ========
  15. ...
  16. The patch below fixes it.
  17. Reviewed-by: Chuck Lever <chuck.lever@oracle.com>
  18. Signed-off-by: Thomas Blume <thomas.blume@suse.com>
  19. Signed-off-by: Steve Dickson <steved@redhat.com>
  20. ---
  21. src/rpcinfo.c | 23 +++++++++++++++++------
  22. 1 file changed, 17 insertions(+), 6 deletions(-)
  23. --- a/src/rpcinfo.c
  24. +++ b/src/rpcinfo.c
  25. @@ -973,6 +973,7 @@ rpcbdump (dumptype, netid, argc, argv)
  26. (" program version(s) netid(s) service owner\n");
  27. for (rs = rs_head; rs; rs = rs->next)
  28. {
  29. + size_t netidmax = sizeof(buf) - 1;
  30. char *p = buf;
  31. printf ("%10ld ", rs->prog);
  32. @@ -985,12 +986,22 @@ rpcbdump (dumptype, netid, argc, argv)
  33. }
  34. printf ("%-10s", buf);
  35. buf[0] = '\0';
  36. - for (nl = rs->nlist; nl; nl = nl->next)
  37. - {
  38. - strcat (buf, nl->netid);
  39. - if (nl->next)
  40. - strcat (buf, ",");
  41. - }
  42. +
  43. + for (nl = rs->nlist; nl; nl = nl->next)
  44. + {
  45. + strncat (buf, nl->netid, netidmax);
  46. + if (strlen (nl->netid) < netidmax)
  47. + netidmax -= strlen(nl->netid);
  48. + else
  49. + break;
  50. +
  51. + if (nl->next && netidmax > 1)
  52. + {
  53. + strncat (buf, ",", netidmax);
  54. + netidmax --;
  55. + }
  56. + }
  57. +
  58. printf ("%-32s", buf);
  59. rpc = getrpcbynumber (rs->prog);
  60. if (rpc)