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 robustness for kernel upgrade pin variants to handle complex configuration inputs more reliably.
    • Fixed input handling in interactive patch naming to prevent unintended backslash character interpretation.
  • Refactor

    • Minor optimizations to bootscript template rendering for improved consistency and maintainability.

iav and others added 2 commits February 16, 2026 19:34
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 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

📝 Walkthrough

Walkthrough

Two shell script files receive refinements: bootscript template rendering and kernel pin extraction parsing improvements in the BSP CLI module, plus a read flag adjustment in the patch naming flow to prevent backslash escape interpretation.

Changes

Cohort / File(s) Summary
BSP Bootscript & Kernel Pin Handling
lib/functions/bsp/armbian-bsp-cli-deb.sh
Bootscript template rendering logic refactored with explicit destination path verification; kernel upgrade freeze pin extraction upgraded from simple array assignment to robust IFS/read parsing for improved space handling.
Patch Input Processing
lib/functions/compilation/patch/patching.sh
Read invocation updated with -r flag to disable backslash escape interpretation during interactive patch subject input capture.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Parsing pins with careful art,
Reading true from the very start,
Bootscripts rendered, paths refined,
These small tweaks, elegantly designed.
Robustness blooms in logic's dance,
Building systems, given a chance! 🛠️

🚥 Pre-merge checks | ✅ 3 | ❌ 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 (3 passed)
Check name Status Explanation
Title check ✅ Passed The title references the two main changes (#9400 P3b,P3c) and accurately summarizes them: read -r flag addition and safe array assignment improvements.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 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?

@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.

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.

1 participant