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.

84 lines
2.1 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. --- a/pki.c
  11. +++ b/pki.c
  12. @@ -9,12 +9,13 @@
  13. #include <unistd.h>
  14. #include <limits.h>
  15. #include "config.h"
  16. +#include <fcntl.h>
  17. +#include <assert.h>
  18. #ifdef WITH_SECURITY
  19. #include <openssl/pem.h>
  20. #include <openssl/err.h>
  21. #include <openssl/evp.h>
  22. #endif
  23. -#include <fcntl.h>
  24. #include <libisns/isns.h>
  25. #include "security.h"
  26. #include <libisns/util.h>
  27. @@ -431,17 +432,43 @@ isns_dsa_load_params(const char *filenam
  28. return dsa;
  29. }
  30. +/*
  31. + * write one 'status' character to stdout
  32. + */
  33. +static void
  34. +write_status_byte(int ch)
  35. +{
  36. + static int stdout_fd = 1; /* fileno(stdout) */
  37. + char buf[2];
  38. + int res;
  39. +
  40. + /*
  41. + * We don't actually care about the return value here, since
  42. + * we are just dumping a status byte to stdout, but
  43. + * some linux distrubutions set the warn_unused_result attribute
  44. + * for the write() API, so we might as well use the return value
  45. + * to make sure the write command isn't broken.
  46. + */
  47. + assert(ch);
  48. + buf[0] = ch;
  49. + buf[1] = '\0';
  50. + res = write(stdout_fd, buf, 1);
  51. + assert(res == 1);
  52. +}
  53. +
  54. static int
  55. isns_dsa_param_gen_callback(int stage,
  56. __attribute__((unused))int index,
  57. __attribute__((unused))void *dummy)
  58. {
  59. if (stage == 0)
  60. - write(1, "+", 1);
  61. + write_status_byte('+');
  62. else if (stage == 1)
  63. - write(1, ".", 1);
  64. + write_status_byte('.');
  65. else if (stage == 2)
  66. - write(1, "/", 1);
  67. + write_status_byte('/');
  68. +
  69. + /* as a callback, we must return a value, so just return success */
  70. return 0;
  71. }
  72. @@ -478,7 +505,7 @@ isns_dsa_init_params(const char *filenam
  73. dsa = DSA_generate_parameters(dsa_key_bits, NULL, 0,
  74. NULL, NULL, isns_dsa_param_gen_callback, NULL);
  75. #endif
  76. - write(1, "\n", 1);
  77. + write_status_byte('\n');
  78. if (dsa == NULL) {
  79. isns_dsasig_report_errors("Error generating DSA parameters",