summaryrefslogtreecommitdiffstats
path: root/src/shared/specifier.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2017-11-24 12:19:40 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2017-12-06 10:17:37 +0100
commit751223fecf56c6865080c2dda760a47a9958e49c (patch)
tree31a43edff3c61d5debc7931202a33450961c7d92 /src/shared/specifier.c
parentman: specifiers are allow for argument field in tmpfiles (diff)
downloadsystemd-751223fecf56c6865080c2dda760a47a9958e49c.tar.xz
systemd-751223fecf56c6865080c2dda760a47a9958e49c.zip
Fail on unknown (alphanumerical) specifiers
The code intentionally ignored unknown specifiers, treating them as text. This needs to change because otherwise we can never add a new specifier in a backwards compatible way. So just treat an unknown (potential) specifier as an error. In principle this is a break of backwards compatibility, but the previous behaviour was pretty much useless, since the expanded value could change every time we add new specifiers, which we do all the time. As a compromise for backwards compatibility, only fail on alphanumerical characters. This should cover the most cases where an unescaped percent character is used, like size=5% and such, which behave the same as before with this patch. OTOH, this means that we will not be able to use non-alphanumerical specifiers without breaking backwards compatibility again. I think that's an acceptable compromise. v2: - add NEWS entry v3: - only fail on alphanumerical
Diffstat (limited to 'src/shared/specifier.c')
-rw-r--r--src/shared/specifier.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/shared/specifier.c b/src/shared/specifier.c
index 9bef890346..9034cc20d7 100644
--- a/src/shared/specifier.c
+++ b/src/shared/specifier.c
@@ -41,6 +41,10 @@
*
*/
+/* Any ASCII character or digit: our pool of potential specifiers,
+ * and "%" used for escaping. */
+#define POSSIBLE_SPECIFIERS ALPHANUMERICAL "%"
+
int specifier_printf(const char *text, const Specifier table[], void *userdata, char **_ret) {
char *ret, *t;
const char *f;
@@ -97,7 +101,10 @@ int specifier_printf(const char *text, const Specifier table[], void *userdata,
ret = n;
t = n + j + k;
- } else {
+ } else if (strchr(POSSIBLE_SPECIFIERS, *f))
+ /* Oops, an unknown specifier. */
+ return -EBADSLT;
+ else {
*(t++) = '%';
*(t++) = *f;
}