Skip to content

Commit 46cfc0a

Browse files
committed
Sigtool: CVD build hack for verify bug in 1.1 -> 1.4
Have --build retry if the tar.gz MD5 starts with 00.
1 parent b8795fd commit 46cfc0a

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

sigtool/sigtool.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,21 @@ static int build(const struct optstruct *opts)
11551155
free(tarfile);
11561156
return -1;
11571157
}
1158+
1159+
1160+
// Check if the MD5 starts with 00. If it does, we'll return CL_ELAST_ERROR. The caller may try again for better luck.
1161+
// This is to avoid a bug in hash verification with ClamAV 1.1 -> 1.4. The bug was fixed in 1.5.0.
1162+
// TODO: Remove this workaround when no one is using those versions.
1163+
if (pt[0] == '0' && pt[1] == '0') {
1164+
// print out the pt hash
1165+
mprintf(LOGG_INFO, "The tar.gz MD5 starts with 00, which will fail to verify in ClamAV 1.1 -> 1.4: %s\n", pt);
1166+
fclose(fh);
1167+
unlink(tarfile);
1168+
free(tarfile);
1169+
free(pt);
1170+
return CL_ELAST_ERROR;
1171+
}
1172+
11581173
rewind(fh);
11591174
sprintf(header + strlen(header), "%s:", pt);
11601175
free(pt);
@@ -3768,9 +3783,15 @@ int main(int argc, char **argv)
37683783
ret = asciinorm(opts);
37693784
else if (optget(opts, "utf16-decode")->enabled)
37703785
ret = utf16decode(opts);
3771-
else if (optget(opts, "build")->enabled)
3786+
else if (optget(opts, "build")->enabled) {
37723787
ret = build(opts);
3773-
else if (optget(opts, "unpack")->enabled)
3788+
if (ret == CL_ELAST_ERROR) {
3789+
// build() returns CL_ELAST_ERROR the hash starts with 00. This will fail to verify with ClamAV 1.1 -> 1.4.
3790+
// Retry the build again to get new hashes.
3791+
mprintf(LOGG_WARNING, "Retrying the build for a chance at a better hash.\n");
3792+
ret = build(opts);
3793+
}
3794+
} else if (optget(opts, "unpack")->enabled)
37743795
ret = unpack(opts);
37753796
else if (optget(opts, "unpack-current")->enabled)
37763797
ret = unpack(opts);

0 commit comments

Comments
 (0)