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

unescaped pathnames may be printed in error cases #2107

Open
emaste opened this issue Apr 1, 2024 · 4 comments
Open

unescaped pathnames may be printed in error cases #2107

emaste opened this issue Apr 1, 2024 · 4 comments

Comments

@emaste
Copy link
Contributor

emaste commented Apr 1, 2024

Archive-provided pathnames may appear in error strings - some examples in #1609, and in particular #1609 (comment).

The change in #1609 improved an error message, to address issue #1561. In addition the change switched one case that printed an error string from safe_fprintf to fprintf. That case was switched back to safe_fprintf in #2101. There are however a number of other code paths that print error strings without escaping, via lafe_errc or lafe_warnc (and are completely independent of the changes in #1609).

As @jsonn suggests in #1609 (comment) we may consider escaping these when adding them to an error string.

@kientzle
Copy link
Contributor

kientzle commented Apr 1, 2024

Good idea! Should such escaping be ASCII-centric or should it try to accommodate UTF-8?

  • In either case, we should escape all C0 control characters (values < 32)
  • ASCII-centric would also escape all values > 127, but that would break UTF-8 sequences

@emaste
Copy link
Contributor Author

emaste commented Apr 1, 2024

Yeah, that's a good question :)

Putting the onus on the consumer (e.g. bsdtar) makes it easier to determine if the escaping should be be context-dependent (e.g. based on LANG), but from a maintainability and security perspective we're better off doing it in the library.

IMO escaping control characters is sufficient, since it's really terminal escapes that we want to avoid and the failure mode of not escaping >127 in a non-UTF-8 context is presumably just printing some garbage characters.

(That said, what does safe_fprintf do today?)

@emaste
Copy link
Contributor Author

emaste commented Apr 1, 2024

That said, what does safe_fprintf do today?

From the comments in safe_fprintf:

                /* Convert to wide char, test if the wide
                 * char is printable in the current locale. */

@kientzle
Copy link
Contributor

kientzle commented Apr 4, 2024

Hmmm..... that seems reasonable enough in the context of immediately printing a string.

If we were to change this to quote pathnames inside of the library when building the error string, I'm not sure such an approach would be appropriate. There, we might be better off just quoting any byte value less than 32.

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

No branches or pull requests

2 participants