Blame SOURCES/0005-src-augtool.c-fix-access-to-invalid-memory.patch

ee1b47
From 78c87b3f3b359fac5401f81a86dd9e2f5968220e Mon Sep 17 00:00:00 2001
ee1b47
From: Pino Toscano <ptoscano@redhat.com>
ee1b47
Date: Thu, 19 Jul 2018 15:43:21 +0200
ee1b47
Subject: [PATCH] * src/augtool.c: fix access to invalid memory
ee1b47
ee1b47
When stripping the context from the result, readline_path_generator used
ee1b47
to realloc the string to a shorter size, copying only the content after
ee1b47
the prefix.  This resulted in reading with strcpy  from the previous
ee1b47
memory, which is freed already.  Avoid the issue, and simplify the code
ee1b47
by using strdup, freeing the old string.
ee1b47
ee1b47
This issue could be reproduced in augtool, trying to autocomplete files
ee1b47
without the /files prefix, e.g.:
ee1b47
  augtool> ls <TAB><TAB>
ee1b47
ee1b47
(cherry picked from commit 05b5784b2029f198ea486738d33fb7b49ef23eb8)
ee1b47
---
ee1b47
 src/augtool.c | 10 ++++------
ee1b47
 1 file changed, 4 insertions(+), 6 deletions(-)
ee1b47
ee1b47
diff --git a/src/augtool.c b/src/augtool.c
ee1b47
index ff097bd9..2745812c 100644
ee1b47
--- a/src/augtool.c
ee1b47
+++ b/src/augtool.c
ee1b47
@@ -153,15 +153,13 @@ static char *readline_path_generator(const char *text, int state) {
ee1b47
 
ee1b47
             /* strip off context if the user didn't give it */
ee1b47
             if (ctx != NULL) {
ee1b47
-                char *c = realloc(child, strlen(child)-strlen(ctx)+1);
ee1b47
-                if (c == NULL) {
ee1b47
-                    free(child);
ee1b47
-                    return NULL;
ee1b47
-                }
ee1b47
                 int ctxidx = strlen(ctx);
ee1b47
                 if (child[ctxidx] == SEP)
ee1b47
                     ctxidx++;
ee1b47
-                strcpy(c, &child[ctxidx]);
ee1b47
+                char *c = strdup(&child[ctxidx]);
ee1b47
+                free(child);
ee1b47
+                if (c == NULL)
ee1b47
+                    return NULL;
ee1b47
                 child = c;
ee1b47
             }
ee1b47
 
ee1b47
-- 
ee1b47
2.17.2
ee1b47