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

compose: Check optipng is there before we use it #321

Merged
merged 1 commit into from Jun 21, 2021

Conversation

iainlane
Copy link
Contributor

@iainlane iainlane commented Jun 4, 2021

There are two places we can beef up the checks for optipng

  • When enabling its usage, make sure we found it first, and refuse to
    enable if we didn't.
  • In case asc_compose_set_optipng_binary (NULL) was called, check
    before spawning that we have a path. It's a programmer error to
    call g_spawn_sync () with NULL in argv[0], and the program
    will crash in that case. Also treat NULL as disabling optipng when
    passed to asc_compose_set_optipng_binary.

In case the binary is removed mid-run or an invalid binary is passed to
asc_compose_set_optipng_binary, the g_spawn_sync call itself will
fail and we'll report a proper GError. This is the best way to handle
it, as we avoid TOCTTOU races that way.

compose/asc-image.c Show resolved Hide resolved
g_set_error (error,
ASC_IMAGE_ERROR,
ASC_IMAGE_ERROR_FAILED,
"optipng not found on $PATH");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: "in PATH" is probably better...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, typo I guess, that's what it is in the other places where I used a similar string

tests/test-compose.c Show resolved Hide resolved
There are two places we can beef up the checks for optipng

  - When enabling its usage, make sure we found it first, and refuse to
    enable if we didn't.
  - In case `asc_compose_set_optipng_binary (NULL)` was called, check
    before spawning that we have *a* path. It's a programmer error to
    call `g_spawn_sync ()` with `NULL` in `argv[0]`, and the program
    will crash in that case. Also treat `NULL` as disabling optipng when
    passed to `asc_compose_set_optipng_binary`.

In case the binary is removed mid-run or an invalid binary is passed to
`asc_compose_set_optipng_binary`, the `g_spawn_sync` call itself will
fail and we'll report a proper GError. This is the best way to handle
it, as we avoid TOCTTOU races that way.
@ximion ximion merged commit 96a7981 into ximion:master Jun 21, 2021
6 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.

None yet

2 participants