chiark / gitweb /
shared/util: fix off-by-one error in tag_to_udev_node
authorDave Reisner <dreisner@archlinux.org>
Sun, 6 Oct 2013 22:26:23 +0000 (18:26 -0400)
committerDave Reisner <dreisner@archlinux.org>
Sun, 6 Oct 2013 22:29:12 +0000 (18:29 -0400)
Triggered false negatives when encoding a string which needed every
character to be escaped, e.g. "LABEL=/".

src/shared/util.c
src/test/test-device-nodes.c

index 82f4221..31cea79 100644 (file)
@@ -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;
index 2f3dedb..59ba4be 100644 (file)
@@ -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[]) {