backup: read board vendor/model from the right cJSON nodes - #182
Open
widgetii wants to merge 1 commit into
Open
Conversation
do_upgrade() looked up the "vendor" and "model" items of the board info object, then called cJSON_GetStringValue(binfo) on the *object* instead of on the item it had just found. cJSON_GetStringValue() returns NULL for a non-string, so: - the vendor branch was NULL-guarded and silently did nothing; - the model branch was not, and ran strcpy(board_id, NULL). So `ipctool upgrade` segfaults on any board whose detector supplies a "model" key — currently Ruision, Anjoy and Hankvision (src/boards/*.c) — and on every other board it leaves board_id empty, so the "hardware" U-Boot variable set from it further down never gets written. Read the values from c_vendor/c_model, guard both against NULL, and bound the copies with snprintf: the strings come from board detection (sysinfo files, directory names) and were being strcpy/strcat'ed into fixed 1024-byte buffers unchecked. Behaviour is otherwise preserved, including board_id carrying the model alone. Note: `board` is assembled here but never read afterwards. That is pre-existing, so left alone rather than silently changing what the composed string is meant to be. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
widgetii
marked this pull request as ready for review
July 31, 2026 10:47
PR Summary by QodoFix board vendor/model cJSON access in upgrade path
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTo customize comments, go to the Qodo configuration screen, or learn more in the docs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
do_upgrade()looks up thevendorandmodelitems of the board-info object, then callscJSON_GetStringValue()onbinfo— the object itself — instead of on the item it just found:detect_board()returns an object, andcJSON_GetStringValue()returns NULL for anything that isn't a string, sobstris NULL in both branches. Consequences:strcpy(board_id, NULL).ipctool upgradetherefore segfaults on any board whose detector supplies amodelkey — currently Ruision, Anjoy and Hankvision (src/boards/*.c). On boards without one it survives, butboard_idstays empty, so thehardwareU-Boot variable set from it further down is never written.Fix
Read from
c_vendor/c_model, guard both against NULL, and bound the copies withsnprintf— these strings come from board detection (sysinfo files, directory names) and were beingstrcpy/strcat'ed into fixed 1024-byte buffers unchecked.Behaviour is otherwise preserved, including
board_idcarrying the model alone.Note for the maintainer
boardis assembled here and then never read again. I left that as-is rather than quietly change what the composed string is supposed to mean — happy to drop it, or to switchhardwareto the full"vendor model"string, if either was the original intent.Testing
Compile-tested. I haven't run
ipctool upgradeon a Ruision/Anjoy/Hankvision board — if someone can reproduce the crash on stock master and confirm it's gone here, that would close the loop.