summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorJoshua Watt <JPEWhacker@gmail.com>2020-12-09 15:45:06 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2020-12-10 13:39:15 +0000
commitfe205758a06a7e1cfcca504647da7a82770aeea4 (patch)
treefce4f4156a48a7016c977afa2bd39fa89d332d51 /bitbake
parentf36484e88d21346357bd1fa1bef6fdcc42bed54a (diff)
downloadpoky-fe205758a06a7e1cfcca504647da7a82770aeea4.tar.gz
bitbake: hashserv: Fix broken AF_UNIX path length limit
Fixes the bug were long paths would break Unix domain socket clients (for real this time; the previous attempt was missing os.path.basename). Adds some tests to prevent regressions (Bitbake rev: 77790e3656048eff5cb1a086c727d86d32773b68) Signed-off-by: Joshua Watt <JPEWhacker@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/hashserv/client.py2
-rw-r--r--bitbake/lib/hashserv/tests.py29
2 files changed, 26 insertions, 5 deletions
diff --git a/bitbake/lib/hashserv/client.py b/bitbake/lib/hashserv/client.py
index 7bbf0865d5..0ffd0c2ae2 100644
--- a/bitbake/lib/hashserv/client.py
+++ b/bitbake/lib/hashserv/client.py
@@ -213,7 +213,7 @@ class Client(object):
213 cwd = os.getcwd() 213 cwd = os.getcwd()
214 try: 214 try:
215 os.chdir(os.path.dirname(path)) 215 os.chdir(os.path.dirname(path))
216 self.loop.run_until_complete(self.client.connect_unix(path)) 216 self.loop.run_until_complete(self.client.connect_unix(os.path.basename(path)))
217 self.loop.run_until_complete(self.client.connect()) 217 self.loop.run_until_complete(self.client.connect())
218 finally: 218 finally:
219 os.chdir(cwd) 219 os.chdir(cwd)
diff --git a/bitbake/lib/hashserv/tests.py b/bitbake/lib/hashserv/tests.py
index 3dd9a31bee..77a19b8077 100644
--- a/bitbake/lib/hashserv/tests.py
+++ b/bitbake/lib/hashserv/tests.py
@@ -23,7 +23,8 @@ def _run_server(server, idx):
23 sys.stderr = sys.stdout 23 sys.stderr = sys.stdout
24 server.serve_forever() 24 server.serve_forever()
25 25
26class TestHashEquivalenceServer(object): 26
27class HashEquivalenceTestSetup(object):
27 METHOD = 'TestMethod' 28 METHOD = 'TestMethod'
28 29
29 server_index = 0 30 server_index = 0
@@ -65,6 +66,8 @@ class TestHashEquivalenceServer(object):
65 result = client.get_unihash(self.METHOD, taskhash) 66 result = client.get_unihash(self.METHOD, taskhash)
66 self.assertEqual(result, unihash) 67 self.assertEqual(result, unihash)
67 68
69
70class HashEquivalenceCommonTests(object):
68 def test_create_hash(self): 71 def test_create_hash(self):
69 # Simple test that hashes can be created 72 # Simple test that hashes can be created
70 taskhash = '35788efcb8dfb0a02659d81cf2bfd695fb30faf9' 73 taskhash = '35788efcb8dfb0a02659d81cf2bfd695fb30faf9'
@@ -240,15 +243,33 @@ class TestHashEquivalenceServer(object):
240 self.assertClientGetHash(self.client, taskhash4, None) 243 self.assertClientGetHash(self.client, taskhash4, None)
241 244
242 245
243class TestHashEquivalenceUnixServer(TestHashEquivalenceServer, unittest.TestCase): 246class TestHashEquivalenceUnixServer(HashEquivalenceTestSetup, HashEquivalenceCommonTests, unittest.TestCase):
244 def get_server_addr(self, server_idx): 247 def get_server_addr(self, server_idx):
245 return "unix://" + os.path.join(self.temp_dir.name, 'sock%d' % server_idx) 248 return "unix://" + os.path.join(self.temp_dir.name, 'sock%d' % server_idx)
246 249
247 250
248class TestHashEquivalenceTCPServer(TestHashEquivalenceServer, unittest.TestCase): 251class TestHashEquivalenceUnixServerLongPath(HashEquivalenceTestSetup, unittest.TestCase):
252 DEEP_DIRECTORY = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ccccccccccccccccccccccccccccccccccccccccccc"
253 def get_server_addr(self, server_idx):
254 os.makedirs(os.path.join(self.temp_dir.name, self.DEEP_DIRECTORY), exist_ok=True)
255 return "unix://" + os.path.join(self.temp_dir.name, self.DEEP_DIRECTORY, 'sock%d' % server_idx)
256
257
258 def test_long_sock_path(self):
259 # Simple test that hashes can be created
260 taskhash = '35788efcb8dfb0a02659d81cf2bfd695fb30faf9'
261 outhash = '2765d4a5884be49b28601445c2760c5f21e7e5c0ee2b7e3fce98fd7e5970796f'
262 unihash = 'f46d3fbb439bd9b921095da657a4de906510d2cd'
263
264 self.assertClientGetHash(self.client, taskhash, None)
265
266 result = self.client.report_unihash(taskhash, self.METHOD, outhash, unihash)
267 self.assertEqual(result['unihash'], unihash, 'Server returned bad unihash')
268
269
270class TestHashEquivalenceTCPServer(HashEquivalenceTestSetup, HashEquivalenceCommonTests, unittest.TestCase):
249 def get_server_addr(self, server_idx): 271 def get_server_addr(self, server_idx):
250 # Some hosts cause asyncio module to misbehave, when IPv6 is not enabled. 272 # Some hosts cause asyncio module to misbehave, when IPv6 is not enabled.
251 # If IPv6 is enabled, it should be safe to use localhost directly, in general 273 # If IPv6 is enabled, it should be safe to use localhost directly, in general
252 # case it is more reliable to resolve the IP address explicitly. 274 # case it is more reliable to resolve the IP address explicitly.
253 return socket.gethostbyname("localhost") + ":0" 275 return socket.gethostbyname("localhost") + ":0"
254