Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(263945)

Unified Diff: Lib/test/test_socket.py

Issue 28332: silent truncations in socket.htons and socket.ntohs
Patch Set: Created 2 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Doc/library/socket.rst ('k') | Modules/socketmodule.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/test/test_socket.py Sat Oct 01 01:06:51 2016 -0500
+++ b/Lib/test/test_socket.py Sun Oct 02 09:13:38 2016 +0300
@@ -888,18 +888,28 @@
self.assertRaises(OverflowError, func, 1<<34)
def testNtoHErrors(self):
- good_values = [ 1, 2, 3, 1, 2, 3 ]
- bad_values = [ -1, -2, -3, -1, -2, -3 ]
- for k in good_values:
+ import _testcapi
+ s_good_values = [ 0, 1, 2, 0xffff ]
+ l_good_values = [ 0, 1, 2, 0xffffffff ]
+ s_bad_values = [ -1, -2, -3, _testcapi.INT_MIN - 1,
+ _testcapi.INT_MAX + 1, 2 ** 1000]
+ l_bad_values = [ -1, -2, 2 ** 32, _testcapi.ULONG_MAX + 1, 2 ** 1000 ]
+ s_deprecated_values = [ 2 ** 16, _testcapi.INT_MAX ]
+ for k in s_good_values:
+ socket.ntohs(k)
+ socket.htons(k)
+ for k in l_good_values:
socket.ntohl(k)
- socket.ntohs(k)
socket.htonl(k)
- socket.htons(k)
- for k in bad_values:
+ for k in s_bad_values:
+ self.assertRaises(OverflowError, socket.ntohs, k)
+ self.assertRaises(OverflowError, socket.htons, k)
+ for k in l_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)
+ for k in s_deprecated_values:
+ self.assertWarns(DeprecationWarning, socket.ntohs, k)
+ self.assertWarns(DeprecationWarning, socket.htons, k)
def testGetServBy(self):
eq = self.assertEqual
« no previous file with comments | « Doc/library/socket.rst ('k') | Modules/socketmodule.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+