From c69a73c559c3aba21ef9f2e4b842eeb262511c1e Mon Sep 17 00:00:00 2001 From: Jens Petersen Date: Tue, 19 May 2020 11:36:41 +0800 Subject: [PATCH] remove-old-stack-work-libs.hs: check hash length for more safety --- etc/diskspace/remove-old-stack-work-libs.hs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/etc/diskspace/remove-old-stack-work-libs.hs b/etc/diskspace/remove-old-stack-work-libs.hs index f99d0ebd..3411ba53 100755 --- a/etc/diskspace/remove-old-stack-work-libs.hs +++ b/etc/diskspace/remove-old-stack-work-libs.hs @@ -21,22 +21,24 @@ main = do samePkgLibDir l1 l2 = pkgDirName l1 == pkgDirName l2 where pkgDirName p = - if countDashes p < 2 + if length p < 26 || countDashes p < 2 then error $ p ++ " not in name-version-hash format" - else let nv_ = dropEnd 22 p in - if last nv_ == '-' then removeDashSegment $ init nv_ - else error $ p ++ " not in name-version-hash format" + else (removeDashSegment . removeHashSegment) p countDashes = length . filter (== '-') removeDashSegment = init . dropWhileEnd (/= '-') + removeHashSegment p = let nv_ = dropEnd 22 p in + if last nv_ == '-' then init nv_ + else error $ p ++ " has incorrect hash format" + samePkgDynLib d1 d2 = pkgDynName d1 == pkgDynName d2 where pkgDynName p = - if countDashes p < 3 + if length p < 43 || countDashes p < 3 then error $ p ++ " not in libHSname-version-hash-ghc*.so format" - else (removeDashSegment . removeDashSegment . removeDashSegment) p + else (removeDashSegment . removeHashSegment . removeDashSegment) p removeOlder remover files = do -- keep 2 latest builds