From patchwork Mon Jun 12 15:39:00 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: 1793984 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=x8EhhJiA; 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 4Qfwq34J6vz20Vx for ; Tue, 13 Jun 2023 01:39:43 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D1F50386C5B6 for ; Mon, 12 Jun 2023 15:39:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D1F50386C5B6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1686584380; bh=Y3CVR1kEnE0LMJNRvsz+tK+FCvJzgEYPUfjlGZZEPvY=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=x8EhhJiA2hgrKIbd3XjL5NVDEIOGZiQcBzQr5/LjlZ+wKGh/heUW+ixi3UGrwCMc3 XIpk2HoPlPvFJWzJV6w0MtjSoPvlhuoq8m6V+TkUVpElGPeVnfyMniuy3PmkB0Nbmb JX4Lue/j+YtVpKmmBLHtv7d/du+UgsRZiLm75I30= 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 551F63858404 for ; Mon, 12 Jun 2023 15:39:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 551F63858404 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-131-zgnaPbUtMZ6exGXFR5B61w-1; Mon, 12 Jun 2023 11:39:22 -0400 X-MC-Unique: zgnaPbUtMZ6exGXFR5B61w-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-6260b40eac6so200436d6.0 for ; Mon, 12 Jun 2023 08:39:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686584346; x=1689176346; 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=Y3CVR1kEnE0LMJNRvsz+tK+FCvJzgEYPUfjlGZZEPvY=; b=ZydmB0qe5Q0gWe7edB+x7wmBaiv7pLltYhd6NI0e+O8MNm6QPQg2Q87HyPVSuWCwmf vQeoC1PyZH6kb1SrKoULr7twLdAEIRDJHBmgupFUsNO7yBiCXasVXUz4yA8JRHSJwkOV NSMD0OsqI/ku0Hy6pYiAX4i5h+xcb8WJmtH0yWiS/2zk3rQTH9jXqvovrPHprmeCStI2 ckBaJwiLoyw2iVMzBecOful13S055MajvchL6zifV6/xbIX+I3pKFuE+Rau/Hct8cU7s SLUq29E5x0IHc9QjMZNp5DKroL5jZn/R+6amFc+0LM8KFtvHOeQLMg44b7zcWjWUQvxb zqGA== X-Gm-Message-State: AC+VfDzCki0bMk+xV1tLs8s+eSajyCY57HZLBawiu4H4DXMCxOc3Q81C XJfQ4BpR8YkubvCyYqdrMT/aRJTI1nwoxhYDszDeO9RrdwderGvPXx8yUgI9jg6uRo8a3zsxWQ/ Ff7/v8Dcha46hsYwIbSOh06Run7bL7cuDkSlDoSU5Ir2ui6ilmryFiDxZ6iOdDiM9i9Kn9GBOxs VePwLm X-Received: by 2002:a05:6214:4013:b0:62d:f284:e992 with SMTP id kd19-20020a056214401300b0062df284e992mr1205148qvb.22.1686584346404; Mon, 12 Jun 2023 08:39:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6B7zYtQGimUMCrblwoJMAs4iOpzNd5qkRAYCxoZm5lDpsGOyHTwlJ7WO7IJ0x+tAKPW89heg== X-Received: by 2002:a05:6214:4013:b0:62d:f284:e992 with SMTP id kd19-20020a056214401300b0062df284e992mr1205125qvb.22.1686584346054; Mon, 12 Jun 2023 08:39:06 -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 i7-20020a056214030700b006260baec3b5sm3308370qvu.12.2023.06.12.08.39.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 08:39:05 -0700 (PDT) To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott , Arjun Shankar Subject: [PATCH v3] tst-getdate: Improve testcase flexibility and add test. Date: Mon, 12 Jun 2023 11:39:00 -0400 Message-Id: <20230612153900.623661-1-josimmon@redhat.com> X-Mailer: git-send-email 2.40.1 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+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. Reviewed-by: Arjun Shankar --- Changes to v2: * Set tm struct members to 0 for testcases where tm isn't checked. * Remove support_record_failure call since we're using TEST_COMPARE. time/tst-getdate.c | 59 ++++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/time/tst-getdate.c b/time/tst-getdate.c index 4c9ed28d58..4f204f4413 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", {0, 0, 0, 0, 0, 0, 0, 0, 0}, + false , 7, false}, + {" 12 AM ", "Europe/Berlin", {0, 0, 0, 0, 0, 0, 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,22 @@ 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) + 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 +150,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);