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.
68 lines
2.6 KiB
68 lines
2.6 KiB
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
|
|
|