Skip to content
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

[systemd-sonic-generator] Fix handling service files with additional fields under [Install] section #115

Closed
wants to merge 1 commit into from

Conversation

stepanblyschak
Copy link
Owner

@stepanblyschak stepanblyschak commented Jan 11, 2024

If encountered a line without RequiredBy or WantedBy the code passes uninitialized pointer to get_install_targets_from_line(). Where it can fail with segfault or silently pass randomly.

Why I did it

Uninitialized target_suffix is passed to get_install_targets_from_line() when other fields are present in [Install] section, like this:

root@sonic:/home/admin# systemctl cat ntpsec
...
[Install]
Alias=ntp.service
Alias=ntpd.service
WantedBy=multi-user.target
Work item tracking
  • Microsoft ADO (number only):

How I did it

Initialize target_suffix with NULL, put an assert in get_install_targets_from_line(). Edited test to cover this scenario.

How to verify it

UT and on the switch.

Without the change - assert fails:

[       OK ] SsgFunctionTest.missing_file (2 ms)
[ RUN      ] SsgFunctionTest.insert_instance_number
[       OK ] SsgFunctionTest.insert_instance_number (2 ms)
[ RUN      ] SsgFunctionTest.get_num_of_asic
[       OK ] SsgFunctionTest.get_num_of_asic (2 ms)
[ RUN      ] SsgFunctionTest.get_unit_files
[       OK ] SsgFunctionTest.get_unit_files (2 ms)
[----------] 4 tests from SsgFunctionTest (8 ms total)

[----------] 4 tests from SsgMainTest
[ RUN      ] SsgMainTest.ssg_main_argv
Installation directory required as argument
[       OK ] SsgMainTest.ssg_main_argv (2 ms)
[ RUN      ] SsgMainTest.ssg_main_single_npu
ssg_test: systemd-sonic-generator.c:145: get_install_targets_from_line: Assertion `install_type' failed.
Aborted (core dumped)

Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006
  • 202012
  • 202106
  • 202111
  • 202205
  • 202211
  • 202305

Tested branch (Please provide the tested image version)

Description for the changelog

Link to config_db schema for YANG module changes

A picture of a cute animal (not mandatory but encouraged)

…fields under [Install] section

Signed-off-by: Stepan Blyschak <[email protected]>
@stepanblyschak stepanblyschak changed the title [systemd-sonic-generator] Fix handling service files with additional … [systemd-sonic-generator] Fix handling service files with additional fields under [Install] section Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants