From patchwork Tue Sep 10 10:20:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wu,Haiqiang" X-Patchwork-Id: 1160265 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=126.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=126.com header.i=@126.com header.b="VLi2p8VK"; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46SMcP3Rvdz9sNw for ; Tue, 10 Sep 2019 21:04:34 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 625F63C20A2 for ; Tue, 10 Sep 2019 13:04:27 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) by picard.linux.it (Postfix) with ESMTP id 34CC93C13DE for ; Tue, 10 Sep 2019 12:20:39 +0200 (CEST) Received: from m15-64.126.com (m15-64.126.com [220.181.15.64]) by in-6.smtp.seeweb.it (Postfix) with ESMTP id EA8A414002DB for ; Tue, 10 Sep 2019 12:20:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=Date:From:Subject:MIME-Version:Message-ID; bh=MlBGC P3XxTh0kdJjX2pUbhkPLApKZQZsnfOz0mcA8NY=; b=VLi2p8VKrPuR1Xz2ymwOV COpY6quhdkRsiuUIO0JE/3rxwnlGLJFdvUeWBtv3oYVLYC+8633lHrspB//uU3y6 K6ywj1XTbIurWQATGj/r5nHs7PdJpSXEG6uveNG6UWGdkOTy1VWS765i5suVqiDn dxzbXRBkmZiEkukdDlBDZ4= Received: from frequentemail$126.com ( [114.247.175.195] ) by ajax-webmail-wmsvr64 (Coremail) ; Tue, 10 Sep 2019 18:20:33 +0800 (CST) X-Originating-IP: [114.247.175.195] Date: Tue, 10 Sep 2019 18:20:33 +0800 (CST) From: frequent To: ltp@lists.linux.it X-Priority: 3 X-Mailer: Coremail Webmail Server Version XT5.0.10 build 20190724(ac680a23) Copyright (c) 2002-2019 www.mailtech.cn 126com MIME-Version: 1.0 Message-ID: <424f5bc4.776d.16d1ab07134.Coremail.frequentemail@126.com> X-Coremail-Locale: zh_CN X-CM-TRANSID: QMqowACnrxPzeHddiHZ1AA--.19680W X-CM-SenderInfo: 5iuh135hqwvzxdloqiyswou0bp/1tbiwRMsHFpD8WZn9gAAs9 X-Coremail-Antispam: 1U5529EdanIXcx71UUUUU7vcSsGvfC2KfnxnUU== X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, GB_FREEMAIL_DISPTO, HTML_MESSAGE, SPF_HELO_NONE, SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it X-Mailman-Approved-At: Tue, 10 Sep 2019 13:04:24 +0200 Subject: [LTP] [PATCH] buffer overflow detected ***: dup201 terminated X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Issues related to this mail: https://github.com/linux-test-project/ltp/issues/570 According to the bactrace in the issue description, we could easily find out that the problem is due to the codes in dup201.c line 80 and 142. As metan-cuw commented, the loop at line 142 is of no use and probablely is a leftover. So we could safely remove these codes. This patch does : 1). remove the leftover, and of course, the issue 570 will be eventually go over. 2). removed unused global variables. The patch goes as: int *ofd; @@ -86,22 +83,19 @@ struct test_case_t { void (*setupfunc) (); } TC[] = { /* First fd argument is less than 0 - EBADF */ - { - &badfd, &goodfd, EBADF, NULL}, - /* First fd argument is getdtablesize() - EBADF */ - { - &maxfd, &goodfd, EBADF, NULL}, - /* Second fd argument is less than 0 - EBADF */ - { - &mystdout, &badfd, EBADF, NULL}, - /* Second fd argument is getdtablesize() - EBADF */ - { -&mystdout, &maxfd, EBADF, NULL},}; + {&badfd, &goodfd, EBADF, NULL}, + /* First fd argument is getdtablesize() - EBADF */ + {&maxfd, &goodfd, EBADF, NULL}, + /* Second fd argument is less than 0 - EBADF */ + {&mystdout, &badfd, EBADF, NULL}, + /* Second fd argument is getdtablesize() - EBADF */ + {&mystdout, &maxfd, EBADF, NULL}, +}; int main(int ac, char **av) { int lc; - int i, j; + int i; tst_parse_opts(ac, av, NULL, NULL); @@ -137,12 +131,6 @@ int main(int ac, char **av) strerror(TC[i].error)); } } - /* cleanup things in case we are looping */ - for (j = fd1; j < maxfd; j++) { - sprintf(fname, "dup201.%d.%d", j, mypid); - (void)close(j); - (void)unlink(fname); - } } cleanup(); @@ -163,7 +151,6 @@ void setup(void) /* get some test specific values */ maxfd = getdtablesize(); - mypid = getpid(); } /* @@ -172,6 +159,5 @@ void setup(void) */ void cleanup(void) { - tst_rmdir(); } diff --git a/testcases/kernel/syscalls/dup2/dup201.c b/testcases/kernel/syscalls/dup2/dup201.c index 4507ac1..762ad86 100644 --- a/testcases/kernel/syscalls/dup2/dup201.c +++ b/testcases/kernel/syscalls/dup2/dup201.c @@ -75,9 +75,6 @@ int maxfd; int goodfd = 5; int badfd = -1; int mystdout = 0; -int fd, fd1; -int mypid; -char fname[20]; struct test_case_t {