4 Star 0 Fork 3

src-openEuler/vhostmd

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0004-libmetrics-Check-return-value-of-asprintf.patch 2.63 KB
一键复制 编辑 原始数据 按行查看 历史
shenhy123 提交于 2021-09-01 09:53 . Add vhostmd
From f659ec774221532cc5452a07418e2ab1385f162c Mon Sep 17 00:00:00 2001
From: Jim Fehlig <jfehlig@suse.com>
Date: Mon, 6 Jan 2020 16:43:21 -0700
Subject: [PATCH 04/19] libmetrics: Check return value of asprintf
Exmaple from coverity scan
vhostmd-1.1/libmetrics/libmetrics.c: scope_hint: In function 'get_mdef'
vhostmd-1.1/libmetrics/libmetrics.c:231:4: warning: ignoring return value of 'asprintf', declared with attribute warn_unused_result [-Wunused-result]
asprintf(&xpath, "//metrics/metric[name='%s'][@context='%s']", pmdef->name, pmdef->context);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
---
libmetrics/libmetrics.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/libmetrics/libmetrics.c b/libmetrics/libmetrics.c
index 49b38ea..4b2369a 100644
--- a/libmetrics/libmetrics.c
+++ b/libmetrics/libmetrics.c
@@ -236,7 +236,9 @@ static int get_mdef(metric_disk *mdisk, private_metric *pmdef)
}
/* Get the matching metric node type */
- asprintf(&xpath, "//metrics/metric[name='%s'][@context='%s']", pmdef->name, pmdef->context);
+ if (asprintf(&xpath, "//metrics/metric[name='%s'][@context='%s']", pmdef->name, pmdef->context) < 0)
+ goto out;
+
obj = xmlXPathEval(BAD_CAST xpath, ctxt);
free(xpath);
if ((obj == NULL) || (obj->type != XPATH_NODESET)) {
@@ -259,7 +261,9 @@ static int get_mdef(metric_disk *mdisk, private_metric *pmdef)
xmlXPathFreeObject(obj);
/* Get the matching metric node value */
- asprintf(&xpath, "//metrics/metric[name='%s'][@context='%s']/value/text()", pmdef->name, pmdef->context);
+ if (asprintf(&xpath, "//metrics/metric[name='%s'][@context='%s']/value/text()", pmdef->name, pmdef->context) < 0)
+ goto out;
+
obj = xmlXPathEval( BAD_CAST xpath, ctxt); /* worked but no nodes */
free(xpath);
if ((obj == NULL) || (obj->type != XPATH_NODESET)) {
@@ -349,7 +353,8 @@ retry:
strcmp(entry->d_name, "..") == 0)
continue;
- asprintf(&path, "/dev/%s", entry->d_name);
+ if (asprintf(&path, "/dev/%s", entry->d_name) < 0)
+ goto error;
#else
path = strdup("/dev/shm/vhostmd0");
#endif
@@ -737,7 +742,9 @@ int dump_xenstore_metrics(const char *dest_file)
libmsg("xs_get_domain_path() error. domid %d.\n", 0);
goto out;
}
- asprintf(&buf, "%s/metrics", path);
+ if (asprintf(&buf, "%s/metrics", path) , 0)
+ goto out;
+
metrics = xs_read(xsh, XBT_NULL, buf, &len);
if (metrics == NULL) {
libmsg("xs_read(): uuid get error. %s.\n", buf);
--
2.32.0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-openeuler/vhostmd.git
git@gitee.com:src-openeuler/vhostmd.git
src-openeuler
vhostmd
vhostmd
master

搜索帮助