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

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

commit 2d03981a4951631b2d46d11f625dcd77b63981ef
Author: Szymon Janc <[email protected]>
AuthorDate: Thu Oct 22 01:00:42 2026 +0200

    nmxact/xact: Allow image upgrade without progress callback
    
    ImageUpgradeCmd wraps the user's progress callback to track the offset
    for retries after a reconnect, but called the user's callback without
    checking it for nil.  Running an ImageUpgradeCmd without ProgressCb
    (the default from NewImageUpgradeCmd()) crashed with a nil pointer
    dereference on the first response.  ImageUploadCmd already handles a
    nil ProgressCb.
    
    Assisted-by: Claude:claude-opus-5-5
---
 nmxact/xact/image.go             |  4 +++-
 nmxact/xact/image_upload_test.go | 20 ++++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/nmxact/xact/image.go b/nmxact/xact/image.go
index f164ef6..cc021f1 100644
--- a/nmxact/xact/image.go
+++ b/nmxact/xact/image.go
@@ -533,7 +533,9 @@ func (c *ImageUpgradeCmd) runUpload(s sesn.Sesn) 
(*ImageUploadResult, error) {
                if r.Rc == 0 {
                        startOff = int(r.Off)
                }
-               c.ProgressCb(uc, r)
+               if c.ProgressCb != nil {
+                       c.ProgressCb(uc, r)
+               }
        }
 
        for {
diff --git a/nmxact/xact/image_upload_test.go b/nmxact/xact/image_upload_test.go
index 9918602..a27c447 100644
--- a/nmxact/xact/image_upload_test.go
+++ b/nmxact/xact/image_upload_test.go
@@ -624,3 +624,23 @@ func TestImageUploadRunDefaultWindow(t *testing.T) {
        }
        checkUploaded(t, &udev.fakeImgDev, data)
 }
+
+func TestImageUpgradeRunNoProgressCb(t *testing.T) {
+       data := testImage(3000)
+       dev := &imgUpgradeDev{}
+       s := newFakeSesn(dev.handle)
+       dev.s = s
+
+       c := NewImageUpgradeCmd()
+       c.Data = data
+       c.MaxWinSz = 1
+
+       res, err := runCmd(t, c, s)
+       if err != nil {
+               t.Fatal(err)
+       }
+       if st := res.Status(); st != 0 {
+               t.Errorf("status %d", st)
+       }
+       checkUploaded(t, &dev.fakeImgDev, data)
+}

Reply via email to