@@ -97,13 +97,23 @@ sqlite3mc_config(sqlite3* db, const char* paramName, int newValue)
9797 value = (hasDefaultPrefix ) ? param -> m_default : (hasMinPrefix ) ? param -> m_minValue : (hasMaxPrefix ) ? param -> m_maxValue : param -> m_value ;
9898 if (!hasMinPrefix && !hasMaxPrefix && newValue >= 0 && newValue >= param -> m_minValue && newValue <= param -> m_maxValue )
9999 {
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 )
102103 {
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 ;
104116 }
105- param -> m_value = newValue ;
106- value = newValue ;
107117 }
108118 if (db != NULL )
109119 {
@@ -758,27 +768,29 @@ sqlite3mcFileControlPragma(sqlite3* db, const char* zDbName, int op, void* pArg)
758768 pragmaValue = ((char * * ) pArg )[2 ];
759769 if (sqlite3StrICmp (pragmaName , "cipher" ) == 0 )
760770 {
761- int j = -1 ;
771+ int cipherId = -1 ;
762772 if (pragmaValue != NULL )
763773 {
774+ int j = 1 ;
764775 /* Try to locate the cipher name */
765776 for (j = 1 ; strlen (globalCodecParameterTable [j ].m_name ) > 0 ; ++ j )
766777 {
767778 if (sqlite3_stricmp (pragmaValue , globalCodecParameterTable [j ].m_name ) == 0 ) break ;
768779 }
780+ cipherId = (strlen (globalCodecParameterTable [j ].m_name ) > 0 ) ? globalCodecParameterTable [j ].m_id : CODEC_TYPE_UNKNOWN ;
769781 }
770782
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 ))
773785 {
774786 int value ;
775787 if (configDefault )
776788 {
777- value = sqlite3mc_config (db , "default:cipher" , j );
789+ value = sqlite3mc_config (db , "default:cipher" , cipherId );
778790 }
779791 else
780792 {
781- value = sqlite3mc_config (db , "cipher" , j );
793+ value = sqlite3mc_config (db , "cipher" , cipherId );
782794 }
783795 rc = SQLITE_OK ;
784796 ((char * * )pArg )[0 ] = sqlite3_mprintf ("%s" , codecDescriptorTable [value - 1 ]-> m_name );
0 commit comments