Blob Blame History Raw
diff --git a/src/addl_data.c b/src/addl_data.c
index 606d53b..33aa235 100644
--- a/src/addl_data.c
+++ b/src/addl_data.c
@@ -71,6 +71,24 @@ insert_addl_data_os(servicelog *slog, struct sl_event *event)
 	else
 		version = os->version;
 
+	if (os->subsystem == NULL) {
+		snprintf(slog->error, SL_MAX_ERR,
+			 "OS subsystem must be specified\n");
+		return -1;
+	}
+
+	if (os->driver == NULL) {
+		snprintf(slog->error, SL_MAX_ERR,
+			 "OS driver must be specified\n");
+		return -1;
+	}
+
+	if (os->device == NULL) {
+		snprintf(slog->error, SL_MAX_ERR,
+			 "Device name must be specified\n");
+		return -1;
+	}
+
 	rc = sqlite3_prepare(slog->db, "INSERT OR REPLACE INTO os (event_id,"
 		" version, subsystem, driver, device) VALUES (?, ?, ?, ?, ?);",
 		 -1, &pstmt, &out);
@@ -81,11 +99,11 @@ insert_addl_data_os(servicelog *slog, struct sl_event *event)
 	rc = rc ? rc : sqlite3_bind_text(pstmt, 2, version,
 				version ? strlen(version):0, SQLITE_STATIC);
 	rc = rc ? rc : sqlite3_bind_text(pstmt, 3, os->subsystem,
-			os->subsystem ? strlen(os->subsystem):0, SQLITE_STATIC);
+			strlen(os->subsystem), SQLITE_STATIC);
 	rc = rc ? rc : sqlite3_bind_text(pstmt, 4, os->driver,
-			os->driver ? strlen(os->driver):0, SQLITE_STATIC);
+			strlen(os->driver), SQLITE_STATIC);
 	rc = rc ? rc : sqlite3_bind_text(pstmt, 5, os->device,
-			os->device ? strlen(os->device):0, SQLITE_STATIC);
+			strlen(os->device), SQLITE_STATIC);
 
 	if (rc != SQLITE_OK)
 		goto sqlt_fail;
@@ -178,12 +196,24 @@ int
 insert_addl_data_enclosure(servicelog *slog, struct sl_event *event)
 {
 	const char *out;
-	int rc;
+	int rc = -1;
 	sqlite3_stmt *pstmt = NULL;
 	struct sl_data_enclosure *encl;
 
 	encl = (struct sl_data_enclosure *)event->addl_data;
 
+	if (encl->enclosure_serial == NULL) {
+		snprintf(slog->error, SL_MAX_ERR,
+			 "Enclosure serial number is NULL\n");
+		return rc;
+	}
+
+	if (encl->enclosure_model == NULL) {
+		snprintf(slog->error, SL_MAX_ERR,
+			 "Enclosure model name is NULL\n");
+		return rc;
+	}
+
 	rc = sqlite3_prepare(slog->db, "INSERT OR REPLACE INTO enclosure"
 		" (event_id, enclosure_model, enclosure_serial) VALUES (?,"
 		" ?, ?);", -1, &pstmt, &out);
@@ -195,11 +225,9 @@ insert_addl_data_enclosure(servicelog *slog, struct sl_event *event)
 
 	rc = sqlite3_bind_int64(pstmt, 1, event->id);
 	rc = rc ? rc : sqlite3_bind_text(pstmt, 2, encl->enclosure_model,
-			encl->enclosure_model ? strlen(encl->enclosure_model):0
-					, SQLITE_STATIC);
+			strlen(encl->enclosure_model), SQLITE_STATIC);
 	rc = rc ? rc : sqlite3_bind_text(pstmt, 3, encl->enclosure_serial,
-		encl->enclosure_serial ? strlen(encl->enclosure_serial):0,
-		SQLITE_STATIC);
+		strlen(encl->enclosure_serial), SQLITE_STATIC);
 
 	if (rc != SQLITE_OK)
 		goto sqlt_fail;
@@ -211,6 +239,7 @@ insert_addl_data_enclosure(servicelog *slog, struct sl_event *event)
 	rc = sqlite3_finalize(pstmt);
 	return rc;
 
+
 sqlt_fail:
 	snprintf(slog->error, SL_MAX_ERR, "%s", sqlite3_errmsg(slog->db));
 	rc = sqlite3_finalize(pstmt);
diff --git a/src/event.c b/src/event.c
index ad40705..32c6a9c 100644
--- a/src/event.c
+++ b/src/event.c
@@ -639,7 +639,7 @@ servicelog_event_query(servicelog *slog, char *query,
 			else if (!strcmp(name, "platform")) {
 				str = (char *)sqlite3_column_text(stmt, i);
 				if (!str)
-					goto free_mem;
+					str = "";
 				e->platform = strdup(str);
 				if (!e->platform)
 					goto free_mem;
@@ -647,7 +647,7 @@ servicelog_event_query(servicelog *slog, char *query,
 			else if (!strcmp(name, "machine_serial")) {
 				str = (char *)sqlite3_column_text(stmt, i);
 				if (!str)
-					goto free_mem;
+					str = "";
 				e->machine_serial = strdup(str);
 				if (!e->machine_serial)
 					goto free_mem;
@@ -655,7 +655,7 @@ servicelog_event_query(servicelog *slog, char *query,
 			else if (!strcmp(name, "machine_model")) {
 				str = (char *)sqlite3_column_text(stmt, i);
 				if (!str)
-					goto free_mem;
+					str = "";
 				e->machine_model = strdup(str);
 				if (!e->machine_model)
 					goto free_mem;
@@ -663,7 +663,7 @@ servicelog_event_query(servicelog *slog, char *query,
 			else if (!strcmp(name, "nodename")) {
 				str = (char *)sqlite3_column_text(stmt, i);
 				if (!str)
-					goto free_mem;
+					str = "";
 				e->nodename = strdup(str);
 				if (!e->nodename)
 					goto free_mem;
@@ -671,7 +671,7 @@ servicelog_event_query(servicelog *slog, char *query,
 			else if (!strcmp(name, "refcode")) {
 				str = (char *)sqlite3_column_text(stmt, i);
 				if (!str)
-					goto free_mem;
+					str = "";
 				e->refcode = strdup(str);
 				if (!e->refcode)
 					goto free_mem;
@@ -679,7 +679,7 @@ servicelog_event_query(servicelog *slog, char *query,
 			else if (!strcmp(name, "description")) {
 				str = (char *)sqlite3_column_text(stmt, i);
 				if (!str)
-					goto free_mem;
+					str = "";
 				e->description = strdup(str);
 				if (!e->description)
 					goto free_mem;
diff --git a/src/notify.c b/src/notify.c
index 9035e6c..e7c9a2c 100644
--- a/src/notify.c
+++ b/src/notify.c
@@ -262,7 +262,7 @@ servicelog_notify_query(servicelog *slog, char *query,
 			else if (!strcmp(name, "command")) {
 				str = (char *)sqlite3_column_text(stmt, i);
 				if (!str)
-					goto free_mem;
+					str = "";
 				n->command = strdup(str);
 				if (!n->command)
 					goto free_mem;
@@ -272,7 +272,7 @@ servicelog_notify_query(servicelog *slog, char *query,
 			else if (!strcmp(name, "match")) {
 				str = (char *)sqlite3_column_text(stmt, i);
 				if (!str)
-					goto free_mem;
+					str = "";
 				n->match = strdup(str);
 				if (!n->match)
 					goto free_mem;
diff --git a/src/repair_action.c b/src/repair_action.c
index ea21e67..1efa05a 100644
--- a/src/repair_action.c
+++ b/src/repair_action.c
@@ -395,7 +395,7 @@ servicelog_repair_query(servicelog *slog, char *query,
 			else if (!strcmp(name, "procedure")) {
 				str = (char *)sqlite3_column_text(stmt, i);
 				if (!str)
-					goto free_mem;
+					str = "";
 				r->procedure = strdup(str);
 				if (!r->procedure)
 					goto free_mem;
@@ -403,7 +403,7 @@ servicelog_repair_query(servicelog *slog, char *query,
 			else if (!strcmp(name, "location")) {
 				str = (char *)sqlite3_column_text(stmt, i);
 				if (!str)
-					goto free_mem;
+					str = "";
 				r->location = strdup(str);
 				if (!r->location)
 					goto free_mem;
@@ -411,7 +411,7 @@ servicelog_repair_query(servicelog *slog, char *query,
 			else if (!strcmp(name, "platform")) {
 				str = (char *)sqlite3_column_text(stmt, i);
 				if (!str)
-					goto free_mem;
+					str = "";
 				r->platform = strdup(str);
 				if (!r->platform)
 					goto free_mem;
@@ -419,7 +419,7 @@ servicelog_repair_query(servicelog *slog, char *query,
 			else if (!strcmp(name, "machine_serial")) {
 				str = (char *)sqlite3_column_text(stmt, i);
 				if (!str)
-					goto free_mem;
+					str = "";
 				r->machine_serial = strdup(str);
 				if (!r->machine_serial)
 					goto free_mem;
@@ -427,7 +427,7 @@ servicelog_repair_query(servicelog *slog, char *query,
 			else if (!strcmp(name, "machine_model")) {
 				str = (char *)sqlite3_column_text(stmt, i);
 				if (!str)
-					goto free_mem;
+					str = "";
 				r->machine_model = strdup(str);
 				if (!r->machine_model)
 					goto free_mem;
@@ -435,7 +435,7 @@ servicelog_repair_query(servicelog *slog, char *query,
 			else if (!strcmp(name, "notes")) {
 				str = (char *)sqlite3_column_text(stmt, i);
 				if (!str)
-					goto free_mem;
+					str = "";
 				r->notes = strdup(str);
 				if (!r->notes)
 					goto free_mem;
diff --git a/src/v29_compat.c b/src/v29_compat.c
index 64afb80..5559bff 100644
--- a/src/v29_compat.c
+++ b/src/v29_compat.c
@@ -401,13 +401,14 @@ convert_encl_to_v29(servicelog *log, struct sl_event *ev, void **data29,
 		return ENOMEM;
 	}
 
+	memset(ev29, 0, ev29_sz);
 	encl29.head.event_length = (uint32_t) ev29_sz;
 	memcpy(ev29, &encl29, sizeof(encl29));
 	next = (char*) ev29;
 	next += sizeof(encl29);
 
 	if (description_sz) {
-		strncpy(next, ev->description, (ev29_sz - sizeof(encl29) - 1));
+		strncpy(next, ev->description, (ev29_sz - sizeof(encl29)));
 		ev29->description = next;
 		next += description_sz;
 	}
@@ -556,17 +557,18 @@ convert_v1_repair_to_v29(servicelog *log, struct sl_repair_action *rpr1,
 		return ENOMEM;
 	}
 
+	memset(ev29, 0, ev29_sz);
 	rpr29.head.event_length = (uint32_t) ev29_sz;
 	memcpy(ev29, &rpr29, sizeof(rpr29));
 	next = (char*) ev29;
 	next += sizeof(rpr29);
 
-	str_size = (ev29_sz - sizeof(rpr29) - 1);
+	str_size = ev29_sz - sizeof(rpr29);
 	if (location_sz) {
 		strncpy(next, rpr1->location, str_size);
 		ev29->location = next;
 		next += location_sz;
-		str_size -= (location_sz + 1);
+		str_size -= location_sz;
 	}
 	if (procedure_sz) {
 		strncpy(next, rpr1->procedure, str_size);