From patchwork Tue Jan 21 00:49:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 13945566 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CBA548BE8 for ; Tue, 21 Jan 2025 00:49:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737420573; cv=none; b=qPY/XWWKaevhLOG9NDitQEiLfS6BB5egBIXlKbXWSCY361YX0rKvrQnWjbkc5BEx4PNTdbY/SZTjldef18kSsERFiUCx+dRiU1Uy6z3jz4NA/AS7WFU15UtHpveJhN9Q/KrewJGO4M18ef5DjyE84zyZMtYe3Fm5TgFqfzUKfK8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737420573; c=relaxed/simple; bh=Q1g8s/x8vcKYx27QtCyPr/MWIVaWCATQBdsGXa2Kfj8=; h=MIME-Version:From:Date:Message-ID:Subject:To:Cc:Content-Type; b=dG/YnhnD4ZItpodpys+UvRI797iDcnQR/rIzLOcihLpb+7e9YeCK+gvQ1kMPsUBTwDwUc+TgK6Fypjbkm3iP5SA4FhSS2wIUgDrDJowr4sHgqysI3AWp1sUmp65H2vjyoDN1mVgCnFR44HwQTdU17H5l8a1SDJJCThG/sY2JrTU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=afDjHOPX; arc=none smtp.client-ip=209.85.167.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="afDjHOPX" Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-54298ec925bso6047456e87.3 for ; Mon, 20 Jan 2025 16:49:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737420569; x=1738025369; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=gP6qn/FApXQMq6lfA//qwEAQ2ecx1WiySyCatf4tjXg=; b=afDjHOPX4ZtV8vLMKcQAP6YLNzSW867yeOK7Z/Xb7aIe6uAnkkVXikMZhQ9ZG1+2VE 0IOAT4/QvPKPc3oABVYHX5Suf+dNX2dAEfbVXIvkP+wvwQlouL5dyv2lhf89H0nwARh5 2JUdEtTDd8ThCz5PnZEmkTy9vbwpCBlQVMQdbatVINI9hpEnx0G2ioc/1cmto220iBfn g4UHRU70gnI4Q+SsmjF9v59x22WCVQCRMSmZWRD01Zne2GzdLPa4idMKpx3ft28ELHJ7 g0jJM97NkpcBw/6Dto6Hj3730u4CzQrZdEcQCWV+uKuBdai8jg8ZQGixaXWWx8h1DfUm nfSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737420569; x=1738025369; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=gP6qn/FApXQMq6lfA//qwEAQ2ecx1WiySyCatf4tjXg=; b=SrSpJs08+SQwBz5XCOyPQXheABuN+HMYchk/vhdGUrJg7cdmqWo/UfMGB42eKJ/W+A SSP9XF0vAokW04lotbFijuqFUzXZlJj8gx2Jh8+6k8rneK3gmgU/Fznjn/79s762EYAG m8Rsd5YeWM2xdIuA3C1msdKIuTiabijlCFq1rtKogjAmrgLhAluOjIJJbUIF5O5lGZG3 Pmkt6rMH/CcaVcpUDEIaHTi9DJMppqpvPHaTIDYkkOQWrMzzsga1Ug1B16ikRz4nEFBJ CpJC9YBHb7xHddwB1gG+4iws9h0tD+SHKQ+IzG2Boreqin4OyIvksTkIWUsi/gtF1DmQ lWsQ== X-Gm-Message-State: AOJu0YypAz/ggWndWWdJv/ucWhh9DTe0itH8ClZ8BJtNFP/MFYcQs8rG yP8hwkBdh2ritMOv19MLEThvdfjM4qEICzwVSb0Y22L5xQg6V4bfuPKpDfNM2j5lfCcEKINdT+7 JNnRqw711jAsWHCyS2sh9pDbv+vUeFvNF X-Gm-Gg: ASbGnctXkdTtOI+xVdzRl7hdaGe0kPlvYye5Ev8DHB/5maEeoYEO6ctulDYKUmguhc0 hpYarknIZtBhqi5m2oMuczkeIA5lgKRtBTGyh1lwIDzQsfu05AaM= X-Google-Smtp-Source: AGHT+IEWaxK+9wGppAbFwsHDURuk8fWxO4/Lgd421+KZSS7CoVqSju/Hl3Qmjm7w9bBbmpashEJmLLCNgKfk5TzEKro= X-Received: by 2002:a05:6512:4808:b0:542:2e09:639a with SMTP id 2adb3069b0e04-5439c22a678mr3884436e87.10.1737420569281; Mon, 20 Jan 2025 16:49:29 -0800 (PST) Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Steve French Date: Mon, 20 Jan 2025 18:49:17 -0600 X-Gm-Features: AbW1kva4btopGe5bFJjKlsMP0x00iSujiyZn9EhKmArgYPguVTyvomDkrZTAqS0 Message-ID: Subject: [PATCH][cifs-utils] avoid using mktemp when updating mtab To: CIFS , samba-technical Cc: Carlos Maiolino Attached patch to Fix build warning: cifs-utils/mount.cifs.c:1726: warning: the use of `mktemp' is dangerous, better use `mkstemp' or `mkdtemp' Use of mktemp() has been deprecated (e.g. due to security issues with symlink races), and instead mkstemp is often recommended. Change the use of mktemp to mkstemp in del_mtab in cifs-utils Fixes: f46dd7661cfb ("mount.cifs: Properly update mtab during remount") Opinions? Better way to address it? From f85c0c63adb4422b300770bfc2d844742e0fccd7 Mon Sep 17 00:00:00 2001 From: Steve French Date: Mon, 20 Jan 2025 18:34:38 -0600 Subject: [PATCH] cifs-utils: avoid using mktemp when updating mtab Fix build warning: cifs-utils/mount.cifs.c:1726: warning: the use of `mktemp' is dangerous, better use `mkstemp' or `mkdtemp' Use of mktemp() has been deprecated (e.g. due to security issues with symlink races), and instead mkstemp is often recommended. Change the use of mktemp to mkstemp in del_mtab in cifs-utils Fixes: f46dd7661cfb ("mount.cifs: Properly update mtab during remount") Signed-off-by: Steve French --- mount.cifs.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mount.cifs.c b/mount.cifs.c index e46693e..7605130 100644 --- a/mount.cifs.c +++ b/mount.cifs.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -1688,7 +1689,7 @@ add_mtab_exit: static int del_mtab(char *mountpoint) { - int len, tmprc, rc = 0; + int len, tmprc, rc = 0, tmpfd; FILE *mnttmp, *mntmtab; struct mntent *mountent; char *mtabfile, *mtabdir, *mtabtmpfile = NULL; @@ -1723,8 +1724,9 @@ del_mtab(char *mountpoint) goto del_mtab_exit; } - mtabtmpfile = mktemp(mtabtmpfile); - if (!mtabtmpfile) { + // Use mkstemp instead of mktemp + tmpfd = mkstemp(mtabtmpfile); + if (tmpfd == -1) { fprintf(stderr, "del_mtab: cannot setup tmp file destination\n"); rc = EX_FILEIO; goto del_mtab_exit; @@ -1734,13 +1736,15 @@ del_mtab(char *mountpoint) if (!mntmtab) { fprintf(stderr, "del_mtab: could not update mount table\n"); rc = EX_FILEIO; + close(tmpfd); goto del_mtab_exit; } - mnttmp = setmntent(mtabtmpfile, "w"); + mnttmp = fdopen(tmpfd, "w"); if (!mnttmp) { fprintf(stderr, "del_mtab: could not update mount table\n"); endmntent(mntmtab); + close(tmpfd); rc = EX_FILEIO; goto del_mtab_exit; } -- 2.43.0