Merge lp:~blake-rouse/maas/fix-1387191 into lp:~maas-committers/maas/trunk

Proposed by Blake Rouse
Status: Merged
Approved by: Blake Rouse
Approved revision: no longer in the source branch.
Merged at revision: 3324
Proposed branch: lp:~blake-rouse/maas/fix-1387191
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 64 lines (+27/-2)
2 files modified
src/provisioningserver/pserv_services/tests/test_tftp.py (+23/-2)
src/provisioningserver/pserv_services/tftp.py (+4/-0)
To merge this branch: bzr merge lp:~blake-rouse/maas/fix-1387191
Reviewer Review Type Date Requested Status
Newell Jensen (community) Approve
Christian Reis (community) Approve
Review via email: mp+240161@code.launchpad.net

Commit message

Convert TFTP request paths that contain backslashes to forward slashes.

To post a comment you must log in.
Revision history for this message
Christian Reis (kiko) wrote :

r=kiko if you drop the XXX in the comment (this isn't a hack AIUI)

review: Approve
Revision history for this message
Andres Rodriguez (andreserl) wrote :
Download full text (3.4 KiB)

What's the regression potential with Trusty?
On Oct 30, 2014 3:36 PM, "Blake Rouse" <email address hidden> wrote:

> Blake Rouse has proposed merging lp:~blake-rouse/maas/fix-1387191 into
> lp:maas.
>
> Commit message:
> Convert TFTP request paths that contain backslashes to forward slashes.
>
> Requested reviews:
> MAAS Maintainers (maas-maintainers)
> Related bugs:
> Bug #1387191 in MAAS: "utopic uefi bootx64.efi not loading grubx64.efi"
> https://bugs.launchpad.net/maas/+bug/1387191
>
> For more details, see:
> https://code.launchpad.net/~blake-rouse/maas/fix-1387191/+merge/240161
> --
> https://code.launchpad.net/~blake-rouse/maas/fix-1387191/+merge/240161
> You are subscribed to branch lp:maas.
>
> === modified file
> 'src/provisioningserver/pserv_services/tests/test_tftp.py'
> --- src/provisioningserver/pserv_services/tests/test_tftp.py 2014-09-30
> 21:05:35 +0000
> +++ src/provisioningserver/pserv_services/tests/test_tftp.py 2014-10-30
> 19:35:41 +0000
> @@ -16,7 +16,7 @@
>
> from functools import partial
> import json
> -from os import path
> +import os
> from socket import (
> AF_INET,
> AF_INET6,
> @@ -140,7 +140,7 @@
>
> def get_reader(self, data):
> temp_file = self.make_file(name="example", contents=data)
> - temp_dir = path.dirname(temp_file)
> + temp_dir = os.path.dirname(temp_file)
> backend = TFTPBackend(temp_dir, "http://nowhere.example.com/")
> return backend.get_reader("example")
>
> @@ -158,6 +158,27 @@
> self.assertEqual(b"", reader.read(1))
>
> @inlineCallbacks
> + def test_get_reader_handles_backslashes_in_path(self):
> + self.patch(tftp_module, 'send_event_node_mac_address')
> + self.patch(tftp_module, 'get_remote_mac')
> +
> + data = factory.make_string().encode("ascii")
> + temp_dir = self.make_dir()
> + subdir = factory.make_name('subdir')
> + filename = factory.make_name('file')
> + os.mkdir(os.path.join(temp_dir, subdir))
> + factory.make_file(os.path.join(temp_dir, subdir), filename, data)
> +
> + path = '\\%s\\%s' % (subdir, filename)
> + backend = TFTPBackend(temp_dir, "http://nowhere.example.com/")
> + reader = yield backend.get_reader(path)
> +
> + self.addCleanup(reader.finish)
> + self.assertEqual(len(data), reader.size)
> + self.assertEqual(data, reader.read(len(data)))
> + self.assertEqual(b"", reader.read(1))
> +
> + @inlineCallbacks
> def test_get_reader_logs_node_event_with_mac_address(self):
> mac_address = factory.make_mac_address()
> self.patch_autospec(tftp_module, 'send_event_node_mac_address')
>
> === modified file 'src/provisioningserver/pserv_services/tftp.py'
> --- src/provisioningserver/pserv_services/tftp.py 2014-09-30
> 21:36:56 +0000
> +++ src/provisioningserver/pserv_services/tftp.py 2014-10-30
> 19:35:41 +0000
> @@ -209,6 +209,10 @@
> from that boot method. Otherwise the filesystem is used to service
> the response.
> """
> + # XXX blake_r 2014-10-30: It is possible for a client to request
> the
> + # file with '\'...

Read more...

Revision history for this message
Newell Jensen (newell-jensen) wrote :

Looks good!

review: Approve
Revision history for this message
Blake Rouse (blake-rouse) wrote :

<slangasek> kiko, blake_r: note btw that at some later date, trusty will also be updated to include a new upstream version of shim, so any changes here should be applied for precise+trusty as well

Revision history for this message
Blake Rouse (blake-rouse) wrote :

but if the file uses '/' then it will work the same, like nothing has changed, which is what the current shim in trusty does.

Revision history for this message
Andres Rodriguez (andreserl) wrote :

Right. So that means that it will be updated sometime in the future. What
about the now? Will this cause any regressions, when say, we use trusty's?
I just want to make sure we don't introduce a regression.
On Oct 30, 2014 3:44 PM, "Blake Rouse" <email address hidden> wrote:

> <slangasek> kiko, blake_r: note btw that at some later date, trusty will
> also be updated to include a new upstream version of shim, so any changes
> here should be applied for precise+trusty as well
> --
> https://code.launchpad.net/~blake-rouse/maas/fix-1387191/+merge/240161
> You are subscribed to branch lp:maas.
>

Revision history for this message
Christian Reis (kiko) wrote :

Reading the code, the main risk would be if valid filenames contained forward slashes (that did not imply path separation), which I have never seen in my life and AFAIK is illegal.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/provisioningserver/pserv_services/tests/test_tftp.py'
--- src/provisioningserver/pserv_services/tests/test_tftp.py 2014-09-30 21:05:35 +0000
+++ src/provisioningserver/pserv_services/tests/test_tftp.py 2014-10-30 19:38:47 +0000
@@ -16,7 +16,7 @@
1616
17from functools import partial17from functools import partial
18import json18import json
19from os import path19import os
20from socket import (20from socket import (
21 AF_INET,21 AF_INET,
22 AF_INET6,22 AF_INET6,
@@ -140,7 +140,7 @@
140140
141 def get_reader(self, data):141 def get_reader(self, data):
142 temp_file = self.make_file(name="example", contents=data)142 temp_file = self.make_file(name="example", contents=data)
143 temp_dir = path.dirname(temp_file)143 temp_dir = os.path.dirname(temp_file)
144 backend = TFTPBackend(temp_dir, "http://nowhere.example.com/")144 backend = TFTPBackend(temp_dir, "http://nowhere.example.com/")
145 return backend.get_reader("example")145 return backend.get_reader("example")
146146
@@ -158,6 +158,27 @@
158 self.assertEqual(b"", reader.read(1))158 self.assertEqual(b"", reader.read(1))
159159
160 @inlineCallbacks160 @inlineCallbacks
161 def test_get_reader_handles_backslashes_in_path(self):
162 self.patch(tftp_module, 'send_event_node_mac_address')
163 self.patch(tftp_module, 'get_remote_mac')
164
165 data = factory.make_string().encode("ascii")
166 temp_dir = self.make_dir()
167 subdir = factory.make_name('subdir')
168 filename = factory.make_name('file')
169 os.mkdir(os.path.join(temp_dir, subdir))
170 factory.make_file(os.path.join(temp_dir, subdir), filename, data)
171
172 path = '\\%s\\%s' % (subdir, filename)
173 backend = TFTPBackend(temp_dir, "http://nowhere.example.com/")
174 reader = yield backend.get_reader(path)
175
176 self.addCleanup(reader.finish)
177 self.assertEqual(len(data), reader.size)
178 self.assertEqual(data, reader.read(len(data)))
179 self.assertEqual(b"", reader.read(1))
180
181 @inlineCallbacks
161 def test_get_reader_logs_node_event_with_mac_address(self):182 def test_get_reader_logs_node_event_with_mac_address(self):
162 mac_address = factory.make_mac_address()183 mac_address = factory.make_mac_address()
163 self.patch_autospec(tftp_module, 'send_event_node_mac_address')184 self.patch_autospec(tftp_module, 'send_event_node_mac_address')
164185
=== modified file 'src/provisioningserver/pserv_services/tftp.py'
--- src/provisioningserver/pserv_services/tftp.py 2014-09-30 21:36:56 +0000
+++ src/provisioningserver/pserv_services/tftp.py 2014-10-30 19:38:47 +0000
@@ -209,6 +209,10 @@
209 from that boot method. Otherwise the filesystem is used to service209 from that boot method. Otherwise the filesystem is used to service
210 the response.210 the response.
211 """211 """
212 # It is possible for a client to request the file with '\' instead
213 # of '/', example being 'bootx64.efi'. Convert all '\' to '/' to be
214 # unix compatiable.
215 file_name = file_name.replace('\\', '/')
212 mac_address = get_remote_mac()216 mac_address = get_remote_mac()
213 if mac_address is not None:217 if mac_address is not None:
214 send_event_node_mac_address(218 send_event_node_mac_address(