Skip to content

(#9400 P3b,P3c) read -r and safe array assignment#9406

Open
iav wants to merge 2 commits intoarmbian:mainfrom
iav:fix/p3bc-read-and-array
Open

(#9400 P3b,P3c) read -r and safe array assignment#9406
iav wants to merge 2 commits intoarmbian:mainfrom
iav:fix/p3bc-read-and-array

Conversation

@iav
Copy link
Contributor

@iav iav commented Feb 16, 2026

Summary

Test plan

  • Verify userpatch_create interactive prompt still works correctly with backslash-containing input
  • Verify kernel freeze pin parsing still works for KERNEL_UPGRADE_FREEZE values

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved parsing for kernel upgrade pin variants to handle complex inputs more reliably.
    • Fixed interactive input handling to prevent unintended backslash interpretation.
  • Refactor

    • Reworked bootscript template rendering flow for more consistent structure and maintainability.

@iav iav requested a review from a team as a code owner February 16, 2026 17:34
@github-actions github-actions bot added size/small PR with less then 50 lines 02 Milestone: First quarter release labels Feb 16, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 1c5c967 and 8dd2c10.

📒 Files selected for processing (2)
  • lib/functions/bsp/armbian-bsp-cli-deb.sh
  • lib/functions/compilation/patch/patching.sh
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/functions/compilation/patch/patching.sh

📝 Walkthrough

Walkthrough

Refinements to two shell scripts: bootscript template rendering code reflowed in the BSP CLI, kernel upgrade freeze pin parsing switched to IFS/read for robust splitting, and the patch subject read now uses -r to prevent backslash interpretation.

Changes

Cohort / File(s) Summary
BSP Bootscript & Kernel Pin Handling
lib/functions/bsp/armbian-bsp-cli-deb.sh
Reflowed bootscript template rendering with explicit destination reference; kernel upgrade freeze parsing changed from simple token substitution to IFS=' ' read -ra into extracted_pins for more robust field splitting.
Patch Input Processing
lib/functions/compilation/patch/patching.sh
Interactive read for patch subject now uses read -r to treat backslashes as literal characters rather than escape sequences.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I nibble code by lantern light,
I split the pins and keep them tight,
I read the subject, backslashes stay,
Bootscripts land in tidy array,
Small hops, big builds — I cheer the byte. 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly references the two main changes (read -r flag and safe array assignment) that are implemented in the PR and clearly matches the file modifications described.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added Needs review Seeking for review Framework Framework components labels Feb 16, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
lib/functions/bsp/armbian-bsp-cli-deb.sh (1)

235-236: Good fix for glob-safe array assignment.

Line 236 correctly prevents glob expansion for values containing * or ?.

Note: Line 235 still uses unquoted $KERNEL_UPGRADE_FREEZE in the $(echo $KERNEL_UPGRADE_FREEZE | sed ...) command substitution, which has the same glob expansion risk this PR aims to fix. Consider quoting it as "$KERNEL_UPGRADE_FREEZE" for consistency.

Proposed fix
-		for pin_variants in $(echo $KERNEL_UPGRADE_FREEZE | sed "s/,/ /g"); do
+		for pin_variants in $(echo "$KERNEL_UPGRADE_FREEZE" | sed "s/,/ /g"); do

@@ -233,7 +233,7 @@ function compile_armbian-bsp-cli() {
# if freeze variable is removed, upgrade becomes possible again
if [[ "${BETA}" != "yes" ]]; then
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@igorpecovnik @rpardini Question about the existing logic around this code:

if [[ "${BETA}" != "yes" ]]; then
    for pin_variants in ...; do
        ...
    done
else
    touch "${destination}"/etc/apt/preferences.d/frozen-armbian
fi

Is this BETA check intentional here? The current behavior:

  • BETA=yes (nightly) → touch creates an empty frozen-armbian (no actual pinning)
  • BETA=no (stable) → freeze logic runs, pins are written
  • BETA unset (user-built) → freeze logic runs, but KERNEL_UPGRADE_FREEZE is typically empty so loop does nothing

The empty touch in the else branch for nightly builds seems like a no-op — dpkg-deb includes the 0-byte file, but it has no effect on apt.

Was this designed this way, or should the condition be something like [[ -n "${KERNEL_UPGRADE_FREEZE}" ]] instead of checking BETA?

Copy link
Member

@igorpecovnik igorpecovnik Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KERNEL_UPGRADE_FREEZE is a functionality that tells to which armbian version we allow upgrades. It is only used https://github.com/armbian/build/blob/main/config/boards/orangepi5pro.csc#L17 and also here we need to remove it as it is deprecated for sure. Not sure if we need this functionality at all ... I would say we drop this completly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then... Should I delete this code instead of clearing it? Or should I not touch it in this PR?

@iav
Copy link
Contributor Author

iav commented Feb 16, 2026

Re: @coderabbitai nitpick about unquoted $KERNEL_UPGRADE_FREEZE on line 235 — yes, this is a known issue tracked as P2a in #9400 (for var in $(echo $VAR | sed) → parameter expansion). It will be addressed in a separate PR to keep each change focused.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 16, 2026

Tip

For best results, initiate chat on the files or code changes.

@iav, understood! Thank you for the clarification. It makes perfect sense to keep this PR focused on P3b and P3c fixes, and address the P2a parameter expansion issue separately in its own PR. This approach makes the changes easier to review and track.


🧠 Learnings used
Learnt from: tabrisnet
Repo: armbian/build PR: 0
File: :0-0
Timestamp: 2025-10-24T04:46:22.901Z
Learning: In lib/functions/rootfs/rootfs-create.sh, the FIXME comment about mmdebstrap usage with --aptopt is a future note related to PR `#8785`, which hasn't been merged yet.

Learnt from: iav
Repo: armbian/build PR: 0
File: :0-0
Timestamp: 2026-02-11T07:41:11.870Z
Learning: In lib/functions/compilation/kernel-make.sh, the common_make_envs array uses a consistent quoting pattern where each element is formatted as "VAR='${value}'" with embedded single quotes. This pattern works correctly with the `env -i` command and should be maintained for consistency across all environment variables added to common_make_envs, including RUST_LIB_SRC.

Learnt from: tabrisnet
Repo: armbian/build PR: 8661
File: lib/functions/compilation/armbian-kernel.sh:194-199
Timestamp: 2025-09-25T18:37:00.330Z
Learning: In PR armbian/build#8661, line 235 of lib/functions/compilation/armbian-kernel.sh already contains the corrected comment "BPF link support for netfilter hooks" for NETFILTER_BPF_LINK, not the misleading "BPF_SYSCALL" comment that was flagged during review.

Learnt from: tabrisnet
Repo: armbian/build PR: 8661
File: lib/functions/compilation/armbian-kernel.sh:194-199
Timestamp: 2025-09-25T18:37:00.330Z
Learning: In PR armbian/build#8661, line 235 of lib/functions/compilation/armbian-kernel.sh already contains the corrected comment "BPF link support for netfilter hooks" for NETFILTER_BPF_LINK, not the misleading "BPF_SYSCALL" comment that was flagged during review.

Learnt from: rpardini
Repo: armbian/build PR: 9159
File: config/sources/families/genio.conf:201-201
Timestamp: 2026-01-03T20:44:12.559Z
Learning: In the Armbian build system, when calling run_host_command_logged with arrays containing arguments that have shell metacharacters (e.g., semicolons, pipes), use "${array[*]Q}" instead of "${array[@]}". This is because run_host_command_logged executes via `bash -c "$*"`, and the Q operator shell-quotes each element to prevent bash from interpreting special characters as command separators or other shell syntax.

Learnt from: EvilOlaf
Repo: armbian/build PR: 8968
File: patch/u-boot/u-boot-sunxi/arm64-dts-sun50i-h6-orangepi.dtsi-Rollback-r_rsb-to-r_i2c.patch:36-36
Timestamp: 2025-11-20T18:20:11.985Z
Learning: The rewrite-patches tool (REWRITE_PATCHES=yes) in the Armbian build system can inadvertently introduce semantic changes when the u-boot/kernel git base revision differs from expected state. The tool applies patches, commits them, and re-exports them using git format-patch, which can cause the re-exported patch to reflect the base revision's state rather than preserving the original patch intent. This is particularly problematic for device tree changes like interrupt specifications. The tool currently lacks validation mechanisms to detect such semantic drift, and affected patches must be manually corrected after rewriting.

Learnt from: leggewie
Repo: armbian/build PR: 0
File: :0-0
Timestamp: 2025-08-29T18:44:47.732Z
Learning: When creating GitHub issues for code improvements in the Armbian build project, include the relevant patches/diffs in the issue description or open a PR directly instead of just describing the changes. This makes it more efficient for the assignee to handle the improvements.

Learnt from: EvilOlaf
Repo: armbian/build PR: 0
File: :0-0
Timestamp: 2025-12-17T05:09:02.306Z
Learning: In the Armbian build system, kernel patches (e.g., in patch/kernel/archive/sunxi-6.18/patches.armbian/) contain device tree overlays and other code that have existed for years and are maintained/ported across kernel versions. When reviewing PRs that modify these patch files, focus on the actual changes being made (e.g., Makefile fixes, new additions) rather than reviewing the entire existing content within the patch as if it were new code. The patch file contents are existing, stable code unless explicitly modified in the PR diff.

Learnt from: EvilOlaf
Repo: armbian/build PR: 8428
File: config/boards/lckfb-taishanpi.csc:5-9
Timestamp: 2025-07-25T03:51:50.830Z
Learning: When reviewing PRs in the Armbian build system, U-Boot defconfig files and patches may be added as part of the PR changes but might not be visible in the current repository clone state during review. It's important to check the actual PR file changes directly via GitHub API (https://api.github.com/repos/armbian/build/pulls/{pr_number}/files) to get the complete picture of what files are being added or modified, especially for U-Boot patches that will be applied during the build process.

Learnt from: EvilOlaf
Repo: armbian/build PR: 8428
File: config/boards/lckfb-taishanpi.csc:5-9
Timestamp: 2025-07-25T03:51:50.830Z
Learning: When reviewing PRs in the Armbian build system, U-Boot defconfig files and patches may be added as part of the PR changes but might not be visible in the current repository clone state during review. It's important to check the actual PR file changes directly via GitHub or the PR API to get the complete picture of what files are being added or modified.

Learnt from: tabrisnet
Repo: armbian/build PR: 9275
File: patch/kernel/archive/filogic-6.18/frank-w/0053-net-phy-as21-try-the-driver-from-mtk-sdk.patch:1298-1326
Timestamp: 2026-01-19T22:46:53.605Z
Learning: In the Armbian build system, patches located under `patch/kernel/archive/filogic-6.18/frank-w/` are sourced from frank-w's out-of-tree BPI-Router-Linux repository (https://github.com/frank-w/BPI-Router-Linux) and are out of scope for code review. These patches are maintained externally and should not be reviewed in Armbian build PRs.

Learnt from: amazingfate
Repo: armbian/build PR: 8619
File: config/sources/families/rockchip.conf:65-72
Timestamp: 2025-09-14T11:37:35.089Z
Learning: In the Armbian build system, patch directories referenced in BOOTPATCHDIR and KERNELPATCHDIR configurations can be non-existent without causing build failures. Empty patch directories are also ignored by git, so missing patch directories should not be flagged as errors during code review.

iav and others added 2 commits February 24, 2026 23:23
Other read calls in the same file already use -r.
Without -r, backslashes in user input are interpreted as escape characters.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…rd splitting

Replace unquoted array assignment `arr=(${var})` with
`IFS=' ' read -ra arr <<< "${var}"` to prevent glob expansion.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@iav iav force-pushed the fix/p3bc-read-and-array branch from 1c5c967 to 8dd2c10 Compare February 24, 2026 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

02 Milestone: First quarter release Framework Framework components Needs review Seeking for review size/small PR with less then 50 lines

Development

Successfully merging this pull request may close these issues.

2 participants