]> arthur.barton.de Git - bup.git/commitdiff
metadata: fix symlink stat() vs. readlink() race
authorJohannes Berg <johannes@sipsolutions.net>
Thu, 31 Dec 2020 22:29:58 +0000 (23:29 +0100)
committerRob Browning <rlb@defaultvalue.org>
Sun, 30 May 2021 16:24:40 +0000 (11:24 -0500)
We might stat() the file and get some size, but by the time
we readlink() the link has changed and the size is something
else.

Arguably, we can't really avoid races here if we don't have
a consistent snapshot of the filesystem to save, however, in
this case we later get an assertion failure when the data is
read back from the index (or repo), and it's easy to avoid.

Set the size from the actually recorded symlink target.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/metadata.py

index 0d577806abda2ff4256688d227a6f62b3a2f6eda..67f3a079d9480aab29a876d76e175eb27624456b 100644 (file)
@@ -479,6 +479,9 @@ class Metadata:
         try:
             if stat.S_ISLNK(st.st_mode):
                 self.symlink_target = os.readlink(path)
+                # might have read a different link than the
+                # one that was in place when we did stat()
+                self.size = len(self.symlink_target)
         except OSError as e:
             add_error('readlink: %s' % e)