Source: bind9
Version: 1:9.10.3.dfsg.P4-10
Severity: wishlist
Tags: patch
User: [email protected]
Usertags: timestamps
X-Debbugs-Cc: [email protected]
Hi,
Whilst working on the "reproducible builds" effort [0], we noticed that bind9
could not be built reproducibly.
Patch attached.
[0] https://wiki.debian.org/ReproducibleBuilds
Regards,
--
,''`.
: :' : Chris Lamb
`. `'` [email protected] / chris-lamb.co.uk
`-
--- a/debian/patches/80_reproducible_build.diff 1970-01-01 02:00:00.000000000
+0200
--- b/debian/patches/80_reproducible_build.diff 2016-06-23 16:47:56.902997121
+0200
@@ -0,0 +1,58 @@
+--- bind9-9.10.3.dfsg.P4.orig/lib/dns/gen.c
++++ bind9-9.10.3.dfsg.P4/lib/dns/gen.c
+@@ -38,6 +38,8 @@
+ #include <stdlib.h>
+ #include <string.h>
+ #include <time.h>
++#include <errno.h>
++#include <limits.h>
+
+ #ifdef WIN32
+ #include "gen-win32.h"
+@@ -543,6 +545,9 @@ main(int argc, char **argv) {
+ char *prefix = NULL;
+ char *suffix = NULL;
+ char *file = NULL;
++ char *source_date_epoch;
++ unsigned long long epoch;
++ char *endptr;
+ isc_dir_t dir;
+
+ for (i = 0; i < TYPENAMES; i++)
+@@ -633,8 +638,34 @@ main(int argc, char **argv) {
+ INSIST(n > 0 && (unsigned)n < sizeof(srcdir));
+ sd(0, "", buf, filetype);
+
+- if (time(&now) != -1) {
+- if ((tm = localtime(&now)) != NULL && tm->tm_year > 104) {
++ source_date_epoch = getenv("SOURCE_DATE_EPOCH");
++ if (source_date_epoch) {
++ errno = 0;
++ epoch = strtoull(source_date_epoch, &endptr, 10);
++ if ((errno == ERANGE && (epoch == ULLONG_MAX || epoch == 0))
++ || (errno != 0 && epoch == 0)) {
++ fprintf(stderr, "Environment variable
$SOURCE_DATE_EPOCH: strtoull: %s\n", strerror(errno));
++ exit(EXIT_FAILURE);
++ }
++ if (endptr == source_date_epoch) {
++ fprintf(stderr, "Environment variable
$SOURCE_DATE_EPOCH: No digits were found: %s\n", endptr);
++ exit(EXIT_FAILURE);
++ }
++ if (*endptr != '\0') {
++ fprintf(stderr, "Environment variable
$SOURCE_DATE_EPOCH: Trailing garbage: %s\n", endptr);
++ exit(EXIT_FAILURE);
++ }
++ if (epoch > ULONG_MAX) {
++ fprintf(stderr, "Environment variable
$SOURCE_DATE_EPOCH: value must be smaller than or equal to: %lu but was found
to be: %llu \n", ULONG_MAX, epoch);
++ exit(EXIT_FAILURE);
++ }
++ now = epoch;
++ } else {
++ time(&now);
++ }
++
++ if (now != -1) {
++ if ((tm = gmtime(&now)) != NULL && tm->tm_year > 104) {
+ n = snprintf(year, sizeof(year), "-%d",
+ tm->tm_year + 1900);
+ INSIST(n > 0 && (unsigned)n < sizeof(year));
--- a/debian/patches/series 2016-06-23 15:18:50.923042149 +0200
--- b/debian/patches/series 2016-06-23 16:47:54.270973512 +0200
@@ -10,3 +10,4 @@
34_prepare_native_pkcs11.diff
70_precise_time.diff
75_ctxstart_no_sighandling.diff
+80_reproducible_build.diff