Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/compat/linux/common Hum, don't pass an mbuf to realloc()...



details:   https://anonhg.NetBSD.org/src/rev/2e494b703867
branches:  trunk
changeset: 453741:2e494b703867
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sat Aug 24 14:08:35 2019 +0000

description:
Hum, don't pass an mbuf to realloc(). Inspired from copyin32_msg_control().

diffstat:

 sys/compat/linux/common/linux_socket.c |  12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)

diffs (45 lines):

diff -r 1a7c0b714564 -r 2e494b703867 sys/compat/linux/common/linux_socket.c
--- a/sys/compat/linux/common/linux_socket.c    Sat Aug 24 13:20:52 2019 +0000
+++ b/sys/compat/linux/common/linux_socket.c    Sat Aug 24 14:08:35 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linux_socket.c,v 1.146 2019/08/24 12:33:25 maxv Exp $  */
+/*     $NetBSD: linux_socket.c,v 1.147 2019/08/24 14:08:35 maxv Exp $  */
 
 /*-
  * Copyright (c) 1995, 1998, 2008 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.146 2019/08/24 12:33:25 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.147 2019/08/24 14:08:35 maxv Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -568,14 +568,15 @@
                        /* Check the buffer is big enough */
                        if (__predict_false(cidx + cspace > clen)) {
                                u_int8_t *nc;
+                               size_t nclen;
 
-                               clen = cidx + cspace;
-                               if (clen >= PAGE_SIZE) {
+                               nclen = cidx + cspace;
+                               if (nclen >= PAGE_SIZE) {
                                        error = EINVAL;
                                        goto done;
                                }
                                nc = realloc(clen <= MLEN ? NULL : control,
-                                               clen, M_TEMP, M_WAITOK);
+                                               nclen, M_TEMP, M_WAITOK);
                                if (!nc) {
                                        error = ENOMEM;
                                        goto done;
@@ -584,6 +585,7 @@
                                        /* Old buffer was in mbuf... */
                                        memcpy(nc, control, cidx);
                                control = nc;
+                               clen = nclen;
                        }
 
                        /* Copy header */



Home | Main Index | Thread Index | Old Index