Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp633037pxt; Thu, 12 Aug 2021 06:23:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzt9rRLyVPoR6eqRmT9B/FQYj9xKHf/8M+GbEWzkYLPzt8ORecwimHscWltE+Ddv+HN5Xno X-Received: by 2002:a05:6402:27d2:: with SMTP id c18mr1007947ede.87.1628774600220; Thu, 12 Aug 2021 06:23:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628774600; cv=none; d=google.com; s=arc-20160816; b=scejD94Zb59Eil3XCAjCZsfQObnBEpPMMwHRdP7vNLQP9wg0I5kJecfsI3X2icyMXi LJzKieCx6tqF/KUFWOyAwncga9TL332PugfLKGd9FL0beAhKtB4tHWYjFJbw1M2Pi5dY DpBaGNneF2Q9nOjG1Tfogu+WEahEregw8a6x19eSOpiLXcX+96yukAOyO3B8URj5opk2 tOf/Ac1rQ1siKo9GuVNom85YjWjAa6q90F0V2LzX1fsSfh1qunVSjAXL/NpNsOd67qwr br1mA+WoBZ3813TdCZC6DCibhRjqf0dASKP2Ek1xqe8pnWlLSYfZEZxFZZ1ysX/y0r1c ESpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :dkim-signature; bh=SaV466qKmDbX32CqXDpoabTK+1tGIC5BVkeekLUlF5I=; b=ZsEM2uWgW2gMk9gnVkItwzdwv3lNdc/9Fen28Pt9okC0INPqKUDo05Eo/ud+EnlRVW o7JVpzcecPT8JDcL5fkp6IaPafWHdlJz1IdLbKgRe6ImmwfzCcZ/8QhoWvQuyu9qs+E1 GoLj3hPg7mFFkPxpD22kj8Fux3WGrm3VHUy6fUF9zf8HlcBcgN7y8ob0EIvFtsztqRbg jJTTwHBDjWHbChRniku0jUbIe/rU76WhwPTkpbH8Z9ajkGncpf4motPlmArQD/u6DYmu XqFBYEXXIO6loMmfHf8tm6ndivHHGLL9qXzsH/iikojYyLOYHE3+gRXq1cutYz2ONpI5 yWtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KeUztBo+; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a25si2403068ejc.304.2021.08.12.06.22.55; Thu, 12 Aug 2021 06:23:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KeUztBo+; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235971AbhHLNWn (ORCPT + 99 others); Thu, 12 Aug 2021 09:22:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:44389 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237556AbhHLNTw (ORCPT ); Thu, 12 Aug 2021 09:19:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628774366; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SaV466qKmDbX32CqXDpoabTK+1tGIC5BVkeekLUlF5I=; b=KeUztBo+6+MKv4PEHYzMy1j96+/BuNpiAGoQOdj+Liv10qZ3Q8gpHpjFpjA+OmkUu6taES dfgXpPpz/aaEGYQVPgN0LzQLv/SYUo/LWhdc2N1ZVmFbSxrOXsvvZOCDc1TqYTDOes2RyW d17xjJDGik0bi2GR6vXpdmAyDWzSa6s= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-576-bhgs66-VNO6jmJB53BmjUg-1; Thu, 12 Aug 2021 09:19:24 -0400 X-MC-Unique: bhgs66-VNO6jmJB53BmjUg-1 Received: by mail-wm1-f72.google.com with SMTP id t12-20020a05600c198c00b002e6bf2ee83dso149011wmq.1 for ; Thu, 12 Aug 2021 06:19:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:mime-version:content-transfer-encoding; bh=SaV466qKmDbX32CqXDpoabTK+1tGIC5BVkeekLUlF5I=; b=IVXMlOXGRVitxHooDZhlgGzuqFsSgz3+2lOXHKVC61cVJtOGEWsDg7MpcPLibFE/kP Vm0A1UGqiw/lGaNkbXXABNcp89o60v/meL+TR9Sg/wwIt3+edlO4DTe3lRhKo+IfI+R3 FbZAcfz/KnVEEZN9Pk0qZaWJalG24oUOJr1sdOygJVKUNJ62vBlWaKCojSg7OCh04ww0 DFnVSvjGNrpxiqOFpJVR4hqgTXNbuhScpbxyYnP5/x60zLM2bYwyTa6vOOl+Uz6voXYc DWwZrMqQxfH4IoBnvxXqlQ1jfPwckC7cUCf1kBrhqgAxGcBk2J5MpoIHYZm04JPluey+ cVdQ== X-Gm-Message-State: AOAM532G3XsJZI2eSMlsWAbEOywQuY15xMtN8XwlnJGgrIh7ryP7lcir wiYIPKLIu6pH/Vd6b2LKbrV/zr3CwZDcacbbu1V6ZVUMLGk0aEKHLJ4hexivQQutNxNzF3RsMdT QagWrn1jws3vLTKzESCLg X-Received: by 2002:a7b:c1cf:: with SMTP id a15mr3991461wmj.72.1628774363399; Thu, 12 Aug 2021 06:19:23 -0700 (PDT) X-Received: by 2002:a7b:c1cf:: with SMTP id a15mr3991439wmj.72.1628774363210; Thu, 12 Aug 2021 06:19:23 -0700 (PDT) Received: from ajmitchell.remote.csb ([95.145.245.173]) by smtp.gmail.com with ESMTPSA id u23sm9546627wmc.24.2021.08.12.06.19.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Aug 2021 06:19:22 -0700 (PDT) Message-ID: <76b96fa95dfb6c53f28cae6b622f71559d8bfe6c.camel@redhat.com> Subject: Re: [PATCH 2/4] nfs-utils: Fix mem leaks in gssd From: Alice Mitchell To: Olga Kornievskaia Cc: linux-nfs , Steve Dickson Date: Thu, 12 Aug 2021 14:19:21 +0100 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5 (3.28.5-16.el8) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org On Fri, 2021-08-06 at 15:12 -0400, Olga Kornievskaia wrote: > On Fri, Aug 6, 2021 at 12:23 PM Alice Mitchell > wrote: > > Also fix the modification of a returned config value which > > should be treated as const. > > > > Signed-off-by: Alice Mitchell > > --- > > utils/gssd/gssd.c | 10 +++++----- > > 1 file changed, 5 insertions(+), 5 deletions(-) > > > > diff --git a/utils/gssd/gssd.c b/utils/gssd/gssd.c > > index 4113cba..0815665 100644 > > --- a/utils/gssd/gssd.c > > +++ b/utils/gssd/gssd.c > > @@ -1016,7 +1016,7 @@ read_gss_conf(void) > > keytabfile = s; > > s = conf_get_str("gssd", "cred-cache-directory"); > > if (s) > > - ccachedir = s; > > + ccachedir = strdup(s); > > s = conf_get_str("gssd", "preferred-realm"); > > if (s) > > preferred_realm = s; > > @@ -1070,7 +1070,7 @@ main(int argc, char *argv[]) > > keytabfile = optarg; > > break; > > case 'd': > > - ccachedir = optarg; > > + ccachedir = strdup(optarg); > > Is it possible that there will be a value in both config file and > command line args. If we are strdup-ing in both we'll be over- > writting > and leaking memory? > > Why do we need to malloc it at all? Is it ever malloc-ed now (and > considered a leak)? I think in both cases it uses static memory and > doesnt require freeing. in both cases the string pointed to gets modified by a later strtok() and so will be modifying the original of argv or a conf parameter, which i presume is why there was ccacherdir_copy to avoid doing that, but it was never properly utilised. i guess strtok truncating those strings doesnt actually *hurt* anything right now, its just a case of unexpected side-effects should anyone later try to reuse them. > > > break; > > case 't': > > context_timeout = atoi(optarg); > > @@ -1133,7 +1133,6 @@ main(int argc, char *argv[]) > > } > > > > if (ccachedir) { > > - char *ccachedir_copy; > > char *ptr; > > > > for (ptr = ccachedir, i = 2; *ptr; ptr++) > > @@ -1141,8 +1140,7 @@ main(int argc, char *argv[]) > > i++; > > > > ccachesearch = malloc(i * sizeof(char *)); > > - ccachedir_copy = strdup(ccachedir); > > - if (!ccachedir_copy || !ccachesearch) { > > + if (!ccachesearch) { > > ccachedir_copy is the only leak here. > > > printerr(0, "malloc failure\n"); > > exit(EXIT_FAILURE); > > } > > @@ -1274,6 +1272,8 @@ main(int argc, char *argv[]) > > > > free(preferred_realm); > > free(ccachesearch); > > + if (ccachedir) > > + free(ccachedir); > > > > return rc < 0 ? EXIT_FAILURE : EXIT_SUCCESS; > > } > > -- > > 2.27.0 > > > >