summaryrefslogtreecommitdiffstats
path: root/abs/core/systemd/0001-shared-util-fix-off-by-one-error-in-tag_to_udev_node.patch
blob: 8c8ea46c223dc2eb3ac1a7398341ad4c7337c1e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
From 1d5989fd803d2019de0f6aaaf3cfb1cb2bbc3cdb Mon Sep 17 00:00:00 2001
From: Dave Reisner <dreisner@archlinux.org>
Date: Sun, 6 Oct 2013 18:26:23 -0400
Subject: [PATCH] shared/util: fix off-by-one error in tag_to_udev_node

Triggered false negatives when encoding a string which needed every
character to be escaped, e.g. "LABEL=/".
---
 src/shared/util.c            | 2 +-
 src/test/test-device-nodes.c | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/shared/util.c b/src/shared/util.c
index 82f4221..31cea79 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -3527,7 +3527,7 @@ static char *tag_to_udev_node(const char *tagvalue, const char *by) {
         if (u == NULL)
                 return NULL;
 
-        enc_len = strlen(u) * 4;
+        enc_len = strlen(u) * 4 + 1;
         t = new(char, enc_len);
         if (t == NULL)
                 return NULL;
diff --git a/src/test/test-device-nodes.c b/src/test/test-device-nodes.c
index 2f3dedb..59ba4be 100644
--- a/src/test/test-device-nodes.c
+++ b/src/test/test-device-nodes.c
@@ -26,7 +26,7 @@
 
 /* helpers for test_encode_devnode_name */
 static char *do_encode_string(const char *in) {
-        size_t out_len = strlen(in) * 4;
+        size_t out_len = strlen(in) * 4 + 1;
         char *out = malloc(out_len);
 
         assert_se(out);
@@ -46,6 +46,8 @@ static void test_encode_devnode_name(void) {
         assert_se(expect_encoded_as("pinkiepie", "pinkiepie"));
         assert_se(expect_encoded_as("valíd\\ųtf8", "valíd\\x5cųtf8"));
         assert_se(expect_encoded_as("s/ash/ng", "s\\x2fash\\x2fng"));
+        assert_se(expect_encoded_as("/", "\\x2f"));
+        assert_se(expect_encoded_as("!", "\\x21"));
 }
 
 int main(int argc, char *argv[]) {
-- 
1.8.4.1