From d4d3d93c7c8fd62dd86d54b6bfd0351bb32b7c43 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Tue, 24 Jun 2014 19:58:25 +1000 Subject: [PATCH] 3886. [bug] rbtdb_write_header should use a once to initialize FILE_VERSION. [RT #36374] (cherry picked from commit ba5c73b383b08326ab6b5ad2d7ca43e117e212f1) --- CHANGES | 3 +++ lib/dns/rbtdb.c | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index 8523ecf0b2e..d62cc067653 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +3886. [bug] rbtdb_write_header should use a once to initialize + FILE_VERSION. [RT #36374] + --- 9.10.1b1 released --- 3885. [port] Use 'open()' rather than 'file()' to open files in diff --git a/lib/dns/rbtdb.c b/lib/dns/rbtdb.c index 36fd348cd6a..b9fb3f339df 100644 --- a/lib/dns/rbtdb.c +++ b/lib/dns/rbtdb.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -7452,6 +7453,18 @@ rbtdb_zero_header(FILE *rbtfile) { return (result); } +static isc_once_t once = ISC_ONCE_INIT; + +static void +init_file_version(void) { + int n; + + memset(FILE_VERSION, 0, sizeof(FILE_VERSION)); + n = snprintf(FILE_VERSION, sizeof(FILE_VERSION), + "RBTDB Image %s %s", dns_major, dns_mapapi); + INSIST(n < sizeof(FILE_VERSION)); +} + /* * Write the file header out, recording the locations of the three * RBT's used in the rbtdb: tree, nsec, and nsec3, and including NodeDump @@ -7465,11 +7478,7 @@ rbtdb_write_header(FILE *rbtfile, off_t tree_location, off_t nsec_location, rbtdb_file_header_t header; isc_result_t result; - if (FILE_VERSION[0] == '\0') { - memset(FILE_VERSION, 0, sizeof(FILE_VERSION)); - snprintf(FILE_VERSION, sizeof(FILE_VERSION), - "RBTDB Image %s %s", dns_major, dns_mapapi); - } + RUNTIME_CHECK(isc_once_do(&once, init_file_version) == ISC_R_SUCCESS); memset(&header, 0, sizeof(rbtdb_file_header_t)); memmove(header.version1, FILE_VERSION, sizeof(header.version1)); -- 2.47.3