From 5fd8dd0d3bb7aa8dd0a0a8602deb24bb3323bd5c Mon Sep 17 00:00:00 2001 From: Tomasz Konojacki Date: Thu, 30 Apr 2020 06:42:40 +0000 Subject: [PATCH] pp_sys.c: don't hardcode socket address buffer size When it's possible, use sizeof(struct sockaddr_storage). fixes #17761 --- metaconfig.h | 2 +- pp_sys.c | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/metaconfig.h b/metaconfig.h index 96a02a5..baba5ea 100644 --- a/metaconfig.h +++ b/metaconfig.h @@ -13,5 +13,5 @@ * Symbols should only be here temporarily. Once they are actually used, * they should be removed from here. * - * HAS_WCRTOMB HAS_SOCKADDR_STORAGE + * HAS_WCRTOMB */ diff --git a/pp_sys.c b/pp_sys.c index 9bae03d..8c26d23 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -2763,9 +2763,13 @@ PP(pp_getpeername) 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; +#endif + sv = sv_2mortal(newSV(len+1)); + (void)SvPOK_only(sv); SvCUR_set(sv, len); *SvEND(sv) ='\0'; fd = PerlIO_fileno(IoIFP(io)); -- 1.8.3.1