Skip to content

libbpf-tools: Always escape tab and newline chars in execsnoop#5497

Open
ReillyBrogan wants to merge 1 commit intoiovisor:masterfrom
ReillyBrogan:bpf-escape
Open

libbpf-tools: Always escape tab and newline chars in execsnoop#5497
ReillyBrogan wants to merge 1 commit intoiovisor:masterfrom
ReillyBrogan:bpf-escape

Conversation

@ReillyBrogan
Copy link
Copy Markdown

5340c21 made it so that the Python execsnoop always escaped newline characters which is required to avoid breaking tools that parse the execsnoop stdout when command args contain newlines. This applies the same change to the libbpf-tools version as well as additionally escaping tab characters.

Specifically I noticed this difference in behavior when porting system76-scheduler to libbpf execsnoop. It would probably be better to have a json output instead but this at least gets system76-scheduler working without additional changes.

5340c21 made it so that the Python execsnoop always escaped newline characters which is required to avoid breaking tools that parse the execsnoop stdout when command args contain newlines. This applies the same change to the libbpf-tools version as well as additionally escaping tab characters.

Specifically I noticed this difference in behavior when porting system76-scheduler to libbpf execsnoop. It would probably be better to have a json output instead but this at least gets system76-scheduler working without additional changes.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aligns libbpf-tools’s execsnoop output escaping behavior with the Python implementation by ensuring newline characters (and additionally tabs) are always escaped in printed exec arguments, preventing stdout line-breaking for downstream parsers.

Changes:

  • Replaces the quoting/escaping helper with a generalized escape_symbol() routine.
  • Escapes \n and \t even when -q (quoted args) mode is not enabled.
  • Keeps double-quote escaping conditional on quoted-output mode.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread libbpf-tools/execsnoop.c

static void inline quoted_symbol(char c) {
static void inline escape_symbol(char c, bool quote) {
switch(c) {
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

Style nit: use switch (c) (with a space) to match the rest of this file (e.g., switch (key) above).

Suggested change
switch(c) {
switch (c) {

Copilot uses AI. Check for mistakes.
Comment thread libbpf-tools/execsnoop.c
Comment on lines 220 to +224
if (c == '\0') {
args_counter++;
putchar(' ');
} else {
putchar(c);
escape_symbol(c, false);
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

print_args takes a bool quote parameter, but the function logic uses env.quote and the escaping calls hardcode true/false. Since this is a static helper, consider either using the quote parameter consistently (and pass it through to escape_symbol) or removing it to avoid a misleading signature.

Copilot uses AI. Check for mistakes.
@ekyooo
Copy link
Copy Markdown
Collaborator

ekyooo commented Apr 19, 2026

  • I confirmed that the AI review feedback is valid.
  • \r can cause a similar issue to \n. Should it also be included in the escape targets?
  • Escaping \t and \n was already applied in quote mode, but not in non-quote mode. As I understand it, this PR extends that behavior to non-quote mode and also includes some refactoring. Could you update the commit message to reflect that more accurately?

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.

3 participants