This is an automated email from the ASF dual-hosted git repository.

vipulrahane pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 89ba023f8 sys/reboot_log: Fix crash on rotate (#3413)
89ba023f8 is described below

commit 89ba023f86d9f2b104da7c24c05c71f7ebff2ad9
Author: Vipul Rahane <[email protected]>
AuthorDate: Thu Apr 24 16:06:08 2025 -0700

    sys/reboot_log: Fix crash on rotate (#3413)
    
    - Reboot was crashing on rotate because the `l_arg` which points to the
    `fcb_log` was actually getting set to the `fcb`, thereby causing a
    crash. This fixes it.
---
 sys/log/full/src/log_fcb.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/sys/log/full/src/log_fcb.c b/sys/log/full/src/log_fcb.c
index 9c7a02088..48bcfc329 100644
--- a/sys/log/full/src/log_fcb.c
+++ b/sys/log/full/src/log_fcb.c
@@ -914,7 +914,8 @@ log_fcb_copy_entry(struct log *log, struct fcb_entry *entry,
     uint16_t hdr_len;
     int dlen;
     int rc;
-    struct fcb *fcb_tmp;
+    struct fcb_log fcb_log_tmp;
+    struct fcb_log *fcb_log_ptr;
 
     rc = log_fcb_read(log, entry, &ueh, 0, LOG_BASE_ENTRY_HDR_SIZE);
 
@@ -932,12 +933,19 @@ log_fcb_copy_entry(struct log *log, struct fcb_entry 
*entry,
         goto err;
     }
 
-    /* Changing the fcb to be logged to be dst fcb */
-    fcb_tmp = &((struct fcb_log *)log->l_arg)->fl_fcb;
+    /* Cache fcb_log pointer */
+    fcb_log_ptr = (struct fcb_log *)log->l_arg;
 
-    log->l_arg = dst_fcb;
+    /* Cache the fcb log, so that we preserve original fcb pointer */
+    fcb_log_tmp = *fcb_log_ptr;
+    fcb_log_tmp.fl_fcb = *dst_fcb;
+    log->l_arg = &fcb_log_tmp;
     rc = log_fcb_append(log, data, dlen);
-    log->l_arg = fcb_tmp;
+
+    /* Restore the original fcb_log pointer */
+    log->l_arg = fcb_log_ptr;
+    *dst_fcb = fcb_log_tmp.fl_fcb;
+
     if (rc) {
         goto err;
     }

Reply via email to