Repository navigation
Conversation
Defaults entries on the same line share a refcounted defaults_binding. Copy the binding on write when refcnt > 1 before mutating it in merge_defaults() or defaults_check_conflict(), and guard against an empty member list in merge_defaults() after simplify_host_list().
Share a single cmndspec_continues() helper across the sudoers, JSON, LDIF and CSV exporters and include timeout, notbefore, notafter and apparmor_profile when deciding whether consecutive commands can share a rule. Also fix CSV quoting for option names, values and newlines, and drop the stray trailing comma after apparmor_profile.
fQwQf
marked this pull request as ready for review
December 4, 2026 15:36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes two related issues in
cvtsudoers:SIGSEGV when merging Defaults across multiple input files
When a single
Defaultsline contains multiple variables, its entries share a refcounteddefaults_binding. During multi-file merging,defaults_check_conflict()calledTAILQ_CONCAT()twice on the shared binding, emptyingmembersfor the remaining entry as well. After the duplicate entry is freed,refcntdrops to 1,merge_defaults()passes therefcnt == 1check, and dereferencesTAILQ_FIRST(&def->binding->members)(NULL).Reproduction:
Fix: copy-on-write detach shared bindings (
unshare_host_binding()) whenrefcnt > 1before mutating them inmerge_defaults()ordefaults_check_conflict(), and guardm != NULLinmerge_defaults()aftersimplify_host_list().Exported policies silently lose command restrictions and CSV quoting
The per-exporter continuation check only compared
runas,tags,privs,limitprivs,role/type,runchroot, andruncwd(with LDIF also omittingapparmor_profile). Adjacent commands with differentTIMEOUT,NOTBEFORE,NOTAFTER, or LDIFAPPARMOR_PROFILEvalues were collapsed into the first command's rule, dropping subsequent restrictions.For example (from the existing
test17input):previously exported
/bin/lsunder the same role with timeout619830, silently droppingTIMEOUT=0; it is now emitted as a separate role.NOTBEFORE,NOTAFTER, andAPPARMOR_PROFILE=differences are likewise preserved (reflected in the updatedtest17/test19.okexpectations).Fix: extract a shared
cmndspec_continues()helper used by the CSV, JSON, and LDIF exporters, includingtimeout,notbefore,notafter, andapparmor_profile. In CSV exports,print_options_csv()andprint_cmnd_option()now escape embedded quotes,print_csv_string()quotes\r/\nas well, and the stray trailing comma afterapparmor_profile=is removed.Testing: full build and
make checkpass (cvtsudoers: 88 tests, 0 errors); both reproductions above verified before and after the patch.