Bug#861955: canna: please make the output of mkbindic reproducible
Chris Lamb
lamby at debian.org
Sat May 6 12:50:10 UTC 2017
Source: canna
Version: 3.7p3-13.1
Severity: wishlist
Tags: patch
User: reproducible-builds at lists.alioth.debian.org
Usertags: timestamps toolchain
X-Debbugs-Cc: reproducible-bugs at lists.alioth.debian.org
Hi,
Whilst working on the Reproducible Builds effort [0], we noticed
that canna's mkbindic utility does not generate reproducible
output.
This affects other packages such as canna-shion, but probably
others.
Patch attached.
[0] https://reproducible-builds.org/
Regards,
--
,''`.
: :' : Chris Lamb
`. `'` lamby at debian.org / chris-lamb.co.uk
`-
-------------- next part --------------
diff --git a/cmd/crxdic/crxdic.c b/cmd/crxdic/crxdic.c
index 36d7a1f..4d76eef 100644
--- a/cmd/crxdic/crxdic.c
+++ b/cmd/crxdic/crxdic.c
@@ -31,6 +31,7 @@ static char rcsid[]="@(#) 102.1 $Id: crxdic.c,v 1.11.2.2 2003/12/27 17:15:21 aid
#include <time.h>
#include <ctype.h>
#include <fcntl.h>
+#include <limits.h>
#include <assert.h>
#include "ccompat.h"
#include "RKindep/file.h"
@@ -932,6 +933,9 @@ makeHeader(dic)
unsigned i;
RkiCksumCalc calc;
unsigned off;
+ char *source_date_epoch;
+ unsigned long long epoch;
+ char *endptr;
if (RkiCksumCRCInit(&calc)
|| RkiCksumAdd(&calc, dic->Dir->buf, dic->Dir->dirsiz)) {
@@ -963,7 +967,32 @@ makeHeader(dic)
hd.data[HD_CMPV].var = 0x300702L;
hd.flag[HD_CMPV] = -1;
}
- hd.data[HD_TIME].var = tloc = time(0);
+ 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);
+ }
+ tloc = epoch;
+ } else {
+ tloc = time(0);
+ }
+ hd.data[HD_TIME].var = tloc;
hd.flag[HD_TIME] = -1;
hd.data[HD_DMNM].ptr = (unsigned char *)STrdup(dic->name);
hd.flag[HD_DMNM] = strlen(dic->name);
More information about the Reproducible-bugs
mailing list