summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2001-09-05 22:23:06 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2001-09-05 22:23:06 +0000
commit1d68b939c4dd217c53cb0e1db87452ac2e6a3248 (patch)
treebe29945226d5c6de11446ab983dbb6a107bda1d1 /ext
parent43dece2ab75d79010b4220d46295e13b03e10f25 (diff)
downloadperl-1d68b939c4dd217c53cb0e1db87452ac2e6a3248.tar.gz
inet_ntoa() tweaks:
- don't allow addresses with > 255 characters - indent the HP-UX workaround - don't leak memory p4raw-id: //depot/perl@11889
Diffstat (limited to 'ext')
-rw-r--r--ext/Socket/Socket.xs20
1 files changed, 14 insertions, 6 deletions
diff --git a/ext/Socket/Socket.xs b/ext/Socket/Socket.xs
index 67f52799d0..85541c0d74 100644
--- a/ext/Socket/Socket.xs
+++ b/ext/Socket/Socket.xs
@@ -213,22 +213,30 @@ inet_ntoa(ip_address_sv)
STRLEN addrlen;
struct in_addr addr;
char * addr_str;
- char * ip_address = SvPV(ip_address_sv,addrlen);
+ char * ip_address;
+ if (DO_UTF8(ip_address_sv) && !sv_utf8_downgrade(ip_address_sv, 1))
+ croak("Wide character in Socket::ntoa");
+ ip_address = SvPV(ip_address_sv,addrlen);
if (addrlen != sizeof(addr)) {
croak("Bad arg length for %s, length is %d, should be %d",
"Socket::inet_ntoa",
addrlen, sizeof(addr));
}
-
Copy( ip_address, &addr, sizeof addr, char );
#if defined(__hpux) && defined(__GNUC__) && defined(USE_64_BIT_INT)
- /* GCC on HP_UX breaks the call to inet_ntoa, // sky*/
- addr_str = (char *) malloc(16);
- sprintf(addr_str, "%d.%d.%d.%d", ((addr.s_addr >> 24) & 0xFF) , ((addr.s_addr >> 16) & 0xFF), ((addr.s_addr >> 8) & 0xFF), (addr.s_addr & 0xFF));
+ /* GCC on HP_UX breaks the call to inet_ntoa --sky */
+ New(1138, addr_str, 4 * 3 + 3 + 1, char);
+ sprintf(addr_str, "%d.%d.%d.%d",
+ ((addr.s_addr >> 24) & 0xFF),
+ ((addr.s_addr >> 16) & 0xFF),
+ ((addr.s_addr >> 8) & 0xFF),
+ ( addr.s_addr & 0xFF));
+ ST(0) = sv_2mortal(newSVpvn(addr_str, strlen(addr_str)));
+ Safefree(addr_str);
#else
addr_str = inet_ntoa(addr);
-#endif
ST(0) = sv_2mortal(newSVpvn(addr_str, strlen(addr_str)));
+#endif
}
void