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