/src/systemd/src/basic/escape.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
2 | | #pragma once |
3 | | |
4 | | #include "forward.h" |
5 | | |
6 | | /* What characters are special in the shell? */ |
7 | | /* must be escaped outside and inside double-quotes */ |
8 | | #define SHELL_NEED_ESCAPE "\"\\`$" |
9 | | |
10 | | /* Those that can be escaped or double-quoted. |
11 | | * |
12 | | * Strictly speaking, ! does not need to be escaped, except in interactive |
13 | | * mode, but let's be extra nice to the user and quote ! in case this |
14 | | * output is ever used in interactive mode. */ |
15 | | #define SHELL_NEED_QUOTES SHELL_NEED_ESCAPE GLOB_CHARS "'()<>|&;!" |
16 | | |
17 | | /* Note that we assume control characters would need to be escaped too in |
18 | | * addition to the "special" characters listed here, if they appear in the |
19 | | * string. Current users disallow control characters. Also '"' shall not |
20 | | * be escaped. |
21 | | */ |
22 | | #define SHELL_NEED_ESCAPE_POSIX "\\\'" |
23 | | |
24 | | typedef enum UnescapeFlags { |
25 | | UNESCAPE_RELAX = 1 << 0, |
26 | | UNESCAPE_ACCEPT_NUL = 1 << 1, |
27 | | } UnescapeFlags; |
28 | | |
29 | | typedef enum ShellEscapeFlags { |
30 | | /* The default is to add shell quotes ("") so the shell will consider this a single argument. |
31 | | * Tabs and newlines are escaped. */ |
32 | | |
33 | | SHELL_ESCAPE_POSIX = 1 << 1, /* Use POSIX shell escape syntax (a string enclosed in $'') instead of plain quotes. */ |
34 | | SHELL_ESCAPE_EMPTY = 1 << 2, /* Format empty arguments as "". */ |
35 | | } ShellEscapeFlags; |
36 | | |
37 | | int cescape_char(char c, char *buf); |
38 | | char* cescape_length(const char *s, size_t n) _nonnull_if_nonzero_(1, 2); |
39 | 0 | static inline char* cescape(const char *s) { |
40 | 0 | return cescape_length(s, SIZE_MAX); |
41 | 0 | } Unexecuted instantiation: link-config.c:cescape Unexecuted instantiation: udev-node.c:cescape Unexecuted instantiation: udev-rules.c:cescape |
42 | | |
43 | | int cunescape_one(const char *p, size_t length, char32_t *ret, bool *eight_bit, bool accept_nul); |
44 | | |
45 | | ssize_t cunescape_length_with_prefix(const char *s, size_t length, const char *prefix, UnescapeFlags flags, char **ret); |
46 | 8.28k | static inline ssize_t cunescape_length(const char *s, size_t length, UnescapeFlags flags, char **ret) { |
47 | 8.28k | return cunescape_length_with_prefix(s, length, NULL, flags, ret); |
48 | 8.28k | } Unexecuted instantiation: link-config.c:cunescape_length Unexecuted instantiation: udev-node.c:cunescape_length udev-rules.c:cunescape_length Line | Count | Source | 46 | 8.28k | static inline ssize_t cunescape_length(const char *s, size_t length, UnescapeFlags flags, char **ret) { | 47 | 8.28k | return cunescape_length_with_prefix(s, length, NULL, flags, ret); | 48 | 8.28k | } |
|
49 | 0 | static inline ssize_t cunescape(const char *s, UnescapeFlags flags, char **ret) { |
50 | 0 | return cunescape_length(s, SIZE_MAX, flags, ret); |
51 | 0 | } Unexecuted instantiation: link-config.c:cunescape Unexecuted instantiation: udev-node.c:cunescape Unexecuted instantiation: udev-rules.c:cunescape |
52 | | |
53 | | typedef enum XEscapeFlags { |
54 | | XESCAPE_8_BIT = 1 << 0, |
55 | | XESCAPE_FORCE_ELLIPSIS = 1 << 1, |
56 | | } XEscapeFlags; |
57 | | |
58 | | char* xescape_full(const char *s, const char *bad, size_t console_width, XEscapeFlags flags); |
59 | 0 | static inline char* xescape(const char *s, const char *bad) { |
60 | 0 | return xescape_full(s, bad, SIZE_MAX, 0); |
61 | 0 | } Unexecuted instantiation: link-config.c:xescape Unexecuted instantiation: udev-node.c:xescape Unexecuted instantiation: udev-rules.c:xescape |
62 | | char* octescape(const char *s, size_t len); |
63 | | char* decescape(const char *s, size_t len, const char *bad) _nonnull_if_nonzero_(1, 2); |
64 | | char* escape_non_printable_full(const char *str, size_t console_width, XEscapeFlags flags); |
65 | | |
66 | | char* shell_escape(const char *s, const char *bad); |
67 | | char* shell_maybe_quote(const char *s, ShellEscapeFlags flags); |
68 | | char* quote_command_line(char **argv, ShellEscapeFlags flags); |