Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

py-2.3 socket.inet_pton() segfault. #38996

Closed
gminick mannequin opened this issue Aug 1, 2003 · 2 comments
Closed

py-2.3 socket.inet_pton() segfault. #38996

gminick mannequin opened this issue Aug 1, 2003 · 2 comments
Labels
extension-modules C modules in the Modules dir

Comments

@gminick
Copy link
Mannequin

gminick mannequin commented Aug 1, 2003

BPO 781722
Nosy @loewis

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2003-08-05.06:27:22.000>
created_at = <Date 2003-08-01.20:40:31.000>
labels = ['extension-modules']
title = 'py-2.3 socket.inet_pton() segfault.'
updated_at = <Date 2003-08-05.06:27:22.000>
user = 'https://bugs.python.org/gminick'

bugs.python.org fields:

activity = <Date 2003-08-05.06:27:22.000>
actor = 'loewis'
assignee = 'none'
closed = True
closed_date = None
closer = None
components = ['Extension Modules']
creation = <Date 2003-08-01.20:40:31.000>
creator = 'gminick'
dependencies = []
files = []
hgrepos = []
issue_num = 781722
keywords = []
message_count = 2.0
messages = ['17572', '17573']
nosy_count = 2.0
nosy_names = ['loewis', 'gminick']
pr_nums = []
priority = 'high'
resolution = 'accepted'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue781722'
versions = ['Python 2.3']

@gminick
Copy link
Mannequin Author

gminick mannequin commented Aug 1, 2003

It works (read: segfaults) only when compiled without
IPv6 support. Code to exploit this bug:

import socket
socket.inet_pton(socket.AF_INET6, '5aef:2b::8')

It segfaults because of that code from
Modules/socketmodule.c:
---

#ifdef ENABLE_IPV6
   char packed[MAX(sizeof(struct in_addr), sizeof(struct 
in6_addr))];
#else
   char packed[sizeof(struct in_addr)];
#endif
   if (!PyArg_ParseTuple(args, "is:inet_pton", &af, &ip)) {
      return NULL;
   }
   retval = inet_pton(af, ip, packed);

Because IPv6 is disabled packet is defined in that way:

char packed[sizeof(struct in_addr)];

but we're still able to ask inet_pton() to convert some
IPv6 address because socket.AF_INET6 constant is
available, but packet buffer is too small to hold IPv6 data.
A simple patch:
#---------------------------------

--- ../../orig/Python-2.3/Modules/socketmodule.c        
Thu Jul 17 18:58:48 2003
+++ socketmodule.c      Fri Aug  1 22:13:30 2003
@@ -2962,6 +2962,14 @@
                return NULL;
        }
 
+#ifndef ENABLE_IPV6
+   if(af == AF_INET6) {
+      PyErr_SetString(socket_error,
+         "can't use AF_INET6, IPv6 is disabled");
+      return NULL;
+   }
+#endif
+
        retval = inet_pton(af, ip, packed);
        if (retval < 0) {
                PyErr_SetFromErrno(socket_error);
#

Sorry, if you know about this one already.

@gminick gminick mannequin closed this as completed Aug 1, 2003
@gminick gminick mannequin added the extension-modules C modules in the Modules dir label Aug 1, 2003
@gminick gminick mannequin closed this as completed Aug 1, 2003
@gminick gminick mannequin added the extension-modules C modules in the Modules dir label Aug 1, 2003
@loewis
Copy link
Mannequin

loewis mannequin commented Aug 5, 2003

Logged In: YES
user_id=21627

Thanks for the patch. Applied as socketmodule.c 1.272 and
1.271.6.1, NEWS 1.831.4.5

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir
Projects
None yet
Development

No branches or pull requests

0 participants