94084c
commit d5ba02f67dd62a63e29c29eebd6c543722aa6b5b
94084c
Author: Hans-Peter Nilsson <hp@axis.com>
94084c
Date:   Fri Dec 17 21:45:54 2021 +0100
94084c
94084c
    timezone: test-case for BZ #28707
94084c
    
94084c
    This test-case is the tzfile for Asuncion generated by
94084c
    tzlib-2021e as follows, using the tzlib-2021e zic: "zic -d
94084c
    DEST -r @1546300800 -L /dev/null -b slim
94084c
    SOURCE/southamerica".  Note that in its type 2 header, it
94084c
    has two entries in its "time-types" array (types), but only
94084c
    one entry in its "transition types" array (type_idxs).
94084c
    
94084c
            * timezone/Makefile, timezone/tst-pr28707.c,
94084c
            timezone/testdata/gen-XT5.sh: New test.
94084c
    
94084c
    Co-authored-by: Christopher Wong <Christopher.Wong@axis.com>
94084c
    (cherry picked from commit ebe899af0dc3215159a9c896ac6f35b72a18cb6e)
94084c
94084c
diff --git a/timezone/Makefile b/timezone/Makefile
94084c
index c624a189b322cb5f..f091663b8bbbceda 100644
94084c
--- a/timezone/Makefile
94084c
+++ b/timezone/Makefile
94084c
@@ -23,7 +23,7 @@ subdir	:= timezone
94084c
 include ../Makeconfig
94084c
 
94084c
 others	:= zdump zic
94084c
-tests	:= test-tz tst-timezone tst-tzset
94084c
+tests	:= test-tz tst-timezone tst-tzset tst-bz28707
94084c
 
94084c
 generated-dirs += testdata
94084c
 
94084c
@@ -85,10 +85,12 @@ $(objpfx)tst-timezone.out: $(addprefix $(testdata)/, \
94084c
 				       America/Sao_Paulo Asia/Tokyo \
94084c
 				       Europe/London)
94084c
 $(objpfx)tst-tzset.out: $(addprefix $(testdata)/XT, 1 2 3 4)
94084c
+$(objpfx)tst-bz28707.out: $(testdata)/XT5
94084c
 
94084c
 test-tz-ENV = TZDIR=$(testdata)
94084c
 tst-timezone-ENV = TZDIR=$(testdata)
94084c
 tst-tzset-ENV = TZDIR=$(testdata)
94084c
+tst-bz28707-ENV = TZDIR=$(testdata)
94084c
 
94084c
 # Note this must come second in the deps list for $(built-program-cmd) to work.
94084c
 zic-deps = $(objpfx)zic $(leapseconds) yearistype
94084c
@@ -122,6 +124,10 @@ $(testdata)/XT%: testdata/XT%
94084c
 	$(make-target-directory)
94084c
 	cp $< $@
94084c
 
94084c
+$(testdata)/XT%: testdata/gen-XT%.sh
94084c
+	$(SHELL) $< > $@.tmp
94084c
+	mv $@.tmp $@
94084c
+
94084c
 $(objpfx)tzselect: tzselect.ksh $(common-objpfx)config.make
94084c
 	sed -e 's|TZDIR=[^}]*|TZDIR=$(zonedir)|' \
94084c
 	    -e '/TZVERSION=/s|see_Makefile|"$(version)"|' \
94084c
diff --git a/timezone/testdata/gen-XT5.sh b/timezone/testdata/gen-XT5.sh
94084c
new file mode 100755
94084c
index 0000000000000000..3cea0569eb5a6a57
94084c
--- /dev/null
94084c
+++ b/timezone/testdata/gen-XT5.sh
94084c
@@ -0,0 +1,16 @@
94084c
+#! /bin/sh
94084c
+
94084c
+# This test-case is the tzfile for America/Asuncion
94084c
+# generated by tzlib-2021e as follows, using the tzlib-2021e
94084c
+# zic: "zic -d DEST -r @1546300800 -L /dev/null -b slim
94084c
+# SOURCE/southamerica".  Note that in its type 2 header, it
94084c
+# has two entries in its "time-types" array (types), but
94084c
+# only one entry in its "transition types" array
94084c
+# (type_idxs).
94084c
+
94084c
+printf \
94084c
+'TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0'\
94084c
+'\0\0\0\0\0\0\0\1\0\0\0\1\0\0\0\0\0\0\0TZif2\0\0\0\0\0\0\0\0'\
94084c
+'\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0\0\2\0\0\0\b\0'\
94084c
+'\0\0\0\*\255\200\1\0\0\0\0\0\0\377\377\325\320\1\4-00\0-03\0\n'\
94084c
+'<-04>4<-03>,M10.1.0/0,M3.4.0/0\n'
94084c
diff --git a/timezone/tst-bz28707.c b/timezone/tst-bz28707.c
94084c
new file mode 100644
94084c
index 0000000000000000..0a9df1e9a094f1e9
94084c
--- /dev/null
94084c
+++ b/timezone/tst-bz28707.c
94084c
@@ -0,0 +1,46 @@
94084c
+/* Copyright (C) 2021 Free Software Foundation, Inc.
94084c
+   This file is part of the GNU C Library.
94084c
+
94084c
+   The GNU C Library is free software; you can redistribute it and/or
94084c
+   modify it under the terms of the GNU Lesser General Public
94084c
+   License as published by the Free Software Foundation; either
94084c
+   version 2.1 of the License, or (at your option) any later version.
94084c
+
94084c
+   The GNU C Library is distributed in the hope that it will be useful,
94084c
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
94084c
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
94084c
+   Lesser General Public License for more details.
94084c
+
94084c
+   You should have received a copy of the GNU Lesser General Public
94084c
+   License along with the GNU C Library; if not, see
94084c
+   <https://www.gnu.org/licenses/>.  */
94084c
+
94084c
+#include <time.h>
94084c
+#include <stdio.h>
94084c
+#include <stdlib.h>
94084c
+#include <string.h>
94084c
+
94084c
+/* Test that we can use a truncated timezone-file, where the time-type
94084c
+   at index 0 is not indexed by the transition-types array (and the
94084c
+   transition-types array does not contain at least both one DST and one
94084c
+   normal time members).  */
94084c
+
94084c
+static int
94084c
+do_test (void)
94084c
+{
94084c
+  if (setenv ("TZ", "XT5", 1))
94084c
+    {
94084c
+      puts ("setenv failed.");
94084c
+      return 1;
94084c
+    }
94084c
+
94084c
+  tzset ();
94084c
+
94084c
+  return
94084c
+    /* Sanity-check that we got the right timezone-name for DST.  For
94084c
+       normal time, we're likely to get "-00" (the "unspecified" marker),
94084c
+       even though the POSIX timezone string says "-04".  Let's not test
94084c
+       that.  */
94084c
+    !(strcmp (tzname[1], "-03") == 0);
94084c
+}
94084c
+#include <support/test-driver.c>