Skip to content

Instantly share code, notes, and snippets.

@clayg
Created October 1, 2019 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clayg/1dd732407c98b27aa387322325b9b63b to your computer and use it in GitHub Desktop.
Save clayg/1dd732407c98b27aa387322325b9b63b to your computer and use it in GitHub Desktop.
trying to filter internal subdirs
vagrant@saio:~$ curl -s "http://saio:8090/v1/AUTH_test/?format=json&prefix=nul&delimiter=l" -H 'x-allow-null-byte: true' | python -m json.tool
[
{
"internal": true,
"subdir": "null"
}
]
vagrant@saio:~$ curl -s "http://saio:8090/v1/AUTH_test/?format=json&prefix=nul&delimiter=l" | python -m json.tool
[]
vagrant@saio:~$ curl -s "http://saio:8090/v1/AUTH_test/?format=json&prefix=nul" -H 'x-allow-null-byte: true' | python -m json.tool
[
{
"bytes": 0,
"count": 0,
"last_modified": "2019-09-27T18:36:42.938450",
"name": "null\u0000bad"
},
{
"bytes": 0,
"count": 0,
"last_modified": "2019-09-27T18:48:02.888630",
"name": "null\u0000test"
}
]
vagrant@saio:~$ curl -s "http://saio:8090/v1/AUTH_test/?format=json&prefix=nul&delimiter=l" | python -m json.tool
[
{
"subdir": "null"
}
]
diff --git a/swift/account/backend.py b/swift/account/backend.py
index dddcbce6e..c02ce95aa 100644
--- a/swift/account/backend.py
+++ b/swift/account/backend.py
@@ -464,7 +464,10 @@ class AccountBroker(DatabaseBroker):
delim_force_gte = True
dir_name = name[:end + 1]
if dir_name != orig_marker:
- results.append([dir_name, 0, 0, '0', 1])
+ if '\x00' in name:
+ results.append([dir_name, 0, 0, '0', 2])
+ else:
+ results.append([dir_name, 0, 0, '0', 1])
curs.close()
break
results.append(row)
diff --git a/swift/account/utils.py b/swift/account/utils.py
index 4e5ebe1ad..af438325a 100644
--- a/swift/account/utils.py
+++ b/swift/account/utils.py
@@ -85,7 +85,10 @@ def account_listing_response(account, req, response_content_type, broker=None,
in account_list:
name_ = name.decode('utf8') if six.PY2 else name
if is_subdir:
- data.append({'subdir': name_})
+ value = {'subdir': name_}
+ if is_subdir > 1:
+ value['internal'] = True
+ data.append(value)
else:
data.append(
{'name': name_, 'count': object_count, 'bytes': bytes_used,
diff --git a/swift/common/middleware/listing_formats.py b/swift/common/middleware/listing_formats.py
index a8ca813a1..9814be6cd 100644
--- a/swift/common/middleware/listing_formats.py
+++ b/swift/common/middleware/listing_formats.py
@@ -126,7 +126,7 @@ class ListingFilter(object):
new_listing = []
for entry in list(listing):
name_value = entry.get('name', entry.get('subdir', ''))
- if '\x00' in name_value:
+ if '\x00' in name_value or entry.get('internal'):
if container:
self.app.logger.warning(
'Container listing for %s/%s had null entry %r',
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment