[PATCH] lib: fwts_klog: handle the case where klog_old is empty list
Colin King
colin.king at canonical.com
Wed Feb 17 00:01:40 UTC 2016
From: Colin Ian King <colin.king at canonical.com>
scan-build detected that an empty klog_old list would lead to l_old_last
being null and hence we get a null pointer dereference when assigning
old to the data in the null list. Check for a empty list and ensure
l_new is initialized to NULL for this corner case.
Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
src/lib/src/fwts_klog.c | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/src/lib/src/fwts_klog.c b/src/lib/src/fwts_klog.c
index 48a0e45..b5f0965 100644
--- a/src/lib/src/fwts_klog.c
+++ b/src/lib/src/fwts_klog.c
@@ -51,7 +51,7 @@ void fwts_klog_free(fwts_list *klog)
*/
fwts_list *fwts_klog_find_changes(fwts_list *klog_old, fwts_list *klog_new)
{
- fwts_list_link *l_old, *l_new;
+ fwts_list_link *l_old, *l_new = NULL;
fwts_list *klog_diff;
if (klog_new == NULL) {
@@ -74,14 +74,17 @@ fwts_list *fwts_klog_find_changes(fwts_list *klog_old, fwts_list *klog_new)
fwts_list_foreach(l_old, klog_old)
l_old_last = l_old;
- /* And now look for that last line in the new log */
- old = fwts_list_data(char *, l_old_last);
- fwts_list_foreach(l_new, klog_new) {
- char *new = fwts_list_data(char *, l_new);
- if (!strcmp(new, old)) {
- /* Found last line that matches, bump to next */
- l_new = l_new->next;
- break;
+ if (l_old_last) {
+ /* And now look for that last line in the new log */
+ old = fwts_list_data(char *, l_old_last);
+ fwts_list_foreach(l_new, klog_new) {
+ const char *new = fwts_list_data(char *, l_new);
+
+ if (!strcmp(new, old)) {
+ /* Found last line that matches, bump to next */
+ l_new = l_new->next;
+ break;
+ }
}
}
}
--
2.7.0
More information about the fwts-devel
mailing list