From patchwork Fri Jun 9 15:59:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Simmons-Talbott X-Patchwork-Id: 1793067 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=Ti7C1sdA; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Qd5Q22Kqpz20QH for ; Sat, 10 Jun 2023 02:00:10 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 34E943856974 for ; Fri, 9 Jun 2023 16:00:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 34E943856974 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1686326408; bh=Dn6+QGjbTcbM0Udne5GIT7rTxWmJ7PC699zzTDjlxXQ=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Ti7C1sdAx2An+1eaQnpyLrefDNkYCeIVpmC/UpXJSyjg/4zv/qFpo+i4jN5IIMJCq oNnA4a+Jh+tY605vIxA1+rTtKl2qRrohIZtWARLzDxLZ/7/jmpyLqLNPAOnPL4VWHs coSb5jflwivNL5SuUTTh2lv7RaySkgxdWMcjtE00= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id B89843858D3C for ; Fri, 9 Jun 2023 15:59:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B89843858D3C Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-364-KmSkKEU0OCiSNkCx3v0Aeg-1; Fri, 09 Jun 2023 11:59:45 -0400 X-MC-Unique: KmSkKEU0OCiSNkCx3v0Aeg-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-75d44483fdeso248211785a.0 for ; Fri, 09 Jun 2023 08:59:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686326385; x=1688918385; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Dn6+QGjbTcbM0Udne5GIT7rTxWmJ7PC699zzTDjlxXQ=; b=gvthut9WqL4Jcd8tLzb36TRr+NRsHnEwtsypbe6v5THCtUmIcrIX2IBURECpoRZmCh lZVEtefnEM19yO2h7NG4FO8938mgcMy/2EZ+l1+218smJtvWB2OfZlzi60abosdiCtWV 3nClpxlWvfBq1jRVBNUnzvc/7HDw6qlO26lTBTM1qLUZqrAgAxZJFSbQDdeGKJkAEsvP oZDVAmlyZRR6gqreBockWf1SQaFuUeq0vR6ecJH9Z8W4bAf4rUk8ITNiDDPYrNSILYir y9RDVmRCq9QWhAjqRgkXPhp/Pdsn3vzeAaI2Dhf+8Y1BmTS61TpolbEbGodiH4pnkTP9 Hi+Q== X-Gm-Message-State: AC+VfDw+RTBDF1xMytSme4eprY4Fvl/damjpfD/4XW3Ux8u/BIDSUH/d VMwJzMS2Y3eXDm8XIg36n5Zdyiy0LJTLBBcrJSHGg7XZOUI6eChWUc8Q8rStXH8HHyHeG7wYSGs uxGTqr2DcJIJmelqGLjp5o1Y0dw7sBH7M/Kqd/ckwmq6h3pIsxDWypQ9nNP+4gi0MpufkinYS82 b4A2wj X-Received: by 2002:a05:620a:3d14:b0:75d:4f84:58a2 with SMTP id tq20-20020a05620a3d1400b0075d4f8458a2mr1293409qkn.58.1686326384788; Fri, 09 Jun 2023 08:59:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ45aquHTRWZgVMYhFB9Eb/7d2ZeoQotRiRz/J5+ym9Lyp7E8T1vS3GkPe/7k8aje+81Ia2gRw== X-Received: by 2002:a05:620a:3d14:b0:75d:4f84:58a2 with SMTP id tq20-20020a05620a3d1400b0075d4f8458a2mr1293379qkn.58.1686326384179; Fri, 09 Jun 2023 08:59:44 -0700 (PDT) Received: from oak.redhat.com (c-71-206-142-238.hsd1.va.comcast.net. [71.206.142.238]) by smtp.gmail.com with ESMTPSA id c23-20020a05620a165700b0075b238d7b01sm1094772qko.134.2023.06.09.08.59.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jun 2023 08:59:43 -0700 (PDT) To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH] tst-getdate: Improve testcase flexibility and add test. Date: Fri, 9 Jun 2023 11:59:40 -0400 Message-Id: <20230609155940.207256-1-josimmon@redhat.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Joe Simmons-Talbott via Libc-alpha From: Joe Simmons-Talbott Reply-To: Joe Simmons-Talbott Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" The getdate testcases all expect successful results. Add support for negative testcases and testcases where a full date and time are not supplied by skipping the tm checks in the test. Add a testcase that would catch a use-after-free that was recently found. --- time/tst-getdate.c | 56 ++++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/time/tst-getdate.c b/time/tst-getdate.c index 4c9ed28d58..0036d313d7 100644 --- a/time/tst-getdate.c +++ b/time/tst-getdate.c @@ -32,34 +32,40 @@ static const struct const char *tz; struct tm tm; bool time64; + int err_val; + bool check_tm; } tests [] = { {"21:01:10 1999-1-31", "Universal", {10, 1, 21, 31, 0, 99, 0, 0, 0}, - false }, + false , 0, true}, {"21:01:10 1999-1-31", "Universal", {10, 1, 21, 31, 0, 99, 0, 0, 0}, - false }, + false , 0, true}, {" 21:01:10 1999-1-31", "Universal", {10, 1, 21, 31, 0, 99, 0, 0, 0}, - false }, + false , 0, true}, {"21:01:10 1999-1-31 ", "Universal", {10, 1, 21, 31, 0, 99, 0, 0, 0}, - false }, + false , 0, true}, {" 21:01:10 1999-1-31 ", "Universal", {10, 1, 21, 31, 0, 99, 0, 0, 0}, - false }, + false , 0, true}, {"21:01:10 1999-2-28", "Universal", {10, 1, 21, 28, 1, 99, 0, 0, 0}, - false }, + false , 0, true}, {"16:30:46 2000-2-29", "Universal", {46, 30,16, 29, 1, 100, 0, 0, 0}, - false }, - {"01-08-2000 05:06:07", "Europe/Berlin", {7, 6, 5, 1, 7, 100, 0, 0, 0}, - false }, + false , 0, true}, + {"01-08-2000 05:06:07", "Europe/Berlin", {7, 6, 5, 1, 7, 100, 0, 0, 0}, + false , 0, true}, + {"01-08-2000 a 05:06:07", "Europe/Berlin", {7, 6, 5, 1, 7, 100, 0, 0, 0}, + false , 7, false}, + {" 12 AM ", "Europe/Berlin", {7, 6, 5, 1, 7, 100, 0, 0, 0}, + false , 0, false}, /* 64 bit time_t tests. */ {"21:01:10 2038-1-31", "Universal", {10, 1, 21, 31, 0, 138, 0, 0, 0}, - true }, + true , 0, true}, {"22:01:10 2048-5-20", "Universal", {10, 1, 22, 20, 4, 148, 0, 0, 0}, - true }, + true , 0, true}, {"01-08-2038 05:06:07", "Europe/Berlin", {7, 6, 5, 1, 7, 138, 0, 0, 0}, - true }, + true , 0, true}, {"20-03-2050 21:30:08", "Europe/Berlin", {8, 30, 21, 20, 2, 150, 0, 0, 0}, - true } + true , 0, true} }; static const char * @@ -93,7 +99,8 @@ report_date_error (void) static char *datemsk; static const char datemskstr[] = "%H:%M:%S %F\n" - "%d-%m-%Y %T\n"; + "%d-%m-%Y %T\n" + "%I %p\n"; static void do_prepare (int argc, char **argv) @@ -115,13 +122,23 @@ do_test (void) setenv ("TZ", tests[i].tz, 1); tm = getdate (tests[i].str); - TEST_COMPARE (getdate_err, 0); - if (getdate_err != 0) + + /* Only check getdate_err when tm is NULL as getdate doesn't set + getdate_err on success. */ + if (tm == NULL) + TEST_COMPARE (getdate_err, tests[i].err_val); + if (tests[i].err_val != 0) /* Expected failure */ + { + TEST_COMPARE_BLOB (tm, 0, NULL, 0); + continue; + } + + if (tm == NULL && getdate_err != tests[i].err_val) { support_record_failure (); printf ("%s\n", report_date_error ()); } - else + else if (tests[i].check_tm) { TEST_COMPARE (tests[i].tm.tm_mon, tm->tm_mon); TEST_COMPARE (tests[i].tm.tm_year, tm->tm_year); @@ -132,8 +149,9 @@ do_test (void) } struct tm tms; - TEST_COMPARE (getdate_r (tests[i].str, &tms), 0); - if (getdate_err == 0) + int retval = getdate_r (tests[i].str, &tms); + TEST_COMPARE (retval, tests[i].err_val); + if (retval == tests[i].err_val && tests[i].check_tm) { TEST_COMPARE (tests[i].tm.tm_mon, tms.tm_mon); TEST_COMPARE (tests[i].tm.tm_year, tms.tm_year);