clean up librtas by using rtas_cop

This commit is contained in:
Than Ngo 2021-04-06 17:20:00 +02:00
parent c59e1a2530
commit 2d881a3fdf
2 changed files with 57 additions and 65 deletions

View File

@ -1,55 +1,3 @@
diff -up librtas-2.0.2/librtasevent_src/rtas_srcfru.c.me librtas-2.0.2/librtasevent_src/rtas_srcfru.c
--- librtas-2.0.2/librtasevent_src/rtas_srcfru.c.me 2021-03-25 09:43:12.764393426 +0100
+++ librtas-2.0.2/librtasevent_src/rtas_srcfru.c 2021-03-25 10:00:06.013239296 +0100
@@ -238,9 +238,10 @@ parse_src_scn(struct rtas_event *re)
add_re_scn(re, src, re_scn_id(&src_raw->v6hdr));
- if (!src_subscns_included(src))
+ if (!src_subscns_included(src)) {
+ free (src_raw);
return 0;
-
+ }
rtas_copy( (char *) src_raw + RE_SRC_SCN_SZ + 4, re, RE_SRC_SUBSCN_SZ);
src->subscn_id = src_raw->subscn_id;
@@ -260,6 +261,7 @@ parse_src_scn(struct rtas_event *re)
if (fru == NULL) {
cleanup_rtas_event(re);
errno = ENOMEM;
+ free(src_raw);
return 1;
}
@@ -288,6 +290,8 @@ parse_src_scn(struct rtas_event *re)
if (cur_fruhdr == NULL) {
cleanup_rtas_event(re);
+ free(src_raw);
+ free(fru);
return -1;
}
@@ -309,6 +313,7 @@ parse_src_scn(struct rtas_event *re)
total_len += fru->length;
} while (total_len < srcsub_len);
+ free(src_raw);
return 0;
}
diff -up librtas-2.0.2/librtasevent_src/rtas_vend.c.me librtas-2.0.2/librtasevent_src/rtas_vend.c
--- librtas-2.0.2/librtasevent_src/rtas_vend.c.me 2021-03-25 10:00:29.520558410 +0100
+++ librtas-2.0.2/librtasevent_src/rtas_vend.c 2021-03-25 10:03:25.367951457 +0100
@@ -116,6 +116,7 @@ parse_vend_errlog_scn(struct rtas_event
ve->vendor_data = malloc(ve->vendor_data_sz);
if (ve->vendor_data == NULL) {
errno = ENOMEM;
+ free(ve);
return -1;
}
diff -up librtas-2.0.2/librtasevent_src/get_rtas_event.c.me librtas-2.0.2/librtasevent_src/get_rtas_event.c
--- librtas-2.0.2/librtasevent_src/get_rtas_event.c.me 2021-03-25 11:26:19.754142871 +0100
+++ librtas-2.0.2/librtasevent_src/get_rtas_event.c 2021-03-25 11:29:24.322686995 +0100
@ -128,25 +76,66 @@ diff -up librtas-2.0.2/librtas_src/syscall_rmo.c.me librtas-2.0.2/librtas_src/sy
if (bits != ((1 << n_pages) - 1)) {
dbg("Invalid region [0x%x, 0x%zx]\n", phys_addr, size);
return RTAS_IO_ASSERT;
diff -up librtas-2.0.2/librtasevent_src/rtas_srcfru.c.me librtas-2.0.2/librtasevent_src/rtas_srcfru.c
--- librtas-2.0.2/librtasevent_src/rtas_srcfru.c.me 2021-03-25 15:31:32.490312970 +0100
+++ librtas-2.0.2/librtasevent_src/rtas_srcfru.c 2021-03-25 15:34:07.641418530 +0100
@@ -73,13 +73,16 @@ parse_fru_id_scn(struct rtas_event *re)
parse_fru_hdr(&fru_id->fruhdr, &fru_id_raw->fruhdr);
diff --git a/librtasevent_src/rtas_srcfru.c b/librtasevent_src/rtas_srcfru.c
index 23c8584..a2eac9a 100644
--- a/librtasevent_src/rtas_srcfru.c
+++ b/librtasevent_src/rtas_srcfru.c
@@ -74,13 +74,13 @@ parse_fru_id_scn(struct rtas_event *re)
re->offset += RE_FRU_HDR_SZ;
+ int len_procedure_id = strlen(fru_id->procedure_id);
+ int len_part_no = strlen(fru_id->part_no);
+
if (fruid_has_part_no(fru_id)) {
- strcpy(fru_id->part_no, RE_EVENT_OFFSET(re));
+ strncpy(fru_id->part_no, RE_EVENT_OFFSET(re), len_part_no);
re->offset += 8;
- re->offset += 8;
+ rtas_copy(fru_id->part_no, re, 7);
+ fru_id->part_no[7] = '\0';
}
if (fruid_has_proc_id(fru_id)) {
- strcpy(fru_id->procedure_id, RE_EVENT_OFFSET(re));
+ strncpy(fru_id->procedure_id, RE_EVENT_OFFSET(re), len_procedure_id);
re->offset += 8;
- re->offset += 8;
+ rtas_copy(fru_id->procedure_id, re, 7);
+ fru_id->procedure_id[7] = '\0';
}
if (fruid_has_ccin(fru_id)) {
@@ -238,9 +238,10 @@ parse_src_scn(struct rtas_event *re)
add_re_scn(re, src, re_scn_id(&src_raw->v6hdr));
- if (!src_subscns_included(src))
+ if (!src_subscns_included(src)) {
+ free (src_raw);
return 0;
-
+ }
rtas_copy( (char *) src_raw + RE_SRC_SCN_SZ + 4, re, RE_SRC_SUBSCN_SZ);
src->subscn_id = src_raw->subscn_id;
@@ -251,6 +252,7 @@ parse_src_scn(struct rtas_event *re)
total_len = RE_SRC_SUBSCN_SZ;
last_fru = NULL;
+ free(src_raw);
do {
uint32_t fru_len, fru_end;
@@ -288,6 +290,7 @@ parse_src_scn(struct rtas_event *re)
if (cur_fruhdr == NULL) {
cleanup_rtas_event(re);
+ free(fru);
return -1;
}
diff --git a/librtasevent_src/rtas_vend.c b/librtasevent_src/rtas_vend.c
index 6fa717e..2814726 100644
--- a/librtasevent_src/rtas_vend.c
+++ b/librtasevent_src/rtas_vend.c
@@ -116,6 +116,7 @@ parse_vend_errlog_scn(struct rtas_event *re)
ve->vendor_data = malloc(ve->vendor_data_sz);
if (ve->vendor_data == NULL) {
errno = ENOMEM;
+ free(ve);
return -1;
}

View File

@ -1,7 +1,7 @@
Summary: Libraries to provide access to RTAS calls and RTAS events
Name: librtas
Version: 2.0.2
Release: 9%{?dist}
Release: 10%{?dist}
URL: https://github.com/nfont/librtas
License: LGPL
@ -68,6 +68,9 @@ rm -f %{buildroot}/%{_docdir}/librtas/*
%{_includedir}/librtasevent_v6.h
%changelog
* Fri Mar 26 2021 Than Ngo <than@redhat.com> - 2.0.2-10
- clean up librtas by using rtas_copy
* Thu Mar 25 2021 Than Ngo <than@redhat.com> - 2.0.2-9
- Undo ExclusiveArch