From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server-vie001.gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,URIBL_DBL_BLOCKED_OPENDNS, URIBL_ZEN_BLOCKED_OPENDNS autolearn=ham autolearn_force=no version=3.4.6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=new2025; t=1757498464; bh=DYOjfH6SU7UZtaElcSJOtw1kFzppibQJ9bPdnaVQFPA=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type:Content-Transfer-Encoding:Message-ID:Date:From: Reply-To:Subject:To:Cc:In-Reply-To:References:Resent-Date: Resent-From:Resent-To:Resent-Cc:User-Agent:Content-Type: Content-Transfer-Encoding; b=lH8/7ZQ69y8QoO1uQg9L47p86M6lTF5xD5F03BY5eThdu2THpltE5v32wEQWmipky 6Us3RgtG1jMqWtdq7ME31guR+O9ivSSROOOqzKen9LJM8cNgCRHeWgQeMHS3BgmWwm jrCbtaf8xDC0xb5EAPywOxcDYdGd/UR79/VVy2+cdbvv9p03fnXXLN5yD3UnnqkxH0 Hmem5jTibLg2yN0mjij2WggtdHtkNwmqmPkFjjGNMU/SnBJzRp2wtot5y4kflB/2sY vc+do17SkQq/7j0eQ4p7FZyLcb4nvWgTzEBJdKfsz8+i+qaZcuocAZxdNsCu1fwDVx YCd++hNJK086w== Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by server-vie001.gnuweeb.org (Postfix) with ESMTPSA id 2226C31279D3 for ; Wed, 10 Sep 2025 10:01:04 +0000 (UTC) Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-7723f0924a3so8700595b3a.2 for ; Wed, 10 Sep 2025 03:01:04 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCXHcGP2wwvxgROzI4vCPZqepm6tLE7kx9+2Mct41mnuTGR6AGmzqydVrGmdXioVqCCjt79q@vger.gnuweeb.org X-Gm-Message-State: AOJu0Yzo23HgJjrgOlnapwQNaa21fFtKK/K83Bfxo/oz+MC+waTOzxVR yyB80FJAY18z+koovwEqfeRrFcwoILZZik21BuQlEyGtpOuxmRwaidfKY74quS70YbXnsJny75N Olb57uYlRRQXS6LicPXywgd4lnKDQ6bY= X-Google-Smtp-Source: AGHT+IFJqA6iXtzxHRCpkqC7T0eYRweuIw/Fjwp44kYptzbnbcQmCXIlQyN7aP4/3HH/I0EMaSULF/ghVc08vHkzaN8= X-Received: by 2002:a05:6a20:939d:b0:251:c33d:2783 with SMTP id adf61e73a8af0-2533fab6448mr19576798637.23.1757498462292; Wed, 10 Sep 2025 03:01:02 -0700 (PDT) MIME-Version: 1.0 References: <20250910030512.551673-1-reyuki@gnuweeb.org> <20250910030512.551673-3-reyuki@gnuweeb.org> In-Reply-To: <20250910030512.551673-3-reyuki@gnuweeb.org> From: Alviro Iskandar Setiawan Date: Wed, 10 Sep 2025 17:00:51 +0700 X-Gmail-Original-Message-ID: X-Gm-Features: Ac12FXzrPtmBD52FagIMatjriZ0RZyUiqaOZ5UYANFndUVLbUGB3DTiT9NdfXlE Message-ID: Subject: Re: [PATCH gwproxy v9 2/2] gwproxy: refactor code base to add experimental raw DNS backend To: Ahmad Gani Cc: Ammar Faizi , "GNU/Weeb Mailing List" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: On Wed, Sep 10, 2025 at 10:07=E2=80=AFAM Ahmad Gani wrote: > + cfg =3D &w->ctx->cfg; > + resolv =3D &w->dns_resolver; > + p1 =3D realloc(resolv->stack.arr, cfg->sess_map_cap * sizeof(*res= olv->stack.arr)); > + if (!p1) > + return; > + p2 =3D realloc(resolv->sess_map, cfg->sess_map_cap * sizeof(*reso= lv->sess_map)); > + if (!p2) > + return; This is absolutely stupid. You're messing with a simple C object without understanding even the basics regarding their handling. Just because it's a shrink operation, it doesn't mean realloc() will always spit out the same pointer you fed it. If "realloc(X, new_size)" succeeds, there's no guarantee the returned pointer matches the one you passed. 'X' could be invalid after the realloc() call. So, if "p2 =3D realloc()" fails, you could be leaking p1, and ->stack.arr might be invalid too, yet it's still used. Clearly, this one mistake results in double bugs, use-after-free and memory leak, because realloc() might free the pointer you gave it and allocate a new memory area with a different address. --=20 Software Engineer & ITPM Officer Alviro Iskandar Setiawan +1 908 777 0074