Page MenuHome GnuPG

libksba reproducible builds
Closed, ResolvedPublic


The asn1-tables.c file in libksba 1.3.5 is not reproducibly generated by asn1-gentables due to inconsistent results returned by the cmp_strings() function passed to qsort(), which leads to unstable sort results. This patch maintains the sort-by-length and then sort-by-contents that I believe the original function intended:

--- clean/libksba-1.3.5/src/asn1-gentables.c	2016-08-22 11:38:21.000000000 +0200
+++ libksba-1.3.5/src/asn1-gentables.c	2020-01-08 10:00:27.297737650 +0100
@@ -109,10 +109,17 @@
 static int
 cmp_string (const void *aptr, const void *bptr)
-  const struct name_list_s **a = (const struct name_list_s **)aptr;
-  const struct name_list_s **b = (const struct name_list_s **)bptr;
+  const char *a = (*(const struct name_list_s **)aptr)->name;
+  const char *b = (*(const struct name_list_s **)bptr)->name;
-  return strlen ((*a)->name) < strlen ((*b)->name);
+  const size_t len_a = strlen(a);
+  const size_t len_b = strlen(b);
+  if (len_a < len_b)
+    return -1;
+  if (len_a > len_b)
+    return +1;
+  return strcmp(a, b);
 static void


Related Objects

Event Timeline

werner triaged this task as Normal priority.Jan 8 2020, 1:26 PM
werner added a project: libksba.
werner added a subscriber: werner.

Frankly, I am not sure why we sort that table at all. Your patch does not harm, though.

Sorting the table is a good idea for reproducibility, since otherwise the tree depends on the order of the arguments to asn1-gentables, which are generated with a wildcard expansion that might be shell or file system dependent.

werner claimed this task.

Thanks. Applied. Will go into 1.4.0