File sg_inq-udev-conformant-character-encoding-for-export.patch of Package sg3_utils.1394

From 6164414d01b548e446f0ee90623fee4da896fefa Mon Sep 17 00:00:00 2001
From: Hannes Reinecke <hare@suse.de>
Date: Tue, 5 May 2015 10:14:25 +0200
Subject: [PATCH] sg_inq: udev-conformant character encoding for --export

The '--export' switch prints out values suitable for direct
udev import. As such we should be using an udev-conformant
character encoding to avoid clashes with the original scsi_id
and also to ensure the string can be used to generate a
symlink.

References: bnc#917011

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 src/sg_inq.c |   24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

--- a/src/sg_inq.c
+++ b/src/sg_inq.c
@@ -1832,7 +1832,17 @@ export_dev_ids(unsigned char * buff, int
             printf("SCSI_IDENT_%s_VENDOR=", assoc_str);
             if ((2 == c_set) || (3 == c_set)) { /* ASCII or UTF-8 */
                 k = encode_whitespaces(ip, i_len);
-                printf("%.*s\n", k, ip);
+                /* udev-conformant character encoding */
+                for (m = 0; m < k; ++m) {
+                    if ((ip[m] >= '0' && ip[m] <= '9') ||
+                        (ip[m] >= 'A' && ip[m] <= 'Z') ||
+                        (ip[m] >= 'a' && ip[m] <= 'z') ||
+                        strchr("#+-.:=@_", ip[m]) != NULL)
+                        printf("%c", ip[m]);
+                    else
+                        printf("\\x%02x", ip[m]);
+                }
+                printf("\n");
             } else {
                 for (m = 0; m < i_len; ++m)
                     printf("%02x", (unsigned int)ip[m]);
@@ -1843,7 +1853,17 @@ export_dev_ids(unsigned char * buff, int
             printf("SCSI_IDENT_%s_T10=", assoc_str);
             if ((2 == c_set) || (3 == c_set)) {
                 k = encode_whitespaces(ip, i_len);
-                printf("%.*s\n", k, ip);
+                /* udev-conformant character encoding */
+                for (m = 0; m < k; ++m) {
+                    if ((ip[m] >= '0' && ip[m] <= '9') ||
+                        (ip[m] >= 'A' && ip[m] <= 'Z') ||
+                        (ip[m] >= 'a' && ip[m] <= 'z') ||
+                        strchr("#+-.:=@_", ip[m]) != NULL)
+                        printf("%c", ip[m]);
+                    else
+                        printf("\\x%02x", ip[m]);
+                }
+                printf("\n");
                 if (!memcmp(ip, "ATA_", 4)) {
                     printf("SCSI_IDENT_%s_ATA=%.*s\n", assoc_str,
                            k - 4, ip + 4);
openSUSE Build Service is sponsored by