diff options
author | Guido van Rossum <guido@python.org> | 2007-01-14 17:03:32 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-01-14 17:03:32 (GMT) |
commit | bb2cc698c1dd69ad57450bb48d64f2b8aaae7bb7 (patch) | |
tree | 7a5adf061a1281e0bc2add6ac069a779274a6d26 /Lib | |
parent | 8ef1cf30b7a3427c42fe803547c6f7f33187783f (diff) | |
download | cpython-bb2cc698c1dd69ad57450bb48d64f2b8aaae7bb7.zip cpython-bb2cc698c1dd69ad57450bb48d64f2b8aaae7bb7.tar.gz cpython-bb2cc698c1dd69ad57450bb48d64f2b8aaae7bb7.tar.bz2 |
Patch #1635058 by Mark Roberts: ensure that htonl and friends never accept or
return negative numbers, per the underlying C implementation.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_socket.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 356b801..1357d54 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -310,6 +310,20 @@ class GeneralModuleTests(unittest.TestCase): self.assertEqual(swapped & mask, mask) self.assertRaises(OverflowError, func, 1L<<34) + def testNtoHErrors(self): + good_values = [ 1, 2, 3, 1L, 2L, 3L ] + bad_values = [ -1, -2, -3, -1L, -2L, -3L ] + for k in good_values: + socket.ntohl(k) + socket.ntohs(k) + socket.htonl(k) + socket.htons(k) + for k in bad_values: + self.assertRaises(OverflowError, socket.ntohl, k) + self.assertRaises(OverflowError, socket.ntohs, k) + self.assertRaises(OverflowError, socket.htonl, k) + self.assertRaises(OverflowError, socket.htons, k) + def testGetServBy(self): eq = self.assertEqual # Find one service that exists, then check all the related interfaces. |