iustin / pyxattr

A python module for accessing filesystem Extended Attributes
https://pyxattr.k1024.org/
GNU Lesser General Public License v2.1
30 stars 15 forks source link

race condition in get_all #12

Closed ThomasWaldmann closed 7 years ago

ThomasWaldmann commented 8 years ago
  1. you first determine the size of the xattr list
  2. then you alloc a buffer of that size
  3. then you actually fetch the list into the buffer

if between 1 and 3 the xattr list changes in the filesystem, the call fails.

at other places in the code I've seen a while loop for such cases.

BTW, I was looking at your code because we just had such a race condition in our code, discovered in the wild, in practical use. (borgbackup has xattr code for linux, freebsd, osx).

iustin commented 7 years ago

Thanks for the report! Cleaning this up properly could use some refactoring, I'll see what I can do.

ThomasWaldmann commented 7 years ago

great it is fixed.

it is a bit of a pity that such xattr code is not managed centrally and for all platforms in the stdlib. so everybody has to fall into same pitfalls and every implementation has its own drawbacks.