Generalize the src-verify.c utility program and provide additional documentation

in the header comment.

FossilOrigin-Name: 7ed84046ef0c2c64031cac3a3a6b43aac3ac40aeb36838d8d046493f2d5ed122
This commit is contained in:
drh 2023-06-05 01:05:46 +00:00
parent 59714faa68
commit 706047470e
3 changed files with 70 additions and 19 deletions

View File

@ -1,5 +1,5 @@
C Minor\scosmetic\snormalizations\sfor\sthe\sMSVC\smakefile.
D 2023-06-05T00:57:38.649
C Generalize\sthe\ssrc-verify.c\sutility\sprogram\sand\sprovide\sadditional\sdocumentation\nin\sthe\sheader\scomment.
D 2023-06-05T01:05:46.192
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -2040,7 +2040,7 @@ F tool/sqldiff.c 2a693b4e7c1818c23f871f82f0c3fe67d80b67e3f087893089d33da29c1e387
F tool/sqlite3_analyzer.c.in f88615bf33098945e0a42f17733f472083d150b58bdaaa5555a7129d0a51621c
F tool/sqltclsh.c.in 1bcc2e9da58fadf17b0bf6a50e68c1159e602ce057210b655d50bad5aaaef898
F tool/sqltclsh.tcl 862f4cf1418df5e1315b5db3b5ebe88969e2a784525af5fbf9596592f14ed848
F tool/src-verify.c efdc92df3139dedeba0b1875d39760e477259949dbdb2ef44ce2524a94dc51b6
F tool/src-verify.c 8991969de8edcee688af869901f0b6aef69abde34a06956207e77674004366cf
F tool/srcck1.c 371de5363b70154012955544f86fdee8f6e5326f
F tool/stack_usage.tcl f8e71b92cdb099a147dad572375595eae55eca43
F tool/stripccomments.c 20b8aabc4694d0d4af5566e42da1f1a03aff057689370326e9269a9ddcffdc37
@ -2073,8 +2073,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 0e79ee97b18792dba9213bd9961f53e2bae765ac92df7963703d08857da74fd1
R c1008182b8d7d2429ca6242c5570d28d
U mistachkin
Z 16274bc3b88a1f11be3e7fc9f78070cc
P c9fda8d6dba36841415d0f445b4081b051bfaa70428b605ac0b9ca4ae98f7d49
R e7690e0368ac1bfdeb0f14274f730ca3
U drh
Z 811356101b2366481e1c6bca269b4085
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
c9fda8d6dba36841415d0f445b4081b051bfaa70428b605ac0b9ca4ae98f7d49
7ed84046ef0c2c64031cac3a3a6b43aac3ac40aeb36838d8d046493f2d5ed122

View File

@ -1,17 +1,39 @@
/*
** This utility program reads the "manifest" and "manifest.uuid" files
** of the SQLite source tree and uses the content therein to verify that
** all of the other files in the source tree are correct.
** in a Fossil-generated source tree (where the repository has the
** "manifest" setting turned on - this is true for SQLite and Fossil itself)
** and verifies that the source code files are complete and unaltered by
** checking the SHA1 and SHA3 hashes of the source files contained in the
** "manifest" file.
**
** Limitations:
** On success it prints: "OK $HASH" where $HASH is the SHA3-256 hash of
** the check-in for the source tree. If it finds any discrepencies, it
** prints "Derived from $HASH with changes to:" followed by a list of files
** which have been altered.
**
** * Does not handle special characters in the filenames. The
** SQLite source tree has no filenames containing special
** characters, so that should not be an issue.
** USAGE:
**
** * Filename length is limited to 1000 characters. The SQLite
** source tree has no files more than 100 characters in length
** so that also should not be an issue.
** src-verify $(ROOT)
**
** Where ROOT is the root of the source tree - the directory that contains
** the "manifest" and "manifest.uuid" files. Add the "-v" option for
** some debugging output. Additional debugging options:
**
** src-verify --sha1 FILE ...
** src-verify --sha3 FILE ...
**
** Compute the SHA1 or SHA3-256 hashes for all of the FILEs named
**
** COMPILING:
**
** This utility is self-contained. It uses only the standard library.
** There are no other dependencies. Just compile it and run it.
**
** LIMITATIONS:
**
** * This utility assumes that the check-in hash uses SHA3-256.
** It is ok for individual file hashes to be SHA1, but the
** check-in itself must use a SHA3-256 hash.
*/
#include <stdio.h>
#include <string.h>
@ -721,6 +743,34 @@ void sha1sum_file(const char *zFilename, char *zCksum){
SHA1Final(zResult, &ctx);
DigestToBase16(zResult, zCksum, 20);
}
/*
** Decode a fossilized string in-place.
*/
void defossilize(char *z){
int i, j, c;
char *zSlash = strchr(z, '\\');
if( zSlash==0 ) return;
i = zSlash - z;
for(j=i; (c=z[i])!=0; i++){
if( c=='\\' && z[i+1] ){
i++;
switch( z[i] ){
case 'n': c = '\n'; break;
case 's': c = ' '; break;
case 't': c = '\t'; break;
case 'r': c = '\r'; break;
case 'v': c = '\v'; break;
case 'f': c = '\f'; break;
case '0': c = 0; break;
case '\\': c = '\\'; break;
default: c = z[i]; break;
}
}
z[j++] = c;
}
if( z[j] ) z[j] = 0;
}
/*
** Report that a single file is incorrect.
@ -744,8 +794,8 @@ int main(int argc, char **argv){
char zHash[100];
char zCk[100];
char zVers[100];
char zLine[4000];
char zFile[2000];
char zLine[40000];
char zFile[40000];
if( argc>=3 && strcmp(argv[1],"--sha1")==0 ){
/* For testing purposes, if the first argument is --sha1, then simply
** compute and print the SHA1 checksum of all subsequent arguments. */
@ -816,6 +866,7 @@ int main(int argc, char **argv){
}
if( j<sizeof(zFile) ) zFile[j] = 0;
zFile[sizeof(zFile)-1] = 0;
defossilize(&zFile[nDir]);
if( zLine[i]!=' ' ){
errorMsg(&nErr, zVers, "manifest");
return 1;