Skip to content

foomatic-rip: free the previous value before overwriting it in composite_set_values - #822

Merged
tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
ManasBagul23:fix-composite-set-values-leak-v2
Nov 28, 2026
Merged

tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
ManasBagul23:fix-composite-set-values-leak-v2

Conversation

@ManasBagul23

Copy link
Copy Markdown
Contributor

All three branches of composite_set_values() do:

val = option_assure_value(dep, optionset);
val->fromoption = opt;
val->value = get_valid_value_string(dep, ...);

option_assure_value() returns the existing value_t for (dep, optionset) if one is already there, not a fresh one — it only allocates when none exists yet (option_find_value() returns NULL). Once a composite option has set a dependent option's value for a given optionset once, every later call that sets it again for the same optionset overwrites val->value with a new get_valid_value_string() string without freeing the one already there, leaking it.

option_set_value(), right above this function, sets a value_t's ->value field for the same reason and does free(val->value) first — this is the same pattern, just missing it in all three places here.

Added the missing free(val->value) before each assignment; it's a correctly-sized no-op the first time a value_t is populated, since option_assure_value() calloc()s new ones (value starts NULL).

Verified by building this branch against current upstream libcupsfilters and libppd, make/make check clean.

…ite_set_values

All three branches of composite_set_values() do:

    val = option_assure_value(dep, optionset);
    val->fromoption = opt;
    val->value = get_valid_value_string(dep, ...);

option_assure_value() returns the *existing* value_t for (dep,
optionset) if one is already there, not a fresh one -- it only
allocates when none exists yet (option_find_value() returns NULL).
Once a composite option has set a dependent option's value for a
given optionset once, every later call that sets it again for the
same optionset overwrites val->value with a new
get_valid_value_string() string without freeing the one already
there, leaking it.

option_set_value(), right above this function, sets a value_t's
->value field for the same reason and does free(val->value) first --
this is the same pattern, just missing it in all three places here.

Added the missing free(val->value) before each assignment; it's a
correctly-sized no-op the first time a value_t is populated, since
option_assure_value() calloc()s new ones (value starts NULL).
@tillkamppeter
tillkamppeter merged commit 6ba2c67 into OpenPrinting:master Nov 28, 2026
11 checks passed
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