From patchwork Fri Jun 9 18:26:51 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: 70839 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C50F93858028 for ; Fri, 9 Jun 2023 18:27:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C50F93858028 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1686335239; bh=uSiUorI5cHIH7tw5rhU5QToZSQoSk1KpHRhfzlal+8g=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=XdUWSt8LKHQa+BRUw1Mn4fVQgaw2OIag7WiUp09WhJ59rfhS44q+0gNUt6QPYWDkl LG1rYlEnIm7ZCwYqB0/Mj57YaTe422Bnq8rEIPZfyFYd5aPRpEpOhIOmFO8yGflYel EhJ4TjAvihj2Hn5YjimLr1aIqskqxC99tlDKGoYY= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id CD92D3858D35 for ; Fri, 9 Jun 2023 18:26:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CD92D3858D35 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-453-T8pzuAV5OguYQ96bMG3iBQ-1; Fri, 09 Jun 2023 14:26:55 -0400 X-MC-Unique: T8pzuAV5OguYQ96bMG3iBQ-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-625fd27e074so26235226d6.3 for ; Fri, 09 Jun 2023 11:26:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686335214; x=1688927214; 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=uSiUorI5cHIH7tw5rhU5QToZSQoSk1KpHRhfzlal+8g=; b=MHEZRxHiVytx2PegV8HzJAUmcqm9X1h/gsTcpZ/3iKlfRc4AkPP0zR4eBX+37AcQW2 4qJE4VjCfoTf9gU4Z0OmIBsMa91cTCfmTJl6Xdo+z7vvNtQnsa1w2wlINNFoWER7XyHN i6NPPLlNEMpQaeXTuVcNonpPScvLldBdcScYxaZxka3NxY3Pg+J2TRyBtSdX2tgzjl+X +bxXC3fxZpGfTSjuNEvBiieA+9WImSclu5gjfc2QwfoImnBkTa0i4sXkGTKbU6qylckk 0ZTb0V7JE8Dtsx1SRUwB0R/IlQsSVC0zc4hpSNlRzq4Y3skxd5nvm2i5hzS1yn2SFy0X sQtA== X-Gm-Message-State: AC+VfDx//FCMIznLZGme2h1bY1q2ulvGK9LjJf5DYxzB5ZFY/zxstuK2 dIQebb1zqbbn6tezoIbA6KapdmY7x/q/BYKGrEC7DbOPCY7sy1kUhiBo6+oUQ1xPP+ExflhBDe0 +a2cdIee+GkDlMiy/FhuzsKmd+grs10wkPdwn1c6Hzkm2DADza8dJVNvyz4EgCz75rWCPmmXfn2 pmPTnM X-Received: by 2002:ad4:5bac:0:b0:61b:6fcd:34b7 with SMTP id 12-20020ad45bac000000b0061b6fcd34b7mr2741663qvq.17.1686335214237; Fri, 09 Jun 2023 11:26:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ43mFEGhL1apFSoe+vyAmlAlC6IcXx2mHBOHfLNbOfx/BxxA3b8bJfENyyq+P5zQa7b0fIISw== X-Received: by 2002:ad4:5bac:0:b0:61b:6fcd:34b7 with SMTP id 12-20020ad45bac000000b0061b6fcd34b7mr2741644qvq.17.1686335213909; Fri, 09 Jun 2023 11:26:53 -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 oj2-20020a056214440200b005ef442226bbsm1327764qvb.8.2023.06.09.11.26.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jun 2023 11:26:53 -0700 (PDT) To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH v2] tst-getdate: Improve testcase flexibility and add test. Date: Fri, 9 Jun 2023 14:26:51 -0400 Message-Id: <20230609182651.666320-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, 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+patchwork=sourceware.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. Reviewed-by: Arjun Shankar --- Changes to v1: * Retain old testcase and add a new one with spaces in the middle of the string. * Move the logic for getdate() failure into the same area. * Use TEST_VERIFY to compare pointer to NULL rather than TEST_COMPARE_BLOB with size 0 which is a nop. time/tst-getdate.c | 62 +++++++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/time/tst-getdate.c b/time/tst-getdate.c index 4c9ed28d58..78486ca2ed 100644 --- a/time/tst-getdate.c +++ b/time/tst-getdate.c @@ -32,34 +32,42 @@ 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 }, + false , 0, true}, {"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 +101,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 +124,25 @@ 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 (getdate_err != tests[i].err_val) + { + support_record_failure (); + printf ("%s\n", report_date_error ()); + } + } + if (tests[i].err_val != 0) /* Expected failure */ { - support_record_failure (); - printf ("%s\n", report_date_error ()); + TEST_VERIFY (tm == NULL); + continue; } - 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 +153,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);