@@ -97,13 +97,23 @@ sqlite3mc_config(sqlite3* db, const char* paramName, int newValue)
97
97
value = (hasDefaultPrefix ) ? param -> m_default : (hasMinPrefix ) ? param -> m_minValue : (hasMaxPrefix ) ? param -> m_maxValue : param -> m_value ;
98
98
if (!hasMinPrefix && !hasMaxPrefix && newValue >= 0 && newValue >= param -> m_minValue && newValue <= param -> m_maxValue )
99
99
{
100
- /* Do not allow to change the default value for parameter "hmac_check" */
101
- if (hasDefaultPrefix && (sqlite3_stricmp (paramName , "hmac_check" ) != 0 ))
100
+ int allowChange = 1 ;
101
+ /* Allow cipher change only if new cipher is actually available */
102
+ if (sqlite3_stricmp (paramName , "cipher" ) == 0 )
102
103
{
103
- param -> m_default = newValue ;
104
+ allowChange = (codecDescriptorTable [newValue - 1 ] != & mcDummyDescriptor );
105
+ }
106
+
107
+ if (allowChange )
108
+ {
109
+ /* Do not allow to change the default value for parameter "hmac_check" */
110
+ if (hasDefaultPrefix && (sqlite3_stricmp (paramName , "hmac_check" ) != 0 ))
111
+ {
112
+ param -> m_default = newValue ;
113
+ }
114
+ param -> m_value = newValue ;
115
+ value = newValue ;
104
116
}
105
- param -> m_value = newValue ;
106
- value = newValue ;
107
117
}
108
118
if (db != NULL )
109
119
{
@@ -758,27 +768,29 @@ sqlite3mcFileControlPragma(sqlite3* db, const char* zDbName, int op, void* pArg)
758
768
pragmaValue = ((char * * ) pArg )[2 ];
759
769
if (sqlite3StrICmp (pragmaName , "cipher" ) == 0 )
760
770
{
761
- int j = -1 ;
771
+ int cipherId = -1 ;
762
772
if (pragmaValue != NULL )
763
773
{
774
+ int j = 1 ;
764
775
/* Try to locate the cipher name */
765
776
for (j = 1 ; strlen (globalCodecParameterTable [j ].m_name ) > 0 ; ++ j )
766
777
{
767
778
if (sqlite3_stricmp (pragmaValue , globalCodecParameterTable [j ].m_name ) == 0 ) break ;
768
779
}
780
+ cipherId = (strlen (globalCodecParameterTable [j ].m_name ) > 0 ) ? globalCodecParameterTable [j ].m_id : CODEC_TYPE_UNKNOWN ;
769
781
}
770
782
771
- /* j is the index of the cipher name, if found */
772
- if ((j == -1 ) || (strlen ( globalCodecParameterTable [ j ]. m_name ) > 0 ))
783
+ /* cipherId is the numeric id of the cipher name, if found */
784
+ if ((cipherId == -1 ) || (cipherId > 0 && cipherId <= CODEC_TYPE_MAX ))
773
785
{
774
786
int value ;
775
787
if (configDefault )
776
788
{
777
- value = sqlite3mc_config (db , "default:cipher" , j );
789
+ value = sqlite3mc_config (db , "default:cipher" , cipherId );
778
790
}
779
791
else
780
792
{
781
- value = sqlite3mc_config (db , "cipher" , j );
793
+ value = sqlite3mc_config (db , "cipher" , cipherId );
782
794
}
783
795
rc = SQLITE_OK ;
784
796
((char * * )pArg )[0 ] = sqlite3_mprintf ("%s" , codecDescriptorTable [value - 1 ]-> m_name );
0 commit comments