Skip to content

sqlcipher_export_init declared with the wrong type #590

Closed

Description

@mmaxim

sqlcipher_export_init is registered as an sqlite "auto extension" function, of which the intended type is the following:

typedef int (*sqlite3_loadext_entry)(
  sqlite3 *db,                       /* Handle to the database. */
  char **pzErrMsg,                   /* Used to set error string on failure. */
  const sqlite3_api_routines *pThunk /* Extension API function pointers. */
);

However,sqlcipher_export_init is declared as:

static int sqlcipher_export_init(sqlite3* db, const char** errmsg, const struct sqlite3_api_routines* api) 

Note the second parameter is const char* instead of char*. We came across this problem because UBSAN ("undefined behavior sanitizer") flags this as a mismatched function call at runtime. I don't think it has any practical downside, since errmsg is unused in sqlcipher_export_init, but it is worth fixing so the sanitizer doesn't complain.

Activity

  1. mmaxim commented on Mar 19, 2026

    @mmaxim
    Author

    Also, just to follow up, the reason this doesn't throw a compiler error is because sqlite stores these functions as some generic pointer type, (void)(*)(void), and then casts back to sqlite3_loadext_entry before it invokes it. Because of this behavior, the mismatch gets lost by the compiler.

  2. sjlombardo commented on Mar 19, 2026

    @sjlombardo
    Member

    Hello @mmaxim - thanks for reporting this issue. It will be resolved in the next release of SQLCipher. We'll leave this issue open until then.

    This highlights a discrepancy in SQLite's Automatically Load Statically Linked Extensions documentation which calls for the entry point to be:

       int xEntryPoint(
         sqlite3 *db,
         const char **pzErrMsg,
         const struct sqlite3_api_routines *pThunk
       );
    

    You might also consider reporting the difference on the SQLite forum to have the documentation corrected in the official documentation.

  3. sjlombardo commented on Apr 28, 2026

    @sjlombardo
    Member

    Hello @mmaxim this should be resolved in 4.15.0. Thanks again for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions