commit 3dca35f17effa102b7140d5554401ef2292425b7
Author: Aristeu Rozanski <aris@redhat.com>
Date: Tue Jan 7 14:49:19 2020 -0500
rasdaemon: fix error handling in ras_mc_event_opendb()
Found with covscan that the return value from ras_mc_prepare_stmt() and from
ras_mc_event_opendb() itself aren't checked.
Signed-off-by: Aristeu Rozanski <aris@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
ras-events.c | 17 +++++++++++++----
ras-record.c | 42 +++++++++++++++++++++++++++++++-----------
2 files changed, 44 insertions(+), 15 deletions(-)
--- rasdaemon-0.4.1.orig/ras-events.c 2020-03-18 15:58:10.477721778 -0400
+++ rasdaemon-0.4.1/ras-events.c 2020-03-18 15:59:05.398236266 -0400
@@ -348,8 +348,10 @@ if (fds[i].fd < 0) {
}
log(TERM, LOG_INFO, "Listening to events for cpus 0 to %d\n", n_cpus - 1);
- if (pdata[0].ras->record_events)
- ras_mc_event_opendb(pdata[0].cpu, pdata[0].ras);
+ if (pdata[0].ras->record_events) {
+ if (ras_mc_event_opendb(pdata[0].cpu, pdata[0].ras))
+ goto error;
+ }
do {
ready = poll(fds, n_cpus, -1);
@@ -485,8 +487,15 @@ if (fd < 0) {
}
log(TERM, LOG_INFO, "Listening to events on cpu %d\n", pdata->cpu);
- if (pdata->ras->record_events)
- ras_mc_event_opendb(pdata->cpu, pdata->ras);
+ if (pdata->ras->record_events) {
+ if (ras_mc_event_opendb(pdata->cpu, pdata->ras)) {
+ log(TERM, LOG_ERR, "Can't open database\n");
+ close(fd);
+ kbuffer_free(kbuf);
+ free(page);
+ return 0;
+ }
+ }
read_ras_event(fd, pdata, kbuf, page);
--- rasdaemon-0.4.1.orig/ras-record.c 2020-03-18 15:58:10.478721769 -0400
+++ rasdaemon-0.4.1/ras-record.c 2020-03-18 16:02:31.382415310 -0400
@@ -506,8 +506,7 @@ int ras_mc_event_opendb(unsigned cpu, st
log(TERM, LOG_ERR,
"cpu %u: Failed to initialize sqlite: error = %d\n",
cpu, rc);
- free(priv);
- return -1;
+ goto error;
}
do {
@@ -523,51 +522,72 @@ usleep(10000);
log(TERM, LOG_ERR,
"cpu %u: Failed to connect to %s: error = %d\n",
cpu, SQLITE_RAS_DB, rc);
- free(priv);
- return -1;
+ goto error;
}
priv->db = db;
rc = ras_mc_create_table(priv, &mc_event_tab);
- if (rc == SQLITE_OK)
+ if (rc == SQLITE_OK) {
rc = ras_mc_prepare_stmt(priv, &priv->stmt_mc_event,
&mc_event_tab);
+ if (rc != SQLITE_OK)
+ goto error;
+ }
#ifdef HAVE_AER
rc = ras_mc_create_table(priv, &aer_event_tab);
- if (rc == SQLITE_OK)
+ if (rc == SQLITE_OK) {
rc = ras_mc_prepare_stmt(priv, &priv->stmt_aer_event,
&aer_event_tab);
+ if (rc != SQLITE_OK)
+ goto error;
+ }
#endif
#ifdef HAVE_EXTLOG
rc = ras_mc_create_table(priv, &extlog_event_tab);
- if (rc == SQLITE_OK)
+ if (rc == SQLITE_OK) {
rc = ras_mc_prepare_stmt(priv, &priv->stmt_extlog_record,
&extlog_event_tab);
+ if (rc != SQLITE_OK)
+ goto error;
+ }
#endif
#ifdef HAVE_MCE
rc = ras_mc_create_table(priv, &mce_record_tab);
- if (rc == SQLITE_OK)
+ if (rc == SQLITE_OK) {
rc = ras_mc_prepare_stmt(priv, &priv->stmt_mce_record,
&mce_record_tab);
+ if (rc != SQLITE_OK)
+ goto error;
+ }
#endif
#ifdef HAVE_NON_STANDARD
rc = ras_mc_create_table(priv, &non_standard_event_tab);
- if (rc == SQLITE_OK)
+ if (rc == SQLITE_OK) {
rc = ras_mc_prepare_stmt(priv, &priv->stmt_non_standard_record,
&non_standard_event_tab);
+ if (rc != SQLITE_OK)
+ goto error;
+ }
#endif
#ifdef HAVE_ARM
rc = ras_mc_create_table(priv, &arm_event_tab);
- if (rc == SQLITE_OK)
+ if (rc == SQLITE_OK) {
rc = ras_mc_prepare_stmt(priv, &priv->stmt_arm_record,
&arm_event_tab);
+ if (rc != SQLITE_OK)
+ goto error;
+ }
#endif
- ras->db_priv = priv;
+ ras->db_priv = priv;
return 0;
+
+error:
+ free(priv);
+ return -1;
}