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.

86 lines
2.2 KiB

  1. From 4c39cb09735a494099fba0474d25ff26800de952 Mon Sep 17 00:00:00 2001
  2. From: Lee Duncan <lduncan@suse.com>
  3. Date: Wed, 29 Jan 2020 12:47:16 -0800
  4. Subject: [PATCH] Do not ignore write() return value.
  5. Some distros set the warn_unused_result attribute for the write()
  6. system call, so check the return value.
  7. ---
  8. pki.c | 37 ++++++++++++++++++++++++++++++++-----
  9. 1 file changed, 32 insertions(+), 5 deletions(-)
  10. diff --git a/pki.c b/pki.c
  11. index 486d9bb..57ea664 100644
  12. --- a/pki.c
  13. +++ b/pki.c
  14. @@ -9,12 +9,13 @@
  15. #include <unistd.h>
  16. #include <limits.h>
  17. #include "config.h"
  18. +#include <fcntl.h>
  19. +#include <assert.h>
  20. #ifdef WITH_SECURITY
  21. #include <openssl/pem.h>
  22. #include <openssl/err.h>
  23. #include <openssl/evp.h>
  24. #endif
  25. -#include <fcntl.h>
  26. #include <libisns/isns.h>
  27. #include "security.h"
  28. #include <libisns/util.h>
  29. @@ -431,17 +432,43 @@ isns_dsa_load_params(const char *filename)
  30. return dsa;
  31. }
  32. +/*
  33. + * write one 'status' character to stdout
  34. + */
  35. +static void
  36. +write_status_byte(int ch)
  37. +{
  38. + static int stdout_fd = 1; /* fileno(stdout) */
  39. + char buf[2];
  40. + int res;
  41. +
  42. + /*
  43. + * We don't actually care about the return value here, since
  44. + * we are just dumping a status byte to stdout, but
  45. + * some linux distrubutions set the warn_unused_result attribute
  46. + * for the write() API, so we might as well use the return value
  47. + * to make sure the write command isn't broken.
  48. + */
  49. + assert(ch);
  50. + buf[0] = ch;
  51. + buf[1] = '\0';
  52. + res = write(stdout_fd, buf, 1);
  53. + assert(res == 1);
  54. +}
  55. +
  56. static int
  57. isns_dsa_param_gen_callback(int stage,
  58. __attribute__((unused))int index,
  59. __attribute__((unused))void *dummy)
  60. {
  61. if (stage == 0)
  62. - write(1, "+", 1);
  63. + write_status_byte('+');
  64. else if (stage == 1)
  65. - write(1, ".", 1);
  66. + write_status_byte('.');
  67. else if (stage == 2)
  68. - write(1, "/", 1);
  69. + write_status_byte('/');
  70. +
  71. + /* as a callback, we must return a value, so just return success */
  72. return 0;
  73. }
  74. @@ -478,7 +505,7 @@ isns_dsa_init_params(const char *filename)
  75. dsa = DSA_generate_parameters(dsa_key_bits, NULL, 0,
  76. NULL, NULL, isns_dsa_param_gen_callback, NULL);
  77. #endif
  78. - write(1, "\n", 1);
  79. + write_status_byte('\n');
  80. if (dsa == NULL) {
  81. isns_dsasig_report_errors("Error generating DSA parameters",