-
Notifications
You must be signed in to change notification settings - Fork 1
RDKB-63013 update cmake build to parse conf file #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -182,7 +182,7 @@ parse_configure_options_file() { | |||||||||||||||||||||||||||||||
| cppflags="${cppflags//\$HOME/$HOME}" | ||||||||||||||||||||||||||||||||
| cflags="${cflags//\$HOME/$HOME}" | ||||||||||||||||||||||||||||||||
| ldflags="${ldflags//\$HOME/$HOME}" | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| # Build final options array | ||||||||||||||||||||||||||||||||
| [[ -n "$cppflags" ]] && options_array+=("CPPFLAGS=${cppflags% }") | ||||||||||||||||||||||||||||||||
| [[ -n "$cflags" ]] && options_array+=("CFLAGS=${cflags% }") | ||||||||||||||||||||||||||||||||
|
|
@@ -335,16 +335,45 @@ run_pre_build_commands() { | |||||||||||||||||||||||||||||||
| # Build with CMake | ||||||||||||||||||||||||||||||||
| build_component_cmake() { | ||||||||||||||||||||||||||||||||
| cd "$COMPONENT_DIR" | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| local build_dir cmake_flags make_targets parallel_make | ||||||||||||||||||||||||||||||||
| build_dir=$(jq -r '.native_component.build.build_dir // "build"' "$CONFIG_FILE") | ||||||||||||||||||||||||||||||||
| cmake_flags=$(jq -r '.native_component.build.cmake_flags // empty' "$CONFIG_FILE") | ||||||||||||||||||||||||||||||||
| cmake_flags=$(expand_path "$cmake_flags") | ||||||||||||||||||||||||||||||||
| make_targets=$(jq -r '.native_component.build.make_targets[]? // "all"' "$CONFIG_FILE" | tr '\n' ' ') | ||||||||||||||||||||||||||||||||
| parallel_make=$(jq -r '.native_component.build.parallel_make // true' "$CONFIG_FILE") | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| build_cmake "$COMPONENT_DIR" "$build_dir" "$cmake_flags" "$make_targets" "$parallel_make" || return 1 | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| # Parse configure options file if exists | ||||||||||||||||||||||||||||||||
| local config_file_path cppflags cflags ldflags | ||||||||||||||||||||||||||||||||
| config_file_path=$(jq -r '.native_component.build.configure_options_file // empty' "$CONFIG_FILE") | ||||||||||||||||||||||||||||||||
| if [[ -n "$config_file_path" ]]; then | ||||||||||||||||||||||||||||||||
| config_file_path=$(expand_path "$config_file_path") | ||||||||||||||||||||||||||||||||
| if [[ ! "$config_file_path" = /* ]]; then | ||||||||||||||||||||||||||||||||
| config_file_path="$COMPONENT_DIR/$config_file_path" | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| step "Reading configure options from: $config_file_path" | ||||||||||||||||||||||||||||||||
| local parsed_array=() | ||||||||||||||||||||||||||||||||
| if parse_configure_options_file "$config_file_path" parsed_array; then | ||||||||||||||||||||||||||||||||
| for opt in "${parsed_array[@]}"; do | ||||||||||||||||||||||||||||||||
| case $opt in | ||||||||||||||||||||||||||||||||
| CPPFLAGS=*) cppflags="${opt#CPPFLAGS=}" ;; | ||||||||||||||||||||||||||||||||
| CFLAGS=*) cflags="${opt#CFLAGS=}" ;; | ||||||||||||||||||||||||||||||||
| LDFLAGS=*) ldflags="${opt#LDFLAGS=}" ;; | ||||||||||||||||||||||||||||||||
| esac | ||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||
| err "Failed to parse configure options file (for cmake)" | ||||||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| # Compose cmake flags | ||||||||||||||||||||||||||||||||
| local combined_cmake_flags="$cmake_flags" | ||||||||||||||||||||||||||||||||
| [[ -n "$cppflags" ]] && combined_cmake_flags+=" -DCMAKE_C_FLAGS=\"$cppflags $cflags\" -DCMAKE_CXX_FLAGS=\"$cppflags $cflags\"" | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
| [[ -n "$cppflags" ]] && combined_cmake_flags+=" -DCMAKE_C_FLAGS=\"$cppflags $cflags\" -DCMAKE_CXX_FLAGS=\"$cppflags $cflags\"" | |
| # Combine CPPFLAGS and CFLAGS if either is present | |
| local cmake_compile_flags="" | |
| if [[ -n "$cppflags" ]]; then | |
| cmake_compile_flags+="$cppflags" | |
| fi | |
| if [[ -n "$cflags" ]]; then | |
| [[ -n "$cmake_compile_flags" ]] && cmake_compile_flags+=" " | |
| cmake_compile_flags+="$cflags" | |
| fi | |
| if [[ -n "$cmake_compile_flags" ]]; then | |
| combined_cmake_flags+=" -DCMAKE_C_FLAGS=\"$cmake_compile_flags\" -DCMAKE_CXX_FLAGS=\"$cmake_compile_flags\"" | |
| fi |
Copilot
AI
Feb 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The values read from configure_options_file are used to build combined_cmake_flags and then passed to build_cmake, which invokes cmake via eval on a command string including these flags. Because configure_options_file is an external file and its CPPFLAGS/CFLAGS/LDFLAGS content is not shell-escaped, an attacker controlling this file can inject shell metacharacters (e.g. ;, backticks, $(...)) so that eval executes arbitrary commands instead of just passing flags to CMake. To mitigate this, avoid using eval for the CMake invocation and pass flags as properly quoted separate arguments (or rigorously sanitize/escape the contents of cppflags, cflags, and ldflags before composing the command).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the
casestatement,$optshould be quoted (case "$opt" in) to prevent word splitting and pathname expansion when an option value contains spaces or glob characters. As written, a value likeCPPFLAGS=-I/foo -I/barcan break thecaseparsing or match unintended patterns.