Skip to content

'Safe printing' format is ambiguous and undocumented, and it should not be used on NUL-delimited output #130

Description

@JustAnotherArchivist

When printing filenames (and possibly other things), lsof replaces some characters with an escaped form. However, this format is ambiguous:

> touch $'a\x0b'
> touch 'a^K'
> # Open these files, e.g. with less in two other terminals:  less $'a\x0b'  +  less 'a^K'
> lsof -Fn $'a\x0b' 'a^K'
p534276
f4
na^K
p534277
f4
na^K

Even when using the NUL-delimited output – which can safely include any possible character in a filename, since NUL bytes are not allowed there – the escaping still takes place:

> lsof -F0n $'a\x0b' 'a^K' | xxd
00000000: 7035 3334 3237 3600 0a66 3400 6e61 5e4b  p534276..f4.na^K
00000010: 000a 7035 3334 3237 3700 0a66 3400 6e61  ..p534277..f4.na
00000020: 5e4b 000a                                ^K..

There are three issues here, in my opinion:

  1. The format is ambiguous on ^ escapes.
  2. The format is undocumented.
  3. The format should not be used on NUL-delimited output for programs because it significantly and needlessly complicates the downstream parsing.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions