Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dereference of opaque sqlite3_context type. #1501

Open
levydsa opened this issue Jun 25, 2024 · 0 comments
Open

Dereference of opaque sqlite3_context type. #1501

levydsa opened this issue Jun 25, 2024 · 0 comments

Comments

@levydsa
Copy link
Contributor

levydsa commented Jun 25, 2024

sqlite3_context is a opaque type when used out of vdbe.c and should not be dereferenced, since it's definition is incomplete at comptime.

// TODO: figure out more illegal combinations to validate
rc = renameParseSql(&sPostAlterParse, zDb, db, (const char *)sqlite3_value_text((sqlite3_value *)context->pOut), bTemp);
Table *pNewTab = sPostAlterParse.pNewTable;

This goes under the radar because of the "amalgamation" aproach to build the source. (Yet another drawback #1028 (comment)). The solution is to #include "vdbeInt.h", but this is very smelly. If the type should be known by the whole source, better add it to sqlite3Int.h.

The func.c includes vdbeInt.h already.

#include "vdbeInt.h"

Here is some docs:

/*
** The "context" argument for an installable function. A pointer to an
** instance of this structure is the first argument to the routines used
** implement the SQL functions.
**
** There is a typedef for this structure in sqlite.h. So all routines,
** even the public interface to SQLite, can use a pointer to this structure.
** But this file is the only place where the internal details of this
** structure are known.
**
** This structure is defined inside of vdbeInt.h because it uses substructures
** (Mem) which are only defined there.
*/
struct sqlite3_context {
Mem *pOut; /* The return value is stored here */
FuncDef *pFunc; /* Pointer to function information */
Mem *pMem; /* Memory cell used to store aggregate context */
Vdbe *pVdbe; /* The VM that owns this context */
int iOp; /* Instruction number of OP_Function */
int isError; /* Error code returned by the function. */
u8 enc; /* Encoding to use for results */
u8 skipFlag; /* Skip accumulator loading if true */
u8 argc; /* Number of arguments */
sqlite3_value *argv[1]; /* Argument set */
};

levydsa added a commit to levydsa/libsql that referenced this issue Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant