[pypy-commit] pypy disable_merge_different_int_types: make sure calls to ntohs and htons get unsigned values

bivab noreply at buildbot.pypy.org
Mon Nov 28 15:55:47 CET 2011


Author: David Schneider <david.schneider at picle.org>
Branch: disable_merge_different_int_types
Changeset: r49907:66ee3fbaa96a
Date: 2011-11-26 15:34 +0100
http://bitbucket.org/pypy/pypy/changeset/66ee3fbaa96a/

Log:	make sure calls to ntohs and htons get unsigned values

diff --git a/pypy/rlib/rsocket.py b/pypy/rlib/rsocket.py
--- a/pypy/rlib/rsocket.py
+++ b/pypy/rlib/rsocket.py
@@ -237,7 +237,9 @@
 
         def get_protocol(self):
             a = self.lock(_c.sockaddr_ll)
-            res = ntohs(rffi.getintfield(a, 'c_sll_protocol'))
+            proto = rffi.getintfield(a, 'c_sll_protocol')
+            proto = rffi.cast(rffi.UINT, proto)
+            res = ntohs(proto)
             self.unlock()
             return res
 
@@ -278,6 +280,7 @@
     def __init__(self, host, port):
         makeipaddr(host, self)
         a = self.lock(_c.sockaddr_in)
+        port = rffi.cast(rffi.UINT, port)
         rffi.setintfield(a, 'c_sin_port', htons(port))
         self.unlock()
 
@@ -1296,9 +1299,13 @@
     servent = _c.getservbyname(name, proto)
     if not servent:
         raise RSocketError("service/proto not found")
-    return ntohs(servent.c_s_port)
+    port = rffi.cast(rffi.UINT, servent.c_s_port)
+    return ntohs(port)
 
 def getservbyport(port, proto=None):
+    # This function is only called from pypy/module/_socket and the range of
+    # port is checked there
+    port = rffi.cast(rffi.USHORT, port)
     servent = _c.getservbyport(htons(port), proto)
     if not servent:
         raise RSocketError("port/proto not found")


More information about the pypy-commit mailing list