1 Star 0 Fork 14

lyn/open-isns

forked from src-openEuler/open-isns 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Fix-the-issue-of-ignoring-the-return-value.patch 2.18 KB
一键复制 编辑 原始数据 按行查看 历史
lyn 提交于 2020-06-02 10:12 +08:00 . Package update
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(-)
diff --git a/pki.c b/pki.c
index 486d9bb..57ea664 100644
--- 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 *filename)
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 *filename)
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",
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lyn1001/open-isns.git
git@gitee.com:lyn1001/open-isns.git
lyn1001
open-isns
open-isns
master

搜索帮助