andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone
dc8c34
From 659ef1334287b48b7ecfa6457cc4743e7f2c06dd Mon Sep 17 00:00:00 2001
dc8c34
From: Noriko Hosoi <nhosoi@redhat.com>
dc8c34
Date: Thu, 26 Jan 2017 15:10:46 -0800
dc8c34
Subject: [PATCH 429/429] Ticket #49104 - dbscan-bin crashing due to a
dc8c34
 segmentation fault
dc8c34
dc8c34
Description: There was a logic error in format_raw.  When a truncate
dc8c34
option (-t width) is given, the function cut the output and replace
dc8c34
the last 5 bytes with " ...\0".  The position to start the replace
dc8c34
was not correct in some case.
dc8c34
dc8c34
https://fedorahosted.org/389/ticket/49104
dc8c34
dc8c34
Reviewed by wibrown@redhat.com (Thank you, William!!)
dc8c34
dc8c34
(cherry picked from commit efeb2f6e873df32ce7545fa1fb319806d2108fda)
dc8c34
(cherry picked from commit 3e3bcee42d3cb800457127e0d71ed7ce7a5d65a0)
dc8c34
(cherry picked from commit 93946f9e853d5f17b894ffb11a1dcfaeb9698890)
dc8c34
---
dc8c34
 ldap/servers/slapd/tools/dbscan.c | 17 ++++++++++++++++-
dc8c34
 1 file changed, 16 insertions(+), 1 deletion(-)
dc8c34
dc8c34
diff --git a/ldap/servers/slapd/tools/dbscan.c b/ldap/servers/slapd/tools/dbscan.c
dc8c34
index d84f138..c9445c6 100644
dc8c34
--- a/ldap/servers/slapd/tools/dbscan.c
dc8c34
+++ b/ldap/servers/slapd/tools/dbscan.c
dc8c34
@@ -239,6 +239,7 @@ static char *format_raw(unsigned char *s, int len, int flags,
dc8c34
         return NULL;
dc8c34
 
dc8c34
     for (p = s, o = buf, i = 0; i < len && o < bufend; p++, i++) {
dc8c34
+        int ishex = 0;
dc8c34
         if ((*p == '%') || (*p <= ' ') || (*p >= 126)) {
dc8c34
             /* index keys are stored with their trailing NUL */
dc8c34
             if ((*p == 0) && (i == len-1))
dc8c34
@@ -252,18 +253,32 @@ static char *format_raw(unsigned char *s, int len, int flags,
dc8c34
                 *o++ = '%';
dc8c34
                 *o++ = hex[*p / 16];
dc8c34
                 *o++ = hex[*p % 16];
dc8c34
+                ishex = 1;
dc8c34
             }
dc8c34
         } else {
dc8c34
             *o++ = *p;
dc8c34
         }
dc8c34
         if (truncatesiz > 0 && o > bufend - 5) {
dc8c34
             /* truncate it */
dc8c34
+            /*
dc8c34
+             * Padding " ...\0" at the end of the buf.
dc8c34
+             * If dumped as %##, truncate the partial value if any.
dc8c34
+             */
dc8c34
+            o = bufend - 5;
dc8c34
+            if (ishex) {
dc8c34
+                if ((o > buf) && *(o-1) == '%') {
dc8c34
+                    o -= 1;
dc8c34
+                } else if ((o > buf + 1) && *(o-2) == '%') {
dc8c34
+                    o -= 2;
dc8c34
+                }
dc8c34
+            }
dc8c34
             strcpy((char *)o, " ...");
dc8c34
             i = len;
dc8c34
             o += 4;
dc8c34
+            break;
dc8c34
         }
dc8c34
     }
dc8c34
-    *o = 0;
dc8c34
+    *o = '\0';
dc8c34
     return (char *)buf;
dc8c34
 }
dc8c34
 
dc8c34
-- 
dc8c34
2.9.3
dc8c34