]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add extra parameter to zonefileCodecCreate() to indicate whether the new
authordan <dan@noemail.net>
Mon, 26 Feb 2018 07:58:39 +0000 (07:58 +0000)
committerdan <dan@noemail.net>
Mon, 26 Feb 2018 07:58:39 +0000 (07:58 +0000)
object will be used for mock-encryption or mock-decryption.

FossilOrigin-Name: 231832c4cb15862e61dfcc00fba9ab78ca7e2442a0d4aa1a98a191f5f8b4cff3

ext/zonefile/zonefile.c
ext/zonefile/zonefile1.test
manifest
manifest.uuid

index 844516509aa0b21843f03f6541fc6e19e76f9c6a..a8da4ba2011ff3a40e7c943361733e6420e0e7e2 100644 (file)
@@ -105,7 +105,8 @@ typedef unsigned long u32;
 ** SQLITE_HAVE_ZONEFILE_CODEC defined.
 */
 typedef struct ZonefileCodec ZonefileCodec;
-static int zonefileCodecCreate(int,unsigned char*,int,ZonefileCodec**,char**);
+static int zonefileCodecCreate(
+    int,int,unsigned char*,int,ZonefileCodec**,char**);
 static int zonefileCodecNonceSize(ZonefileCodec*);
 static void zonefileCodecEncode(ZonefileCodec*, unsigned char*, int);
 static void zonefileCodecDecode(ZonefileCodec*, unsigned char*, int);
@@ -116,6 +117,7 @@ typedef struct ZonefileCodec ZonefileCodec;
 
 struct ZonefileCodec {
   u8 aKey[16];
+  int bEncrypt;                   /* Second parameter passed to Create() */
 };
 
 /* Create a new encryption module instance using algorithm iAlg.
@@ -133,6 +135,7 @@ struct ZonefileCodec {
 */
 static int zonefileCodecCreate(
   int iAlg, 
+  int bEncrypt,                   /* True for encryption, zero for decryption */
   unsigned char *pKey, int nKey, 
   ZonefileCodec **pp, 
   char **pzErr
@@ -152,6 +155,7 @@ static int zonefileCodecCreate(
       for(i=0; i<sizeof(pRet->aKey); i++){
         pRet->aKey[i] = pKey[i % nKey];
       }
+      pRet->bEncrypt = bEncrypt;
     }
   }
 
@@ -176,6 +180,7 @@ static void zonefileCodecEncode(
 ){
   int i;
   u8 *aNonce = &pIn[nIn];
+  assert( pCodec->bEncrypt );
   sqlite3_randomness(16, aNonce);
   for(i=0; i<nIn; i++){
     pIn[i] = pIn[i] ^ aNonce[i%16] ^ pCodec->aKey[i%16];
@@ -193,6 +198,7 @@ static void zonefileCodecDecode(
 ){
   int i;
   u8 *aNonce = &pIn[nIn-16];
+  assert( pCodec->bEncrypt==0 );
   for(i=0; i<nIn-16; i++){
     pIn[i] = pIn[i] ^ aNonce[i%16] ^ pCodec->aKey[i%16];
   }
@@ -1124,7 +1130,7 @@ static void zonefileWriteFunc(
   if( sParam.encryptionType!=0 ){
     int n = strlen(sParam.encryptionKey);
     rc = zonefileCodecCreate(
-        sParam.encryptionType, (u8*)sParam.encryptionKey, n, &pCodec, &zErr
+        sParam.encryptionType, 1, (u8*)sParam.encryptionKey, n, &pCodec, &zErr
     );
     if( rc!=SQLITE_OK ){
       if( zErr ){
@@ -2585,7 +2591,7 @@ static int zonefileValueReadCache(sqlite3_context *pCtx, ZonefileCsr *pCsr){
         zErr = sqlite3_mprintf("missing encryption key for file \"%s\"", zFile);
         rc = SQLITE_ERROR;
       }else{
-        rc = zonefileCodecCreate(hdr.encryptionType, (u8*)z, n, &pCodec, &zErr);
+        rc = zonefileCodecCreate(hdr.encryptionType, 0, (u8*)z,n,&pCodec,&zErr);
       }
     }
 
index 92255f12193eaeb07af622b3020e11c9fd56e798..3c9a1c058347802611681e26fbff219a4a68dd2c 100644 (file)
@@ -627,5 +627,11 @@ foreach id {1 2 3 2 3 1} {
   incr i
 }
 
+if {[file exists /dev/null]} {
+  do_catchsql_test 11.2 {
+    INSERT INTO nm_files(filename) VALUES('/dev/null');
+  } {1 {failed to read zonefile header from file "/dev/null"}}
+}
+
 finish_test
 
index 504bfd748dd8911b7307e485481fa4d7d5bd4450..561b6d506d1ab37d3f3794e5a00f177f77ca2595 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Test\sedge\scases\sin\sthe\szonefile\smodule.\sFix\sa\sbroken\serror\smessage\sin\sthe\ssame.
-D 2018-02-24T08:26:21.801
+C Add\sextra\sparameter\sto\szonefileCodecCreate()\sto\sindicate\swhether\sthe\snew\nobject\swill\sbe\sused\sfor\smock-encryption\sor\smock-decryption.
+D 2018-02-26T07:58:39.046
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F Makefile.in a2d2fb8d17c39ab5ec52beb27850b903949080848236923f436156b72a958737
@@ -409,8 +409,8 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3
 F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04
 F ext/userauth/userauth.c 3410be31283abba70255d71fd24734e017a4497f
 F ext/zonefile/README.md df86ef5b4f9aa8b07e1c8124b3f2dcea616927385aad59d525b784f0a06d446c
-F ext/zonefile/zonefile.c eeba1f8a353661998b2e54d499c0fd7241946d48285d1e20fc86ac1c81651b6c
-F ext/zonefile/zonefile1.test 43e10166a74187d997a224c4f199cabfdbf4c17f704759fd37b0fcb8616c26a3
+F ext/zonefile/zonefile.c 4af6b26c047f6510816536e7423cc5fa61b28c9ad77d83bf0648637de9d67441
+F ext/zonefile/zonefile1.test 79ac1a99674b986dab6ce5e8bf342e9585cd7fd02406ea223c969624b93dd46f
 F ext/zonefile/zonefileenc.test 10e770105edeff6a05df6be8db5481eaa8fcda2422ec5446ad21b34ed70d02d7
 F ext/zonefile/zonefilefault.test 6f0b10364972981380de65e8665b7a8f882a70ec7ee188695fe199f2851e180e
 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x
@@ -1712,7 +1712,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 9a99afafa3fb9ec4823e5030cb04a685d64942ec04a1154b729dc4c0f313dc4a
-R 6618d746fdec54fbaf0229c804a7cf37
+P 1764ade22b52eba0226ae2e6e837a1b0967023eabd7d50e9f87c5e7042ea2f12
+R c1770a6f91e4d8e969767de9b3f750ba
 U dan
-Z 6cb0aff8f941832f5fc5365c2afb34dd
+Z 4642b01a17023ca2ce0927319db5bcf7
index 6d2999ac4495a3f86418beef730392b70f9e5e80..4aac7ba5f7a4db209ccfe3ee9a41888323882e68 100644 (file)
@@ -1 +1 @@
-1764ade22b52eba0226ae2e6e837a1b0967023eabd7d50e9f87c5e7042ea2f12
\ No newline at end of file
+231832c4cb15862e61dfcc00fba9ab78ca7e2442a0d4aa1a98a191f5f8b4cff3
\ No newline at end of file