Skip to content

Commit 9369791

Browse files
committed
sigtool: Retry incompatible build hashes after a delay
A database archive whose MD5 starts with 00 cannot be verified by ClamAV 1.1 through 1.4. The existing immediate retry can rebuild the same archive when both attempts use the same timestamp. Retry this specific compatibility failure up to ten times, waiting one second for the build timestamp to change between attempts. Preserve immediate failures for all other errors and keep the test limited to one sigtool invocation. CLAM-3048
1 parent 9d0878e commit 9369791

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

sigtool/sigtool.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
#include "vba.h"
7070

7171
#define MAX_DEL_LOOKAHEAD 5000
72+
#define MAX_BUILD_ATTEMPTS 10
7273

7374
// global variable for the absolute path of the --cvdcertsdir option
7475
char *g_cvdcertsdir = NULL;
@@ -4175,6 +4176,7 @@ static void help(void)
41754176
int main(int argc, char **argv)
41764177
{
41774178
int ret;
4179+
unsigned int build_attempt;
41784180
struct optstruct *opts;
41794181
STATBUF sb;
41804182

@@ -4276,12 +4278,15 @@ int main(int argc, char **argv)
42764278
else if (optget(opts, "utf16-decode")->enabled)
42774279
ret = utf16decode(opts);
42784280
else if (optget(opts, "build")->enabled) {
4279-
ret = build(opts);
4280-
if (ret == CL_ELAST_ERROR) {
4281-
// build() returns CL_ELAST_ERROR the hash starts with 00. This will fail to verify with ClamAV 1.1 -> 1.4.
4282-
// Retry the build again to get new hashes.
4283-
mprintf(LOGG_WARNING, "Retrying the build for a chance at a better hash.\n");
4281+
for (build_attempt = 0; build_attempt < MAX_BUILD_ATTEMPTS; build_attempt++) {
42844282
ret = build(opts);
4283+
if (ret != CL_ELAST_ERROR || build_attempt + 1 == MAX_BUILD_ATTEMPTS)
4284+
break;
4285+
4286+
// build() returns CL_ELAST_ERROR when the hash starts with 00. This will fail to verify with ClamAV 1.1 -> 1.4.
4287+
// Wait for the build timestamp to change before retrying to get a different hash.
4288+
mprintf(LOGG_WARNING, "Retrying the build in one second for a chance at a better hash.\n");
4289+
sleep(1);
42854290
}
42864291
} else if (optget(opts, "sign")->enabled)
42874292
ret = sign(opts);

unit_tests/sigtool_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import shutil
1111
import subprocess
1212
import sys
13-
import time
1413
import unittest
1514

1615
import testcase

0 commit comments

Comments
 (0)