This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
pp_sys.c: don't hardcode socket address buffer size
authorTomasz Konojacki <me@xenu.pl>
Thu, 30 Apr 2020 06:42:40 +0000 (06:42 +0000)
committerH.Merijn Brand <h.m.brand@xs4all.nl>
Tue, 19 May 2020 07:03:49 +0000 (09:03 +0200)
When it's possible, use sizeof(struct sockaddr_storage).

fixes #17761

metaconfig.h
pp_sys.c

index 96a02a5..baba5ea 100644 (file)
@@ -13,5 +13,5 @@
  * Symbols should only be here temporarily. Once they are actually used,
  * they should be removed from here.
  *
  * Symbols should only be here temporarily. Once they are actually used,
  * they should be removed from here.
  *
- * HAS_WCRTOMB HAS_SOCKADDR_STORAGE
+ * HAS_WCRTOMB
  */
  */
index 9bae03d..8c26d23 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -2763,9 +2763,13 @@ PP(pp_getpeername)
     if (!IoIFP(io))
        goto nuts;
 
     if (!IoIFP(io))
        goto nuts;
 
-    sv = sv_2mortal(newSV(257));
-    (void)SvPOK_only(sv);
+#ifdef HAS_SOCKADDR_STORAGE
+    len = sizeof(struct sockaddr_storage);
+#else
     len = 256;
     len = 256;
+#endif
+    sv = sv_2mortal(newSV(len+1));
+    (void)SvPOK_only(sv);
     SvCUR_set(sv, len);
     *SvEND(sv) ='\0';
     fd = PerlIO_fileno(IoIFP(io));
     SvCUR_set(sv, len);
     *SvEND(sv) ='\0';
     fd = PerlIO_fileno(IoIFP(io));