>From 3d6c193d5fb1e4e6022f976437caf01fdef68ee8 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Wed, 6 Nov 2019 11:13:02 +0100 Subject: [PATCH] ustar: fix prefix length calculation in split_long_name This is backport of cd91cd3c629e3c489e5ab4650f443cdcfeec670a from GNU tar. * src/tar.c (split_long_name): Fix prefix length calculation. --- src/tar.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/tar.c b/src/tar.c index 07abfcd..99ef8a2 100644 --- a/src/tar.c +++ b/src/tar.c @@ -48,10 +48,12 @@ split_long_name (const char *name, size_t length) { size_t i; - if (length > TARPREFIXSIZE) - length = TARPREFIXSIZE+2; + if (length > TARPREFIXSIZE + 1) + length = TARPREFIXSIZE + 1; + else if (ISSLASH (name[length - 1])) + length--; for (i = length - 1; i > 0; i--) - if (name[i] == '/') + if (ISSLASH (name[i])) break; return i; } -- 2.23.0