[issue5104] getsockaddrarg() casts port number from int to short without any warning

2009-01-29 Thread Roman Zeyde

New submission from Roman Zeyde :

The following code shouldn't fail without any warning at all:

>>> import socket
>>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> s.bind(('localhost', 7))
>>> print(s.getsockname())
('127.0.0.1', 4464)

After looking through socketmodule.c (rev. 68450), it seems that AF_INET
case casts an "int port" into a "short addr->sin_port", and does not
checks for overflows:

case AF_INET:
{
struct sockaddr_in* addr;
char *host;
int port, result;
if (!PyTuple_Check(args)) {
PyErr_Format(
PyExc_TypeError,
"getsockaddrarg: "
"AF_INET address must be tuple, not %.500s",
Py_TYPE(args)->tp_name);
return 0;
}
if (!PyArg_ParseTuple(args, "eti:getsockaddrarg",
  "idna", &host, &port))
return 0;
addr=(struct sockaddr_in*)addr_ret;
result = setipaddr(host, (struct sockaddr *)addr,
   sizeof(*addr),  AF_INET);
PyMem_Free(host);
if (result < 0)
return 0;
addr->sin_family = AF_INET;
addr->sin_port = htons((short)port);
*len_ret = sizeof *addr;
return 1;
}

--
components: None
messages: 80794
nosy: roman.zeyde
severity: normal
status: open
title: getsockaddrarg() casts port number from int to short without any warning
versions: Python 2.7

___
Python tracker 
<http://bugs.python.org/issue5104>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5104] getsockaddrarg() casts port number from int to short without any warning

2009-01-29 Thread Roman Zeyde

Changes by Roman Zeyde :


--
components: +Extension Modules -None

___
Python tracker 
<http://bugs.python.org/issue5104>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5104] getsockaddrarg() casts port number from int to short without any warning

2009-01-29 Thread Roman Zeyde

Changes by Roman Zeyde :


--
type:  -> behavior

___
Python tracker 
<http://bugs.python.org/issue5104>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5104] getsockaddrarg() casts port number from int to short without any warning

2009-02-14 Thread Roman Zeyde

Roman Zeyde  added the comment:

I've checked Python 3.0.1 today (at
http://svn.python.org/projects/python/tags/r301/Modules/socketmodule.c)
and it seems that the bug above has been fixed there too.

___
Python tracker 
<http://bugs.python.org/issue5104>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18169] struct.pack() behaves strangely for 'L' on 64bit Linux

2013-06-08 Thread Roman Zeyde

New submission from Roman Zeyde:

Reproduction:

Python 2.7.4 (default, Apr 19 2013, 18:28:01) 
[GCC 4.7.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import struct
>>> struct.pack('!L', 0x01020304)
'\x01\x02\x03\x04'
>>> struct.pack('>L', 0x01020304)
'\x01\x02\x03\x04'
>>> struct.pack('>> struct.pack('L', 0x01020304)
'\x04\x03\x02\x01\x00\x00\x00\x00' ### WAT??? ###
>>> 

As far as I see at the source code 
(http://hg.python.org/releasing/2.7.4/file/9290822f2280/Modules/_struct.c#l703),
 sizeof(long) is used as the size of 'L', which is equal to 8 at 64bit Linux...

The problem is that the results of packing with 'L' returns 8 bytes,
instead of 4 - as was expected from the documentation...

--
components: Interpreter Core
messages: 190817
nosy: Roman.Zeyde
priority: normal
severity: normal
status: open
title: struct.pack() behaves strangely for 'L' on 64bit Linux
type: behavior
versions: Python 2.7

___
Python tracker 
<http://bugs.python.org/issue18169>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18169] struct.pack() behaves strangely for 'L' on 64bit Linux

2013-06-08 Thread Roman Zeyde

Roman Zeyde added the comment:

You are correct - the documentation is right: 
"Format characters have the following meaning; the conversion between C and 
Python values should be obvious given their types. The ‘Standard size’ column 
refers to the size of the packed value in bytes when using standard size; that 
is, when the format string starts with one of '<', '>', '!' or '='. When using 
native size, the size of the packed value is platform-dependent."

So indeed, there is no problem - just my own misinterpretation of the docs...

--
status: pending -> open
type:  -> behavior

___
Python tracker 
<http://bugs.python.org/issue18169>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18169] struct.pack() behaves strangely for 'L' on 64bit Linux

2013-06-08 Thread Roman Zeyde

Changes by Roman Zeyde :


--
resolution:  -> works for me
status: open -> closed

___
Python tracker 
<http://bugs.python.org/issue18169>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com