/ Check-in [c13264d5ef]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Improve the sqlite3_result_pointer() interface so that it cannot be faked using sqlite3_result_null() and sqlite3_result_subtype().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | pointer-types
Files: files | file ages | folders
SHA3-256: c13264d5ef0470fb24e09f7bc12f19be3b77eab06d41f55607b38dddb532a132
User & Date: drh 2017-07-17 11:39:46
Context
2017-07-17
12:27
Add the pointer-type parameter to sqlite3_bind_pointer(), sqlite3_result_pointer(), and sqlite3_value_pointer(). The pointer type is a static string that must match (according to strcmp()) or else the pointer is passed as a NULL. This is a security measure to prevent crossing pointers between different extensions. check-in: e1196567fc user: drh tags: branch-3.20
11:39
Improve the sqlite3_result_pointer() interface so that it cannot be faked using sqlite3_result_null() and sqlite3_result_subtype(). Closed-Leaf check-in: c13264d5ef user: drh tags: pointer-types
00:40
Add an experimental "pointer type" parameter to sqlite3_bind_pointer(), sqlite3_result_pointer(), and sqlite3_value_pointer(). The pointer type is a string that must compare equal using strcmp() or else the pointer comes through as a NULL. check-in: 211cce04e9 user: drh tags: pointer-types
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/vdbeapi.c.

197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
}
unsigned int sqlite3_value_subtype(sqlite3_value *pVal){
  Mem *pMem = (Mem*)pVal;
  return ((pMem->flags & MEM_Subtype) ? pMem->eSubtype : 0);
}
void *sqlite3_value_pointer(sqlite3_value *pVal, const char *zPType){
  Mem *p = (Mem*)pVal;
  if( (p->flags & MEM_TypeMask)==(MEM_Null|MEM_Subtype)
   && p->eSubtype=='p'
   && zPType!=0
   && strcmp(p->z, zPType)==0
  ){
    return p->u.pPtr;
  }else{
    return 0;







|







197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
}
unsigned int sqlite3_value_subtype(sqlite3_value *pVal){
  Mem *pMem = (Mem*)pVal;
  return ((pMem->flags & MEM_Subtype) ? pMem->eSubtype : 0);
}
void *sqlite3_value_pointer(sqlite3_value *pVal, const char *zPType){
  Mem *p = (Mem*)pVal;
  if( p->flags==(MEM_Null|MEM_Subtype|MEM_Term|MEM_Static)
   && p->eSubtype=='p'
   && zPType!=0
   && strcmp(p->z, zPType)==0
  ){
    return p->u.pPtr;
  }else{
    return 0;

Changes to src/vdbemem.c.

708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
/*
** Set the value stored in *pMem should already be a NULL.
** Also store a pointer to go with it.
*/
void sqlite3VdbeMemSetPointer(Mem *pMem, void *pPtr, const char *zPType){
  assert( pMem->flags==MEM_Null );
  if( zPType ){
    pMem->flags = MEM_Null|MEM_Subtype;
    pMem->u.pPtr = pPtr;
    pMem->eSubtype = 'p';
    pMem->z = (char*)zPType;
  }
}

#ifndef SQLITE_OMIT_FLOATING_POINT







|







708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
/*
** Set the value stored in *pMem should already be a NULL.
** Also store a pointer to go with it.
*/
void sqlite3VdbeMemSetPointer(Mem *pMem, void *pPtr, const char *zPType){
  assert( pMem->flags==MEM_Null );
  if( zPType ){
    pMem->flags = MEM_Null|MEM_Subtype|MEM_Term|MEM_Static;
    pMem->u.pPtr = pPtr;
    pMem->eSubtype = 'p';
    pMem->z = (char*)zPType;
  }
}

#ifndef SQLITE_OMIT_FLOATING_POINT