Skip to content

system/nxinit: skip empty lines in init.rc parser#3523

Merged
acassis merged 1 commit into
apache:masterfrom
Zepp-Hanzj:master
Jun 4, 2026
Merged

system/nxinit: skip empty lines in init.rc parser#3523
acassis merged 1 commit into
apache:masterfrom
Zepp-Hanzj:master

Conversation

@Zepp-Hanzj

@Zepp-Hanzj Zepp-Hanzj commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Description

Empty lines in init.rc caused parsing to fail with -EINVAL because init_parse_arguments() returns 0 for empty strings, triggering the argc < 1 error path in init_action_parse() and accessing uninitialized argv[0] in init_service_parse().

Fix by skipping empty lines and lines containing only whitespace before attempting to match section keywords or calling parser callbacks.

Fixes #3513

Changes

  • system/nxinit/parser.c: Add empty/whitespace-only line skip logic in init_parse_config_file()

Testing

Verified on sim:nsh with NXINIT enabled and an init.rc containing empty lines:

on boot
    start console
    sleep 1
                    ← empty line (previously caused -EINVAL)
service console sh
    class core
    restart_period 1000

Before fix:

Error Parse /etc/init.d/init.rc -22

After fix:

nsh> ps
  TID   PID  PPID PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK            STACK COMMAND
    4     4     0 100 FIFO     Task      - Waiting  Signal    0000000000000000 0067496 init_main
    5     5     4 100 FIFO     Task      - Running            0000000000000000 0067504 sh
    6     6     4 100 FIFO     Task      - Ready              0000000000000000 0067464 system -c sleep 1

NXInit successfully parsed the init.rc with empty lines and started the console service.

Comment thread system/popen/Kconfig Outdated
@Zepp-Hanzj Zepp-Hanzj force-pushed the master branch 3 times, most recently from ae3f287 to 27266fe Compare June 4, 2026 09:56
@github-actions github-actions Bot added Size: XS and removed Size: S labels Jun 4, 2026
Empty lines in init.rc caused parsing to fail with -EINVAL because init_parse_arguments() returns 0 for empty strings, triggering the 'argc < 1' error path in init_action_parse() and accessing uninitialized argv[0] in init_service_parse().

Fix by skipping empty lines and lines containing only whitespace before attempting to match section keywords or calling parser callbacks.

Fixes apache#3513

Signed-off-by: hanzj <hanzhijian@zepp.com>
@acassis

acassis commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

@jerpelea I think this fix also is important

@acassis acassis merged commit e86c0b9 into apache:master Jun 4, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] NXInit init.rc file fails to parse empty lines

3 participants