reentr: update size after Renew
authorHugo van der Sanden <hv@crypt.org>
Tue, 28 Feb 2017 11:21:55 +0000 (11:21 +0000)
committerDavid Mitchell <davem@iabyn.com>
Wed, 15 Mar 2017 09:16:29 +0000 (09:16 +0000)
RT #130841

Setting it before Renew can cause problems if the Renew fails.

Required 'make regen'.

reentr.c
regen/reentr.pl

index c464acc..70b971b 100644 (file)
--- a/reentr.c
+++ b/reentr.c
 #include "perl.h"
 #include "reentr.h"
 
+#define RenewDouble(data_pointer, size_pointer, type) \
+    STMT_START { \
+       const size_t size = *(size_pointer) * 2; \
+       Renew((data_pointer), (size), type); \
+       *(size_pointer) = size; \
+    } STMT_END
+
 void
 Perl_reentrant_size(pTHX) {
        PERL_UNUSED_CONTEXT;
@@ -326,9 +333,8 @@ Perl_reentrant_retry(const char *f, ...)
                PERL_REENTRANT_MAXSIZE / 2)
 #endif
            {
-               PL_reentrant_buffer->_hostent_size *= 2;
-               Renew(PL_reentrant_buffer->_hostent_buffer,
-                     PL_reentrant_buffer->_hostent_size, char);
+               RenewDouble(PL_reentrant_buffer->_hostent_buffer,
+                       &PL_reentrant_buffer->_hostent_size, char);
                switch (PL_op->op_type) {
                case OP_GHBYADDR:
                    p0    = va_arg(ap, void *);
@@ -359,9 +365,8 @@ Perl_reentrant_retry(const char *f, ...)
 #endif
            {
                Gid_t gid;
-               PL_reentrant_buffer->_grent_size *= 2;
-               Renew(PL_reentrant_buffer->_grent_buffer,
-                     PL_reentrant_buffer->_grent_size, char);
+               RenewDouble(PL_reentrant_buffer->_grent_buffer,
+                     &PL_reentrant_buffer->_grent_size, char);
                switch (PL_op->op_type) {
                case OP_GGRNAM:
                    p0 = va_arg(ap, void *);
@@ -394,9 +399,8 @@ Perl_reentrant_retry(const char *f, ...)
 #endif
            {
                Netdb_net_t net;
-               PL_reentrant_buffer->_netent_size *= 2;
-               Renew(PL_reentrant_buffer->_netent_buffer,
-                     PL_reentrant_buffer->_netent_size, char);
+               RenewDouble(PL_reentrant_buffer->_netent_buffer,
+                     &PL_reentrant_buffer->_netent_size, char);
                switch (PL_op->op_type) {
                case OP_GNBYADDR:
                    net = va_arg(ap, Netdb_net_t);
@@ -426,9 +430,8 @@ Perl_reentrant_retry(const char *f, ...)
 #endif
            {
                Uid_t uid;
-               PL_reentrant_buffer->_pwent_size *= 2;
-               Renew(PL_reentrant_buffer->_pwent_buffer,
-                     PL_reentrant_buffer->_pwent_size, char);
+               RenewDouble(PL_reentrant_buffer->_pwent_buffer,
+                     &PL_reentrant_buffer->_pwent_size, char);
                switch (PL_op->op_type) {
                case OP_GPWNAM:
                    p0 = va_arg(ap, void *);
@@ -462,9 +465,8 @@ Perl_reentrant_retry(const char *f, ...)
                PERL_REENTRANT_MAXSIZE / 2)
 #endif
            {
-               PL_reentrant_buffer->_protoent_size *= 2;
-               Renew(PL_reentrant_buffer->_protoent_buffer,
-                     PL_reentrant_buffer->_protoent_size, char);
+               RenewDouble(PL_reentrant_buffer->_protoent_buffer,
+                     &PL_reentrant_buffer->_protoent_size, char);
                switch (PL_op->op_type) {
                case OP_GPBYNAME:
                    p0 = va_arg(ap, void *);
@@ -492,9 +494,8 @@ Perl_reentrant_retry(const char *f, ...)
                PERL_REENTRANT_MAXSIZE / 2)
 #endif
            {
-               PL_reentrant_buffer->_servent_size *= 2;
-               Renew(PL_reentrant_buffer->_servent_buffer,
-                     PL_reentrant_buffer->_servent_size, char);
+               RenewDouble(PL_reentrant_buffer->_servent_buffer,
+                     &PL_reentrant_buffer->_servent_size, char);
                switch (PL_op->op_type) {
                case OP_GSBYNAME:
                    p0 = va_arg(ap, void *);
index 802b8db..f8f78a5 100644 (file)
@@ -773,6 +773,13 @@ print $c <<"EOF";
 #include "perl.h"
 #include "reentr.h"
 
+#define RenewDouble(data_pointer, size_pointer, type) \\
+    STMT_START { \\
+       const size_t size = *(size_pointer) * 2; \\
+       Renew((data_pointer), (size), type); \\
+       *(size_pointer) = size; \\
+    } STMT_END
+
 void
 Perl_reentrant_size(pTHX) {
        PERL_UNUSED_CONTEXT;
@@ -840,9 +847,8 @@ Perl_reentrant_retry(const char *f, ...)
                PERL_REENTRANT_MAXSIZE / 2)
 #endif
            {
-               PL_reentrant_buffer->_hostent_size *= 2;
-               Renew(PL_reentrant_buffer->_hostent_buffer,
-                     PL_reentrant_buffer->_hostent_size, char);
+               RenewDouble(PL_reentrant_buffer->_hostent_buffer,
+                       &PL_reentrant_buffer->_hostent_size, char);
                switch (PL_op->op_type) {
                case OP_GHBYADDR:
                    p0    = va_arg(ap, void *);
@@ -873,9 +879,8 @@ Perl_reentrant_retry(const char *f, ...)
 #endif
            {
                Gid_t gid;
-               PL_reentrant_buffer->_grent_size *= 2;
-               Renew(PL_reentrant_buffer->_grent_buffer,
-                     PL_reentrant_buffer->_grent_size, char);
+               RenewDouble(PL_reentrant_buffer->_grent_buffer,
+                     &PL_reentrant_buffer->_grent_size, char);
                switch (PL_op->op_type) {
                case OP_GGRNAM:
                    p0 = va_arg(ap, void *);
@@ -908,9 +913,8 @@ Perl_reentrant_retry(const char *f, ...)
 #endif
            {
                Netdb_net_t net;
-               PL_reentrant_buffer->_netent_size *= 2;
-               Renew(PL_reentrant_buffer->_netent_buffer,
-                     PL_reentrant_buffer->_netent_size, char);
+               RenewDouble(PL_reentrant_buffer->_netent_buffer,
+                     &PL_reentrant_buffer->_netent_size, char);
                switch (PL_op->op_type) {
                case OP_GNBYADDR:
                    net = va_arg(ap, Netdb_net_t);
@@ -940,9 +944,8 @@ Perl_reentrant_retry(const char *f, ...)
 #endif
            {
                Uid_t uid;
-               PL_reentrant_buffer->_pwent_size *= 2;
-               Renew(PL_reentrant_buffer->_pwent_buffer,
-                     PL_reentrant_buffer->_pwent_size, char);
+               RenewDouble(PL_reentrant_buffer->_pwent_buffer,
+                     &PL_reentrant_buffer->_pwent_size, char);
                switch (PL_op->op_type) {
                case OP_GPWNAM:
                    p0 = va_arg(ap, void *);
@@ -976,9 +979,8 @@ Perl_reentrant_retry(const char *f, ...)
                PERL_REENTRANT_MAXSIZE / 2)
 #endif
            {
-               PL_reentrant_buffer->_protoent_size *= 2;
-               Renew(PL_reentrant_buffer->_protoent_buffer,
-                     PL_reentrant_buffer->_protoent_size, char);
+               RenewDouble(PL_reentrant_buffer->_protoent_buffer,
+                     &PL_reentrant_buffer->_protoent_size, char);
                switch (PL_op->op_type) {
                case OP_GPBYNAME:
                    p0 = va_arg(ap, void *);
@@ -1006,9 +1008,8 @@ Perl_reentrant_retry(const char *f, ...)
                PERL_REENTRANT_MAXSIZE / 2)
 #endif
            {
-               PL_reentrant_buffer->_servent_size *= 2;
-               Renew(PL_reentrant_buffer->_servent_buffer,
-                     PL_reentrant_buffer->_servent_size, char);
+               RenewDouble(PL_reentrant_buffer->_servent_buffer,
+                     &PL_reentrant_buffer->_servent_size, char);
                switch (PL_op->op_type) {
                case OP_GSBYNAME:
                    p0 = va_arg(ap, void *);