From eae48289c0848c5812644f20dbb1b39fb117a8f6 Mon Sep 17 00:00:00 2001
From: Sergey Poznyakoff <gray@gnu.org>
Date: Thu, 20 Dec 2018 17:53:40 +0200
Subject: [PATCH 32/58] Fix improper memory access

Bug reported in
  http://lists.gnu.org/archive/html/bug-tar/2018-12/msg00009.html

* src/transform.c (parse_transform_expr): Check if re is not empty
before accessing its last byte.
---
 src/transform.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/transform.c b/src/transform.c
index 6ef0da6..bbf2033 100644
--- a/src/transform.c
+++ b/src/transform.c
@@ -273,7 +273,7 @@ parse_transform_expr (const char *expr)
       USAGE_ERROR ((0, 0, _("Invalid transform expression: %s"), errbuf));
     }
 
-  if (str[0] == '^' || str[strlen (str) - 1] == '$')
+  if (str[0] == '^' || (i > 2 && str[i - 3] == '$'))
     tf->transform_type = transform_first;
 
   free (str);
-- 
2.19.1

