Skip to contentSkip to conversation

tools: bpftool: remove invalid \' json escape

PATCH Applied Luis Gerhorst 3 participants 3 messages Feb 27, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools: bpftool: remove invalid \' json escape

RFC8259 ("The JavaScript Object Notation (JSON) Data Interchange Format") only specifies \", \\, \/, \b, \f, \n, \r, and \r as valid two-character escape sequences. This does not include \', which is not required in JSON because it exclusively uses double quotes as string separators.

Solidus (/) may be escaped, but does not have to. Only reverse solidus (\), double quotes ("), and the control characters have to be escaped. Therefore, with this fix, bpftool correctly supports all valid two-character escape sequences (but still does not support characters that require multi-character escape sequences).

Witout this fix, attempting to load a JSON file generated by bpftool using Python 3.10.6's default json.load() may fail with the error "Invalid \escape" if the file contains the invalid escaped single quote (\').

---
 tools/bpf/bpftool/json_writer.c | 3 ---
 1 file changed, 3 deletions(-)
tools/bpf/bpftool/json_writer.c +0 -3
index 7fea83bedf48..bca5dd0a59e3 100644
@@ -80,9 +80,6 @@ static void jsonw_puts(json_writer_t *self, const char *str)
 		case '"':
 			fputs("\\\"", self->out);
 			break;
-		case '\'':
-			fputs("\\\'", self->out);
-			break;
 		default:
 			putc(*str, self->out);
 		}
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw

2023-02-27 16:08 UTC+0100 ~ Luis Gerhorst <[email protected]>

Quoted 12 lines

RFC8259 ("The JavaScript Object Notation (JSON) Data Interchange Format") only specifies \", \\, \/, \b, \f, \n, \r, and \r as valid two-character escape sequences. This does not include \', which is not required in JSON because it exclusively uses double quotes as string separators.

Solidus (/) may be escaped, but does not have to. Only reverse solidus (\), double quotes ("), and the control characters have to be escaped. Therefore, with this fix, bpftool correctly supports all valid two-character escape sequences (but still does not support characters that require multi-character escape sequences).

Quoted 6 lines

Witout this fix, attempting to load a JSON file generated by bpftool using Python 3.10.6's default json.load() may fail with the error "Invalid \escape" if the file contains the invalid escaped single quote (\').

Fixes b66e907cfee2 ("tools: bpftool: copy JSON writer from iproute2

repository")

I see this escape was similarly removed from iproute2's version of the file [0]. Thanks!

[0]
https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/lib/json_writer.c?id=49c63bc775d610c3dfd3db0d6501ac29c519967f

#2 lore raw
In reply to Luis Gerhorst
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Quoted 6 lines · On Mon, 27 Feb 2023 16:08:54 +0100 you wrote:

RFC8259 ("The JavaScript Object Notation (JSON) Data Interchange Format") only specifies \", \\, \/, \b, \f, \n, \r, and \r as valid two-character escape sequences. This does not include \', which is not required in JSON because it exclusively uses double quotes as string separators.

Quoted 7 lines

Solidus (/) may be escaped, but does not have to. Only reverse solidus (\), double quotes ("), and the control characters have to be escaped. Therefore, with this fix, bpftool correctly supports all valid two-character escape sequences (but still does not support characters that require multi-character escape sequences).

[...]

Here is the summary with links:
- tools: bpftool: remove invalid \' json escape

    https://git.kernel.org/bpf/bpf-next/c/c679bbd611c0

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html