{"id":2215833,"url":"http://patchwork.ozlabs.org/api/patches/2215833/?format=json","web_url":"http://patchwork.ozlabs.org/project/ltp/patch/20260325122207.1967-1-always.starving0@gmail.com/","project":{"id":59,"url":"http://patchwork.ozlabs.org/api/projects/59/?format=json","name":"Linux Test Project development","link_name":"ltp","list_id":"ltp.lists.linux.it","list_email":"ltp@lists.linux.it","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260325122207.1967-1-always.starving0@gmail.com>","list_archive_url":null,"date":"2026-03-25T12:22:05","name":"[v5] open: fix cleanup condition and use snprintf","commit_ref":null,"pull_url":null,"state":"changes-requested","archived":false,"hash":"9d2b01d2aaf59a1eacc4497bb25e1fbf284de464","submitter":{"id":92589,"url":"http://patchwork.ozlabs.org/api/people/92589/?format=json","name":"Jinseok Kim","email":"always.starving0@gmail.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/ltp/patch/20260325122207.1967-1-always.starving0@gmail.com/mbox/","series":[{"id":497432,"url":"http://patchwork.ozlabs.org/api/series/497432/?format=json","web_url":"http://patchwork.ozlabs.org/project/ltp/list/?series=497432","date":"2026-03-25T12:22:05","name":"[v5] open: fix cleanup condition and use snprintf","version":5,"mbox":"http://patchwork.ozlabs.org/series/497432/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2215833/comments/","check":"success","checks":"http://patchwork.ozlabs.org/api/patches/2215833/checks/","tags":{},"related":[],"headers":{"Return-Path":"<ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it>","X-Original-To":["incoming@patchwork.ozlabs.org","ltp@lists.linux.it"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","ltp@picard.linux.it"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=a1YcgR+t;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it\n (client-ip=213.254.12.146; helo=picard.linux.it;\n envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it;\n receiver=patchwork.ozlabs.org)"],"Received":["from picard.linux.it (picard.linux.it [213.254.12.146])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fgmJH1lcWz1xy1\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 25 Mar 2026 23:22:39 +1100 (AEDT)","from picard.linux.it (localhost [IPv6:::1])\n\tby picard.linux.it (Postfix) with ESMTP id C61BE3E4875\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 25 Mar 2026 13:22:36 +0100 (CET)","from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it\n [IPv6:2001:4b78:1:20::7])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature ECDSA (secp384r1))\n (No client certificate requested)\n by picard.linux.it (Postfix) with ESMTPS id CDF303E143F\n for <ltp@lists.linux.it>; Wed, 25 Mar 2026 13:22:32 +0100 (CET)","from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com\n [IPv6:2607:f8b0:4864:20::1044])\n (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 556162003B7\n for <ltp@lists.linux.it>; Wed, 25 Mar 2026 13:22:32 +0100 (CET)","by mail-pj1-x1044.google.com with SMTP id\n 98e67ed59e1d1-35a1f549e7eso2940805a91.0\n for <ltp@lists.linux.it>; Wed, 25 Mar 2026 05:22:32 -0700 (PDT)","from localhost.localdomain ([211.196.223.197])\n by smtp.gmail.com with ESMTPSA id\n 98e67ed59e1d1-35c0dd77c57sm831731a91.5.2026.03.25.05.22.29\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Wed, 25 Mar 2026 05:22:30 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20251104; t=1774441351; x=1775046151; darn=lists.linux.it;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=cchd8EY3LQZrecvPfqdSCw1FSJxa+On/v7sif/CBCMA=;\n b=a1YcgR+tkuITu8XHzrj+q0ZT2wJ9Rg1NsoukdTMrnVKSOFYtxqubNbhIx9dI5OmUnS\n wcukoCi/JB+0dL3ebrQjohp/zGZAP+LGOuayAhXUX4P3Jb7Z1epYYGYtI9z/zgrq7xZ1\n Du/fTCM2nYgIBA9cmvkIE5MtI5+uA5Zhp6YWYiNl0DjKZAuReNkOH+D/69mN7XnMDyrL\n klvDjZks8pWL29sTRbqLzfujWU1+EXBTbZJkZeQ7GbhUuF4WyGm8TyoRlcQwAG/gAMhf\n fyTTnKrfBU2P5CpFYkgeAddxIYxjOnBUvnB14G6khdssto3xVPwMc7V/e7lAoyHkzQ/E\n NEUg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1774441351; x=1775046151;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=cchd8EY3LQZrecvPfqdSCw1FSJxa+On/v7sif/CBCMA=;\n b=kctYtPf/sNXXk3dNdkUUm+WfmahyqWEBjCvAuAuNECi9xBSoYyqAteuG6Y5CKjRJ8B\n 0Ik7YLQ/oKNPLCNCINjPZTLepHRg3CDnCS03w6fMzH2UFR8psaHK//pmhTLDSZTuHx14\n yRYMj4uzHVUGUByXGhRDa8QMvdtrsW64V9JnXV7O4ytmPACJxf5UjWbnBubL+k04Iuel\n DA26ecUGQ35zzyKxXVBBF8w/x9gZmWZ2fdEALLkXW8X+fyM1bxB7bsBZ2hs3M3nvdU1d\n DtMihz9mdrNSLTBpDSZvGI+noPLdtHO2Dt97utAUklzrL0mkZySRqUcg+lRiTEMLtNsg\n Zjqg==","X-Gm-Message-State":"AOJu0YxizLhBPi+mbJ7cCp1frP5w+MnucxcLoiUlbhKfsUPgwN1NORUq\n lXsJvwozN12EtQyftLPLlJ0IpCb2nVv//WI8WBo29Vsq5Sj2K+N50ZkWKD5uhc0lOQ==","X-Gm-Gg":"ATEYQzwgZqLNpI0eWPzRhlibMV2X8dZe4qOrNJln8jzRMoI6hVFqjeSdQTcg1ab3rTA\n yPQr2C9gaievzBK6q+V30+OpAz3N07KP98rJhCMIwMpQuQS/8bJEK/f8JgsMBRXOtGHDsrODAd5\n gSBkzUkppcfNyP9SoGDbR8+Mgo+efeF+/z1xtdUN3qlcgLH4lRPY5vpFKG/45x+Biktp2c+wPja\n 5l6QLajz5YrasU5MU+f7qYpAHJF0Ub4tTAEwCDVxeTO0dCJP++avtzEc9Z+63gykfws/DNfuiHp\n 0qzpifx3aALiDDYQS2pCd22nFetN/hs4FVjtRH+GP5Xm2B1m6miGndHJ1rntkMHQxvY39GsRu7R\n y3SQ8TnjSScpBWja/INytjE760XarU4WcCZAWPvz0lVeR4LEFajnzKpc3VAw8J9dWrCjXKMs2Yp\n Ks5Aso86nsb/wUu2EcsZFHdUveutOViJneMwFEcmjG301V","X-Received":"by 2002:a17:90b:2dd2:b0:35c:854:d1d0 with SMTP id\n 98e67ed59e1d1-35c0dd94e96mr3029293a91.26.1774441350643;\n Wed, 25 Mar 2026 05:22:30 -0700 (PDT)","From":"Jinseok Kim <always.starving0@gmail.com>","To":"andrea.cervesato@suse.com","Date":"Wed, 25 Mar 2026 21:22:05 +0900","Message-ID":"<20260325122207.1967-1-always.starving0@gmail.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<69c0e189.050a0220.8a4b1.49b0@mx.google.com>","References":"<69c0e189.050a0220.8a4b1.49b0@mx.google.com>","MIME-Version":"1.0","X-Spam-Status":"No, score=0.3 required=7.0 tests=DKIM_SIGNED,DKIM_VALID,\n DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,\n SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=disabled version=4.0.1","X-Spam-Checker-Version":"SpamAssassin 4.0.1 (2024-03-25) on in-7.smtp.seeweb.it","X-Virus-Scanned":"clamav-milter 1.0.9 at in-7.smtp.seeweb.it","X-Virus-Status":"Clean","Subject":"[LTP] [PATCH v5] open: fix cleanup condition and use snprintf","X-BeenThere":"ltp@lists.linux.it","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"Linux Test Project <ltp.lists.linux.it>","List-Unsubscribe":"<https://lists.linux.it/options/ltp>,\n <mailto:ltp-request@lists.linux.it?subject=unsubscribe>","List-Archive":"<http://lists.linux.it/pipermail/ltp/>","List-Post":"<mailto:ltp@lists.linux.it>","List-Help":"<mailto:ltp-request@lists.linux.it?subject=help>","List-Subscribe":"<https://lists.linux.it/listinfo/ltp>,\n <mailto:ltp-request@lists.linux.it?subject=subscribe>","Cc":"ltp@lists.linux.it","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it","Sender":"\"ltp\" <ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it>"},"content":"Replace sprintf() with snprintf() for safer string handling.\n\nThe cleanup logic checked '!first' to decide whether to close file\ndescriptors. Since file descriptor 0 is valid, this may incorrectly\nskip cleanup and leak descriptors.\n\nAlso initialize \"first\" to -1 and set the fds array to -1 after\nallocation. Skip such entries in cleanup() to avoid calling SAFE_CLOSE()\non invalid file descriptors.\n\nSigned-off-by: Jinseok Kim <always.starving0@gmail.com>\n---\n testcases/kernel/syscalls/open/open04.c | 24 ++++++++++++++----------\n 1 file changed, 14 insertions(+), 10 deletions(-)\n\n--\n2.43.0","diff":"diff --git a/testcases/kernel/syscalls/open/open04.c b/testcases/kernel/syscalls/open/open04.c\nindex 7573af1c8..3457024fc 100644\n--- a/testcases/kernel/syscalls/open/open04.c\n+++ b/testcases/kernel/syscalls/open/open04.c\n@@ -15,7 +15,8 @@\n\n #define FNAME \"open04\"\n\n-static int fds_limit, first, i;\n+static int fds_limit;\n+static int first = -1;\n static int *fds;\n static char fname[20];\n\n@@ -29,10 +30,11 @@ static void setup(void)\n \tfirst = SAFE_OPEN(FNAME, O_RDWR | O_CREAT, 0777);\n\n \tfds = SAFE_MALLOC(sizeof(int) * (fds_limit - first));\n+\tmemset(fds, -1, sizeof(int) * (fds_limit - first));\n \tfds[0] = first;\n\n-\tfor (i = first + 1; i < fds_limit; i++) {\n-\t\tsprintf(fname, FNAME \".%d\", i);\n+\tfor (int i = first + 1; i < fds_limit; i++) {\n+\t\tsnprintf(fname, sizeof(fname), FNAME \".%d\", i);\n \t\tfd = open(fname, O_RDWR | O_CREAT, 0777);\n \t\tif (fd == -1) {\n \t\t\tif (errno != EMFILE)\n@@ -46,20 +48,22 @@ static void setup(void)\n\n static void run(void)\n {\n-\tsprintf(fname, FNAME \".%d\", fds_limit);\n+\tsnprintf(fname, sizeof(fname), FNAME \".%d\", fds_limit);\n \tTST_EXP_FAIL2(open(fname, O_RDWR | O_CREAT, 0777), EMFILE);\n }\n\n static void cleanup(void)\n {\n-\tif (!first || !fds)\n-\t\treturn;\n+\tif (first >= 0) {\n+\t\tint limit = fds_limit - first;\n\n-\tfor (i = first; i < fds_limit; i++)\n-\t\tSAFE_CLOSE(fds[i - first]);\n+\t\tfor (int i = 0; i < limit; i++) {\n+\t\t\tif (fds[i] != -1)\n+\t\t\t\tSAFE_CLOSE(fds[i]);\n+\t\t}\n+\t}\n\n-\tif (fds)\n-\t\tfree(fds);\n+\tfree(fds);\n }\n\n static struct tst_test test = {\n","prefixes":["v5"]}