project
stringclasses 633
values | commit_id
stringlengths 7
81
| target
int64 0
1
| func
stringlengths 5
484k
| cwe
stringclasses 131
values | big_vul_idx
float64 0
189k
⌀ | idx
int64 0
522k
| hash
stringlengths 34
39
| size
float64 1
24k
⌀ | message
stringlengths 0
11.5k
⌀ | dataset
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC dbEvalCallCmd( DbEvalContext *p, Jsi_Interp *interp, Jsi_RC result)
{
int cnt = 0;
Jsi_RC rc = result;
Jsi_Value *varg1;
Jsi_Obj *argso;
char **apColName = NULL;
int *apColType = NULL;
if (p->jdb->debug & TMODE_EVAL)
JSI_DBQUERY_PRINTF( "DEBUG: eval\n");
while( (rc==JSI_OK) && JSI_OK==(rc = dbEvalStep(p)) ) {
int i;
int nCol;
cnt++;
dbEvalRowInfo(p, &nCol, &apColName, &apColType);
if (nCol<=0)
continue;
if (Jsi_ValueIsNull(interp,p->tocall))
continue;
/* Single object containing sql result members. */
varg1 = Jsi_ValueMakeObject(interp, NULL, argso = Jsi_ObjNew(interp));
for(i=0; i<nCol; i++) {
Jsi_Value *nnv = dbEvalSetColumnValue(p, i, NULL);
Jsi_ObjInsert(interp, argso, apColName[i], nnv, 0);
}
Jsi_IncrRefCount(interp, varg1);
bool rb = Jsi_FunctionInvokeBool(interp, p->tocall, varg1);
Jsi_DecrRefCount(interp, varg1);
if (Jsi_InterpGone(interp))
return JSI_ERROR;
if (rb)
break;
}
//dbEvalFinalize(p);
if( rc==JSI_OK || rc==JSI_BREAK ) {
//Jsi_ResetResult(interp);
rc = JSI_OK;
}
return rc;
}
|
CWE-120
| null | 520,786 |
298751573126045757082173918053120441077
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
const char* jsi_GetDirective(Jsi_Interp *interp, Jsi_OpCodes *ops, const char *str) {
if (!ops) return NULL;
if (!ops->code_len) return NULL;
if (ops->codes[0].op != OP_PUSHSTR || !ops->codes[0].data) return NULL;
if (Jsi_Strncmp((char*)ops->codes[0].data, str, Jsi_Strlen(str))) return NULL;
return (char*)ops->codes[0].data;
}
|
CWE-120
| null | 520,787 |
135934457576762661622070654072659545994
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_Value* Jsi_ValueMakeObject(Jsi_Interp *interp, Jsi_Value **vPtr, Jsi_Obj *o) {
Jsi_Value *v = (vPtr?*vPtr:NULL);
if (v && v->vt == JSI_VT_OBJECT && o == v->d.obj)
return v;
if (v)
Jsi_ValueReset(interp, vPtr);
else
v = Jsi_ValueNew(interp);
//Jsi_IncrRefCount(interp, v);
if (!o)
o = Jsi_ObjNewType(interp, JSI_OT_OBJECT);
v->vt = JSI_VT_OBJECT;
v->d.obj = o;
Jsi_ObjIncrRefCount(interp,v->d.obj);
return v;
}
|
CWE-120
| null | 520,788 |
37816788953741321057738719560805978645
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_TreeEntry *StringPtrCreate( Jsi_Tree *treePtr, const void *key, bool *newPtr)
{
return OneWordCreate(treePtr, key, newPtr);
}
|
CWE-120
| null | 520,789 |
299582198817126051271233651104137650396
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_Number Jsi_ValueToNumberInt(Jsi_Interp *interp, Jsi_Value *v, int isInt)
{
char *endPtr = NULL, *sptr;
Jsi_Number a = 0;
switch(v->vt) {
case JSI_VT_BOOL:
a = (Jsi_Number)(v->d.val ? 1.0: 0);
break;
case JSI_VT_NULL:
a = 0;
break;
case JSI_VT_OBJECT: {
Jsi_Obj *obj = v->d.obj;
switch(obj->ot) {
case JSI_OT_BOOL:
a = (Jsi_Number)(obj->d.val ? 1.0: 0);
break;
case JSI_OT_NUMBER:
a = obj->d.num;
break;
case JSI_OT_STRING:
sptr = obj->d.s.str;
goto donum;
break;
default:
a = 0;
break;
}
break;
}
case JSI_VT_UNDEF:
a = Jsi_NumberNaN();
break;
case JSI_VT_NUMBER:
a = v->d.num;
break;
case JSI_VT_STRING:
sptr = v->d.s.str;
donum:
if (!isInt) {
a = strtod(sptr, &endPtr);
if (endPtr && *endPtr) {
a = interp->NaNValue->d.num;
}
} else {
a = (Jsi_Number)strtol(sptr, &endPtr, 0);
if (!isdigit(*sptr))
a = interp->NaNValue->d.num;
}
break;
default:
Jsi_LogBug("Convert a unknown type: 0x%x to number", v->vt);
break;
}
if (isInt && Jsi_NumberIsNormal(a))
a = (Jsi_Number)((int64_t)(a));
return a;
}
|
CWE-120
| null | 520,790 |
322929736525924831359094708338836676304
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static SqlFunc *dbFindSqlFunc(Jsi_Db *jdb, const char *zName) {
SqlFunc *p, *pNew;
int i;
pNew = (SqlFunc*)Jsi_Calloc(1, sizeof(*pNew) + Jsi_Strlen(zName) + 1 );
pNew->sig = SQLITE_SIG_FUNC;
pNew->zName = (char*)&pNew[1];
for(i=0; zName[i]; i++) {
pNew->zName[i] = tolower(zName[i]);
}
pNew->zName[i] = 0;
for(p=jdb->pFunc; p; p=p->pNext) {
if( Jsi_Strcmp(p->zName, pNew->zName)==0 ) {
Jsi_Free((char*)pNew);
return p;
}
}
pNew->interp = jdb->interp;
pNew->pScript = 0;
Jsi_DSInit(&pNew->dScript);
pNew->pNext = jdb->pFunc;
jdb->pFunc = pNew;
return pNew;
}
|
CWE-120
| null | 520,791 |
248772193579753768094468177534860623594
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_Value* Jsi_ValueMakeArrayObject(Jsi_Interp *interp, Jsi_Value **vPtr, Jsi_Obj *o) {
Jsi_Value *v = (vPtr?*vPtr:NULL);
if (!o)
o = Jsi_ObjNewType(interp, JSI_OT_ARRAY);
if (!v)
v = Jsi_ValueNew(interp);
else {
if (v->vt == JSI_VT_OBJECT && o == v->d.obj) {
if (!o->isarrlist) {
if (o->tree)
Jsi_TreeDelete( o->tree);
o->tree = NULL;
o->__proto__ = interp->Array_prototype;
o->isarrlist = 1;
}
return v;
}
Jsi_ValueReset(interp, vPtr);
}
v->vt = JSI_VT_OBJECT;
v->d.obj = o;
o->ot = JSI_OT_OBJECT;
o->__proto__ = interp->Array_prototype;
o->isarrlist = 1;
Jsi_ObjArraySizer(interp, o, 0);
Jsi_ObjIncrRefCount(interp,v->d.obj);
return v;
}
|
CWE-120
| null | 520,792 |
331280275782198739715476041587823833092
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static int jsi_FSStatProc(Jsi_Interp *interp, Jsi_Value* path, Jsi_StatBuf *buf) {
const char *pathPtr = Jsi_ValueToString(interp, path, NULL);
Jsi_DString dStr = {};
if (*pathPtr == '~')
pathPtr = jsi_TildePath(interp, pathPtr, &dStr);
int rc = stat(pathPtr, buf);
Jsi_DSFree(&dStr);
return rc;
}
|
CWE-120
| null | 520,793 |
184516633927837136826726401386887334176
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC WebSocketConstructor(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
if (Jsi_InterpAccess(interp, NULL, JSI_INTACCESS_NETWORK ) != JSI_OK)
return Jsi_LogError("WebSocket disallowed by Interp.noNetwork option");
jsi_wsCmdObj *cmdPtr;
Jsi_Value *toacc = NULL;
Jsi_Value *arg = Jsi_ValueArrayIndex(interp, args, 0);
cmdPtr = (jsi_wsCmdObj*)Jsi_Calloc(1, sizeof(*cmdPtr));
cmdPtr->sig = JWS_SIG_OBJ;
cmdPtr->_ = &wsObjCmd;
cmdPtr->_->newCnt++;
cmdPtr->_->activeCnt++;
cmdPtr->port = 8080;
cmdPtr->formParams = jsi_wsparam_str;
cmdPtr->maxUpload = 100000;
cmdPtr->interp = interp;
cmdPtr->ietf_version = -1;
cmdPtr->bufferPwr2 = 0;
cmdPtr->ws_gid = -1;
cmdPtr->ws_uid = -1;
cmdPtr->startTime = time(NULL);
cmdPtr->hasOpts = 1;
cmdPtr->includeFile = "include.shtml";
cmdPtr->jsiFnPattern = "jsig*.js";
if ((arg != NULL && !Jsi_ValueIsNull(interp,arg))
&& Jsi_OptionsProcess(interp, WSOptions, cmdPtr, arg, 0) < 0) {
bail:
jsi_wswebsocketObjFree(interp, cmdPtr);
return JSI_ERROR;
}
if (!cmdPtr->udata) {
cmdPtr->udata = Jsi_ValueNewObj(interp, NULL);
Jsi_IncrRefCount(interp, cmdPtr->udata);
}
Jsi_PathNormalize(interp, &cmdPtr->rootdir);
if (cmdPtr->headers && (Jsi_ValueGetLength(interp, cmdPtr->headers)%2)) {
Jsi_LogError("Odd header length");
goto bail;
}
const char *up = cmdPtr->urlPrefix, *ur = cmdPtr->urlRedirect;
if (up && ur && Jsi_Strncmp(ur, up, Jsi_Strlen(up))) {
Jsi_LogError("urlRedirect does not start with urlPrefix");
goto bail;
}
const char* subprot = (cmdPtr->protocol&&cmdPtr->protocol[0]?cmdPtr->protocol:"ws");
if (cmdPtr->protocol && !cmdPtr->protocol[0])
Jsi_LogWarn("empty protocol string: forcing to 'ws'");
cmdPtr->protocols[JWS_PROTOCOL_HTTP].name="http-only";
cmdPtr->protocols[JWS_PROTOCOL_HTTP].callback=jsi_wscallback_http;
cmdPtr->protocols[JWS_PROTOCOL_HTTP].per_session_data_size=sizeof(jsi_wsUser);
cmdPtr->protocols[JWS_PROTOCOL_WEBSOCK].name=subprot;
cmdPtr->protocols[JWS_PROTOCOL_WEBSOCK].callback=jsi_wscallback_websock;
cmdPtr->protocols[JWS_PROTOCOL_WEBSOCK].per_session_data_size=sizeof(jsi_wsUser);
if (cmdPtr->bufferPwr2 == 0)
cmdPtr->bufferPwr2 = 16;
if (cmdPtr->bufferPwr2>0) {
if (cmdPtr->bufferPwr2>20) {
Jsi_LogError("bufferPwr2 not in 0-20: %d", cmdPtr->bufferPwr2);
goto bail;
}
cmdPtr->protocols[JWS_PROTOCOL_WEBSOCK].rx_buffer_size=(1<<cmdPtr->bufferPwr2);
}
cmdPtr->pssTable = Jsi_HashNew(interp, JSI_KEYS_ONEWORD, jsi_wsfreePss);
if (cmdPtr->onModify)
cmdPtr->fileHash = Jsi_HashNew(interp, JSI_KEYS_STRING, jsi_wsfreeFile);
cmdPtr->info.port = (cmdPtr->client ? CONTEXT_PORT_NO_LISTEN : cmdPtr->port);
cmdPtr->info.user = cmdPtr;
cmdPtr->info.iface = cmdPtr->interface ? Jsi_ValueString(interp, cmdPtr->interface, NULL) : NULL;
if (cmdPtr->local && !cmdPtr->info.iface)
cmdPtr->info.iface = "lo";
#ifdef __WIN32
cmdPtr->info.iface = NULL;
#endif
cmdPtr->info.protocols = cmdPtr->protocols;
if (!cmdPtr->noCompress)
cmdPtr->info.extensions = jsi_lws_exts;
cmdPtr->info.ssl_cert_filepath = cmdPtr->ssl_cert_filepath;
cmdPtr->info.ssl_private_key_filepath = cmdPtr->ssl_private_key_filepath;
cmdPtr->info.gid = cmdPtr->ws_gid;
cmdPtr->info.uid = cmdPtr->ws_uid;
cmdPtr->opts = LWS_SERVER_OPTION_SKIP_SERVER_CANONICAL_NAME|LWS_SERVER_OPTION_VALIDATE_UTF8;
cmdPtr->info.options = cmdPtr->opts;
cmdPtr->info.max_http_header_pool = 16;
cmdPtr->info.timeout_secs = 5;
cmdPtr->info.ssl_cipher_list = "ECDHE-ECDSA-AES256-GCM-SHA384:"
"ECDHE-RSA-AES256-GCM-SHA384:"
"DHE-RSA-AES256-GCM-SHA384:"
"ECDHE-RSA-AES256-SHA384:"
"HIGH:!aNULL:!eNULL:!EXPORT:"
"!DES:!MD5:!PSK:!RC4:!HMAC_SHA1:"
"!SHA1:!DHE-RSA-AES128-GCM-SHA256:"
"!DHE-RSA-AES128-SHA256:"
"!AES128-GCM-SHA256:"
"!AES128-SHA256:"
"!DHE-RSA-AES256-SHA256:"
"!AES256-GCM-SHA384:"
"!AES256-SHA256";
lws_set_log_level(cmdPtr->debug>255?cmdPtr->debug/256:0, NULL);
// TODO: WS2.2 Still leaks a small amount if server port unavailable.
if (!cmdPtr->client)
cmdPtr->info.options |= LWS_SERVER_OPTION_EXPLICIT_VHOSTS;
cmdPtr->context = lws_create_context(&cmdPtr->info);
if (cmdPtr->context == NULL) {
fail:
Jsi_LogError("libwebsocket init failed on port %d (try another port?)", cmdPtr->info.port);
goto bail;
}
if (cmdPtr->info.options & LWS_SERVER_OPTION_EXPLICIT_VHOSTS) {
cmdPtr->info.options &= ~LWS_SERVER_OPTION_EXPLICIT_VHOSTS;
if (!lws_create_vhost(cmdPtr->context, &cmdPtr->info))
goto fail;
}
if (cmdPtr->client) {
struct lws_client_connect_info lci = {};
lci.context = cmdPtr->context;
lci.address = cmdPtr->address ? Jsi_ValueString(cmdPtr->interp, cmdPtr->address, NULL) : "127.0.0.1";
lci.port = cmdPtr->port;
lci.ssl_connection = cmdPtr->use_ssl;
lci.path = Jsi_ValueString(cmdPtr->interp, cmdPtr->rootdir, NULL);
lci.host = cmdPtr->clientHost?cmdPtr->clientHost:lws_canonical_hostname( cmdPtr->context );
lci.origin = cmdPtr->clientOrigin?cmdPtr->clientOrigin:"origin";
lci.protocol = cmdPtr->protocols[JWS_PROTOCOL_WEBSOCK].name;
lci.ietf_version_or_minus_one = cmdPtr->ietf_version;
#if (LWS_LIBRARY_VERSION_MAJOR>1)
if (cmdPtr->post)
lci.method = "POST";
else if (!Jsi_Strcmp(subprot, "get"))
lci.method = "GET";
#endif
if (NULL == lws_client_connect_via_info(&lci))
{
Jsi_LogError("websock connect failed");
jsi_wswebsocketObjFree(interp, cmdPtr);
return JSI_ERROR;
}
} else if (cmdPtr->port == 0) {
// Extract actually used port.
char *cp, cbuf[JSI_BUFSIZ*2];
cbuf[0] = 0;
lws_json_dump_context(cmdPtr->context, cbuf, sizeof(cbuf), 0);
cp = Jsi_Strstr(cbuf, "\"port\":\"");
if (cp)
cmdPtr->port = atoi(cp+8);
}
cmdPtr->event = Jsi_EventNew(interp, jsi_wswebsockUpdate, cmdPtr);
if (Jsi_FunctionIsConstructor(funcPtr)) {
toacc = _this;
} else {
Jsi_Obj *o = Jsi_ObjNew(interp);
Jsi_PrototypeObjSet(interp, "WebSocket", o);
Jsi_ValueMakeObject(interp, ret, o);
toacc = *ret;
}
Jsi_Obj *fobj = Jsi_ValueGetObj(interp, toacc);
if ((cmdPtr->objId = Jsi_UserObjNew(interp, &websockobject, fobj, cmdPtr))<0) {
goto bail;
}
Jsi_UserObjName(interp, toacc, &cmdPtr->cName);
cmdPtr->handlers = Jsi_HashNew(interp, JSI_KEYS_STRING, jsi_wsfreeHandlers);
if (cmdPtr->extHandlers) {
jsi_wsHandlerAdd(interp, cmdPtr, ".jsi", "Jspp", 1);
jsi_wsHandlerAdd(interp, cmdPtr, ".htmli", "Htmlpp", 1);
jsi_wsHandlerAdd(interp, cmdPtr, ".cssi", "Csspp", 1);
}
cmdPtr->fobj = fobj;
#ifdef LWS_LIBRARY_VERSION_NUMBER
Jsi_JSONParseFmt(interp, &cmdPtr->version, "{libVer:\"%s\", hdrVer:\"%s\", hdrNum:%d, pkgVer:%d}",
(char *)lws_get_library_version(), LWS_LIBRARY_VERSION, LWS_LIBRARY_VERSION_NUMBER, jsi_WsPkgVersion);
#endif
return JSI_OK;
}
|
CWE-120
| null | 520,794 |
288218400400159540145654241563755145607
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
bool dbIsAlnumStr(const char *cp)
{
if (!cp || !*cp) return 0;
while (*cp)
if (isalnum(*cp) || *cp == '_')
cp++;
else
return 0;
return 1;
}
|
CWE-120
| null | 520,795 |
38240018258418527722055928093168679385
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC jsi_logic_less(Jsi_Interp* interp, int i1, int i2) {
Jsi_Value *v, *v1 = _jsi_STACK[interp->framePtr->Sp-i1], *v2 = _jsi_STACK[interp->framePtr->Sp-i2], *res = _jsi_TOQ;
int val = 0, l1 = 0, l2 = 0;
bool strict = interp->strict;
Jsi_RC rc = JSI_OK;
rc = _jsi_StrictUChk2(v1, v2);
if (rc != JSI_OK)
return JSI_ERROR;
char *s1 = Jsi_ValueString(interp, v1, &l1);
char *s2 = Jsi_ValueString(interp, v2, &l2);
Jsi_Number n1, n2;
if (s1 || s2) {
char *str;
if (!(s1 && s2)) {
v = (s1 ? v2 : v1);
jsi_ValueToPrimitive(interp, &v);
Jsi_ValueToString(interp, v, NULL);
str = Jsi_ValueString(interp, v, (s1?&l2:&l1));
if (s1) s2 = str; else s1 = str;
}
Assert(l1>=0 && l1<=JSI_MAX_ALLOC_BUF);
Assert(l2>=0 && l2<=JSI_MAX_ALLOC_BUF);
//int mlen = (l1>l2?l1:l2);
val = Jsi_Strcmp(s1, s2);
if (val > 0) val = 0;
else if (val < 0) val = 1;
else val = (l1 < l2);
jsiClearStack(interp,2);
Jsi_ValueMakeBool(interp, &res, val);
} else {
Jsi_ValueToNumber(interp, v1);
Jsi_ValueToNumber(interp, v2);
rc = _jsi_StrictChk2(v1,v2);
if (rc != JSI_OK)
return JSI_ERROR;
n1 = v1->d.num; n2 = v2->d.num;
if (Jsi_NumberIsNaN(n1) || Jsi_NumberIsNaN(n2)) {
jsiClearStack(interp,2);
Jsi_ValueMakeUndef(interp, &res);
} else {
val = (n1 < n2);
jsiClearStack(interp,2);
Jsi_ValueMakeBool(interp, &res, val);
}
}
return JSI_OK;
}
|
CWE-120
| null | 520,796 |
137031274982641498450076560978696330865
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void mdbJsToMyTime(Jsi_Number time, MYSQL_TIME* mtm, int utc)
{
struct tm tm;
time_t tim = (time_t)(time/1000);
if (utc)
gmtime_r(&tim, &tm);
else
localtime_r(&tim, &tm);
mtm->second = tm.tm_sec;
mtm->minute = tm.tm_min;
mtm->hour = tm.tm_hour;
mtm->day = tm.tm_mday;
mtm->month = tm.tm_mon+1;
mtm->year = tm.tm_year + 1900;
Jsi_Number secs = (tim/1000.0);
mtm->second_part = (int)((secs-(int)secs)*1000000);
}
|
CWE-120
| null | 520,797 |
118786602622406071908494695954834547029
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC FilesysPutsCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
UdfGet(udf, _this, funcPtr);
if (!udf->filename) {
Jsi_ValueMakeBool(interp, ret, 0);
return JSI_OK;
}
Jsi_Value *toput = Jsi_ValueArrayIndex(interp, args, 0);
if (!toput) {
Jsi_ValueMakeBool(interp, ret, 0);
return JSI_OK;
}
const char * cp = Jsi_ValueToString(interp, toput, NULL);
if (Jsi_Printf(interp, udf->chan, "%s\n", cp?cp:"") < 0) {
Jsi_ValueMakeBool(interp, ret, 0);
return JSI_OK;
}
Jsi_ValueMakeBool(interp, ret, 1);
return JSI_OK;
}
|
CWE-120
| null | 520,798 |
77352828439828259435209907007069773347
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC WebSocketConfCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
jsi_wsCmdObj *cmdPtr = (jsi_wsCmdObj*)Jsi_UserObjGetData(interp, _this, funcPtr);
if (!cmdPtr)
return Jsi_LogError("Apply in a non-websock object");
Jsi_Value *opts = Jsi_ValueArrayIndex(interp, args, 0);
if (cmdPtr->noConfig && opts && !Jsi_ValueIsString(interp, opts))
return Jsi_LogError("WebSocket conf() is disabled for set");
return Jsi_OptionsConf(interp, WSOptions, cmdPtr, opts, ret, 0);
}
|
CWE-120
| null | 520,799 |
144583805540106502077899280361115445887
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_OptionSpec * jsi_GetCachedOptionSpecs(Jsi_Interp *interp, const Jsi_OptionSpec *staticSpecs)
{
return (Jsi_OptionSpec *)staticSpecs;
}
|
CWE-120
| null | 520,800 |
247603551612087155018219341221521931692
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC jsi_FunctionInvoke(Jsi_Interp *interp, Jsi_Value *tocall, Jsi_Value *args, Jsi_Value **ret, Jsi_Value *_this)
{
if (interp->maxDepth>0 && interp->maxDepth && interp->callDepth>=interp->maxDepth)
return Jsi_LogError("max call depth exceeded");
if (interp->deleting)
return JSI_ERROR;
if (!Jsi_ValueIsFunction(interp, tocall))
return Jsi_LogError("can not execute expression, expression is not a function");
if (!tocall->d.obj->d.fobj) { /* empty function */
return JSI_OK;
}
if (!ret) {
if (!interp->nullFuncRet) {
interp->nullFuncRet = Jsi_ValueNew(interp);
Jsi_IncrRefCount(interp, interp->nullFuncRet);
}
ret = &interp->nullFuncRet;
Jsi_ValueMakeUndef(interp, ret);
}
if (!args) {
if (!interp->nullFuncArg) {
interp->nullFuncArg = Jsi_ValueMakeObject(interp, NULL, Jsi_ObjNewArray(interp, NULL, 0, 0));
Jsi_IncrRefCount(interp, interp->nullFuncArg);
}
args = interp->nullFuncArg;
}
/* func to call */
Jsi_Func *funcPtr = tocall->d.obj->d.fobj->func;
SIGASSERT(funcPtr, FUNC);
/* prepare args */
if (args->vt != JSI_VT_OBJECT || !Jsi_ObjIsArray(interp, args->d.obj))
return Jsi_LogError("argument must be an array");
/* new this */
Jsi_Value *fthis = Jsi_ValueDup(interp, _this ? _this : tocall);
Jsi_Func *prevActive = interp->activeFunc;
Jsi_RC res = jsi_SharedArgs(interp, args, funcPtr, 1);
bool isalloc = 0;
int calltrc = 0;
int tc = interp->traceCall | (funcPtr->pkg?funcPtr->pkg->popts.modConf.traceCall:0);
interp->callDepth++;
if (res == JSI_OK) {
jsi_InitLocalVar(interp, args, funcPtr);
jsi_SetCallee(interp, args, tocall);
isalloc = 1;
Jsi_IncrRefCount(interp, args);
if (funcPtr->type == FC_NORMAL) {
if ((tc&jsi_callTraceFuncs) && funcPtr->name)
calltrc = 1;
} else {
if ((tc&jsi_callTraceCmds) && funcPtr->name)
calltrc = 1;
}
interp->activeFunc = funcPtr;
if (funcPtr->type == FC_NORMAL) {
if (calltrc)
jsi_TraceFuncCall(interp, funcPtr, NULL, fthis, args, NULL, tc);
res = jsi_evalcode(interp->ps, funcPtr, funcPtr->opcodes, tocall->d.obj->d.fobj->scope,
args, fthis, ret);
} else {
if (calltrc)
jsi_TraceFuncCall(interp, funcPtr, NULL, fthis, args, NULL, tc);
res = funcPtr->callback(interp, args, fthis, ret, funcPtr);
}
funcPtr->callCnt++;
}
interp->callDepth--;
if (res == JSI_OK && funcPtr->retType)
res = jsi_ArgTypeCheck(interp, funcPtr->retType, *ret, "returned from", funcPtr->name, 0, funcPtr, 0);
if (calltrc && (tc&jsi_callTraceReturn))
jsi_TraceFuncCall(interp, funcPtr, NULL, fthis, NULL, *ret, tc);
interp->activeFunc = prevActive;
jsi_SharedArgs(interp, args, funcPtr, 0);
if (isalloc)
Jsi_DecrRefCount(interp, args);
Jsi_DecrRefCount(interp, fthis);
return res;
}
|
CWE-120
| null | 520,801 |
86288762746155489233300757689757791252
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void searchSpace(Jsi_TreeSearch *searchPtr, int n)
{
if ((searchPtr->top+n) >= searchPtr->max) {
int i, cnt = (searchPtr->max *= 2);
if (searchPtr->Ptrs == searchPtr->staticPtrs)
searchPtr->Ptrs = (Jsi_TreeEntry**)Jsi_Calloc(cnt, sizeof(Jsi_TreeEntry*));
else
searchPtr->Ptrs = (Jsi_TreeEntry**)Jsi_Realloc(searchPtr->Ptrs, cnt* sizeof(Jsi_TreeEntry*));
for (i=0; i<cnt; i++)
SIGINIT((searchPtr->Ptrs[i]),TREEENTRY);
}
}
|
CWE-120
| null | 520,802 |
173012228088635124405379275325972921637
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
int Jsi_MapEntryDelete (Jsi_MapEntry *entryPtr){
switch (jsi_GetListType(entryPtr)) {
case JSI_MAP_HASH: return Jsi_HashEntryDelete((Jsi_HashEntry*)entryPtr);
case JSI_MAP_TREE: return Jsi_TreeEntryDelete((Jsi_TreeEntry*)entryPtr);
case JSI_MAP_LIST: {
Jsi_ListEntry *lptr = (Jsi_ListEntry*)entryPtr;
Jsi_ListPop(lptr->list, lptr);
Jsi_ListEntryDelete(lptr);
return 1;
}
}
return JSI_OK;
}
|
CWE-120
| null | 520,803 |
273896636600318922876150196027902037208
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void jsiClearThis(Jsi_Interp *interp, int ofs) {
Jsi_Value **vPtr = &_jsi_THISIDX(ofs), *v = *vPtr;
if (!v) return;
#ifndef XX_NEWSTACK
Jsi_ValueReset(interp, vPtr);
#else
if (v->refCnt<=1)
Jsi_ValueReset(interp, vPtr);
else {
Jsi_DecrRefCount(interp, v);
_jsi_THISIDX(ofs) = Jsi_ValueNew1(interp);
}
#endif
}
|
CWE-120
| null | 520,804 |
10064570670294588894963265309010030608
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_RC Jsi_ThisDataSet(Jsi_Interp *interp, Jsi_Value *_this, void *value)
{
bool isNew;
Jsi_HashEntry *hPtr = Jsi_HashEntryNew(interp->thisTbl, _this, &isNew);
if (!hPtr)
return JSI_ERROR;
Jsi_HashValueSet(hPtr, value);
return JSI_OK;
}
|
CWE-120
| null | 520,805 |
139858293588499449752337504050617234243
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
void* Jsi_CurrentThread(void) { return NULL; }
|
CWE-120
| null | 520,806 |
156183963894663364238102833052297295204
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC ValueToCArray(Jsi_Interp *interp, Jsi_OptionSpec* spec, Jsi_Value *inValue, const char *inStr, void *record, Jsi_Wide flags)
{
if (inStr)
return JSI_ERROR;
uchar *s = (uchar*)((char*)record) + spec->offset;
Jsi_OptionSpec *subSpec = spec->init.OPT_CARRAY;
int argc, i, isize, size = spec->arrSize;
if (!subSpec || size<=0 || (isize=subSpec->size)<=0)
goto bail;
isize = isize/size;
if (!Jsi_ValueIsArray(interp, inValue))
return Jsi_LogError("expected array");
argc = Jsi_ValueGetLength(interp, inValue);
if (argc != size)
return Jsi_LogError("array length %d was not %d", argc, size);
for (i = 0; i<size; i++) {
Jsi_Value *v = Jsi_ValueArrayIndex(interp, inValue, i);
if (Jsi_OptionsSet(interp, subSpec, (void*)s, subSpec->name, v, 0) != JSI_OK)
return JSI_ERROR;
s += isize;
}
return JSI_OK;
bail:
return Jsi_LogError("bad config");
}
|
CWE-120
| null | 520,807 |
306774909937241888638745519065140723127
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
void jsi_ScopeStrsFree(Jsi_Interp *interp, Jsi_ScopeStrs *ss)
{
if (!ss) return;
int i;
for (i=0; i<ss->count; i++)
if (ss->args[i].defValue)
Jsi_DecrRefCount(interp, ss->args[i].defValue);
if (ss->args)
Jsi_Free(ss->args);
Jsi_Free(ss);
}
|
CWE-120
| null | 520,808 |
317627985253667250523096642201766775997
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void MutexUnlock(Jsi_Mutex* mtx) { LeaveCriticalSection(&mtx->mtx); }
|
CWE-120
| null | 520,809 |
233090936794404694116425412464121759539
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_OptionsFind(Jsi_Interp *interp, Jsi_OptionSpec *specs, const char *name, Jsi_Wide flags)
{
Jsi_OptionSpec *specPtr;
char c; /* First character of current argument. */
Jsi_OptionSpec *matchPtr; /* Matching spec, or NULL. */
size_t length;
const char *matStr = NULL;
if (name == NULL) {
Jsi_LogError("Null name for option");
return NULL;
}
c = name[0];
length = Jsi_Strlen(name);
matchPtr = NULL;
for (specPtr = specs; specPtr->id>=JSI_OPTION_BOOL && specPtr->id < JSI_OPTION_END && specPtr->name; specPtr++) {
if ((specPtr->name[0] != c)
|| (Jsi_Strncmp(specPtr->name, name, length) != 0)) {
continue;
}
if (specPtr->name[length] == 0) {
return specPtr; /* Stop on a perfect match. */
}
if (matchPtr != NULL) {
Jsi_LogError("ambiguous option \"%s\" matches both \"%s\" and \"%s\"", name, matStr, specPtr->name);
return (Jsi_OptionSpec *) NULL;
}
matchPtr = specPtr;
matStr = specPtr->name;
}
if (matchPtr == NULL) {
Jsi_DString dStr = {};
Jsi_DSAppend(&dStr, "unknown option \"", name, "\" not one of: ", NULL);
for (specPtr = specs; specPtr->id>=JSI_OPTION_BOOL && specPtr->id < JSI_OPTION_END && specPtr->name; specPtr++) {
if (specPtr->name == NULL) {
break;
}
if (name[0] != '?' || _JSICASTINT(specPtr->id) < 0 || specPtr->id >= JSI_OPTION_END) {
Jsi_DSAppend(&dStr, specPtr->name, " ", NULL);
} else {
Jsi_DSAppend(&dStr, "?", specPtr->name, " <", jsi_OptTypeInfo[specPtr->id].idName, ">? ", NULL);
}
}
assert(specPtr->id == JSI_OPTION_END);
Jsi_LogError("%s", Jsi_DSValue(&dStr));
Jsi_DSFree(&dStr);
return (Jsi_OptionSpec *) NULL;
}
return matchPtr;
}
|
CWE-120
| null | 520,810 |
20789942039766079872453458218715901910
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_TreeEntry *searchAdd(Jsi_TreeSearch *searchPtr, Jsi_TreeEntry *hPtr)
{
int order = (searchPtr->flags & JSI_TREE_ORDER_MASK);
searchSpace(searchPtr, 2);
switch (order) {
case JSI_TREE_ORDER_LEVEL:
if (hPtr) {
if (hPtr->right)
searchPtr->Ptrs[searchPtr->top++] = hPtr->right;
if (hPtr->left)
searchPtr->Ptrs[searchPtr->top++] = hPtr->left;
return hPtr;
}
if (searchPtr->top<=0)
return NULL;
hPtr = searchPtr->Ptrs[0];
searchPtr->top--;
if (searchPtr->top > 0) {
/* Not very efficient way to implement a queue, but works for now. */
memmove(searchPtr->Ptrs, searchPtr->Ptrs+1, sizeof(Jsi_TreeEntry*)*searchPtr->top);
}
if (hPtr->right)
searchPtr->Ptrs[searchPtr->top++] = hPtr->right;
if (hPtr->left)
searchPtr->Ptrs[searchPtr->top++] = hPtr->left;
return hPtr;
break;
case JSI_TREE_ORDER_POST:
if (hPtr)
searchPtr->Ptrs[searchPtr->top++] = searchPtr->current = hPtr;
while (searchPtr->top>0) {
hPtr = searchPtr->Ptrs[searchPtr->top-1];
if (hPtr->right == searchPtr->current || hPtr->left == searchPtr->current ||
(hPtr->left == NULL && hPtr->right == NULL)) {
searchPtr->top--;
searchPtr->current = hPtr;
return hPtr;
} else {
searchSpace(searchPtr, 2);
if (hPtr->left)
searchPtr->Ptrs[searchPtr->top++] = hPtr->left;
if (hPtr->right)
searchPtr->Ptrs[searchPtr->top++] = hPtr->right;
}
}
return NULL;
break;
case JSI_TREE_ORDER_PRE:
if (!hPtr) {
if (searchPtr->top<=0) return NULL;
hPtr = searchPtr->Ptrs[--searchPtr->top];
}
searchPtr->Ptrs[searchPtr->top++] = hPtr;
if (hPtr->left) searchPtr->Ptrs[searchPtr->top++] = hPtr->left;
if (hPtr->right) searchPtr->Ptrs[searchPtr->top++] = hPtr->right;
break;
case JSI_TREE_ORDER_IN:
while (1) {
searchSpace(searchPtr, 2);
if (searchPtr->current) {
searchPtr->Ptrs[searchPtr->top++] = searchPtr->current;
searchPtr->current = searchPtr->current->right;
} else {
if (searchPtr->top<=0)
return NULL;
hPtr = searchPtr->Ptrs[--searchPtr->top] ;
searchPtr->current = hPtr->left;
return hPtr;
}
}
break;
default:
if (hPtr) {
Jsi_Interp *interp = hPtr->treePtr->opts.interp;
JSI_NOTUSED(interp);
Jsi_LogError("Invalid order: %d", order);
}
}
return searchPtr->Ptrs[--searchPtr->top];
}
|
CWE-120
| null | 520,811 |
138497403479905767722095598564448758305
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
jsi_SetOption_(Jsi_Interp *interp, Jsi_OptionSpec *specPtr, const char *string /*UNUSED*/, void* rec, Jsi_Value *argValue, Jsi_Wide flags, bool isSafe)
{
Jsi_Wide wcount = 0;
bool bn;
Jsi_Number nv;
bool isIncr = (flags & JSI_OPTS_INCR);
const char *expType = NULL;
char *record = (char*)rec, *ptr = record + specPtr->offset;
Jsi_OptionCustom* cust = NULL;
const char *emsg = NULL, *epre = "";
if (specPtr->id<JSI_OPTION_BOOL || specPtr->id>=JSI_OPTION_END)
return Jsi_LogBug("unknown option id \"%d\" for \"%s\"", specPtr->id, specPtr->name);
if (specPtr->custom && specPtr->id == JSI_OPTION_CUSTOM) {
cust = Jsi_OptionCustomBuiltin(specPtr->custom);
if (cust && cust->parseProc) {
int lastErrCnt = interp->logErrorCnt;
Jsi_OptionSpec *oep = interp->parseMsgSpec;
interp->parseMsgSpec = specPtr;
Jsi_RC rc = (*cust->parseProc)(interp, specPtr, argValue, NULL, record, flags);
if (rc != JSI_OK) {
if (!interp->csc || lastErrCnt == interp->logErrorCnt)
Jsi_LogError("invalid value");
interp->parseMsgSpec = oep;
return JSI_ERROR;
}
interp->parseMsgSpec = oep;
} else
return Jsi_LogBug("missing or bad custom for \"%s\"", specPtr->name);
goto done;
}
switch (specPtr->id) {
case JSI_OPTION_CUSTOM:
if (!specPtr->custom)
return Jsi_LogBug("missing or custom for \"%s\"", specPtr->name);
case JSI_OPTION_BOOL: {
if (!argValue)
*(char*)ptr = 0;
else if (!Jsi_ValueIsBoolean(interp, argValue))
goto bail;
Jsi_GetBoolFromValue(interp, argValue, &bn);
*(char*)ptr = bn;
break;
}
case JSI_OPTION_INT:
case JSI_OPTION_UINT:
case JSI_OPTION_LONG:
case JSI_OPTION_INTPTR_T:
case JSI_OPTION_UINTPTR_T:
case JSI_OPTION_SIZE_T:
case JSI_OPTION_SSIZE_T:
case JSI_OPTION_ULONG:
case JSI_OPTION_SHORT:
case JSI_OPTION_USHORT:
case JSI_OPTION_UINT64:
case JSI_OPTION_INT64:
case JSI_OPTION_INT8:
case JSI_OPTION_UINT8:
case JSI_OPTION_INT16:
case JSI_OPTION_UINT16:
case JSI_OPTION_INT32:
case JSI_OPTION_UINT32:
wcount = 0;
if (argValue) {
if (!Jsi_ValueIsNumber(interp, argValue))
goto bail;
if (Jsi_GetWideFromValue(interp, argValue, &wcount) != JSI_OK) {
return JSI_ERROR;
}
}
switch (specPtr->id) {
#define _JSI_OPTSETTYP(typ, n, ptr) if (isIncr) n += *((typ *)ptr); \
if (isIncr || ((Jsi_Wide)(typ)(n)) == (n)) interp->cdataIncrVal = *((typ *)ptr) = (typ)(n); else expType = #typ;
case JSI_OPTION_INT: _JSI_OPTSETTYP(int, wcount, ptr); break;
case JSI_OPTION_UINT: _JSI_OPTSETTYP(uint, wcount, ptr); break;
case JSI_OPTION_INTPTR_T: _JSI_OPTSETTYP(intptr_t, wcount, ptr); break;
case JSI_OPTION_UINTPTR_T:_JSI_OPTSETTYP(uintptr_t, wcount, ptr); break;
case JSI_OPTION_SIZE_T: _JSI_OPTSETTYP(size_t, wcount, ptr); break;
case JSI_OPTION_SSIZE_T: _JSI_OPTSETTYP(ssize_t, wcount, ptr); break;
case JSI_OPTION_LONG: _JSI_OPTSETTYP(long, wcount, ptr); break;
case JSI_OPTION_ULONG: _JSI_OPTSETTYP(ulong, wcount, ptr); break;
case JSI_OPTION_SHORT: _JSI_OPTSETTYP(short, wcount, ptr); break;
case JSI_OPTION_USHORT: _JSI_OPTSETTYP(ushort, wcount, ptr); break;
case JSI_OPTION_INT8: _JSI_OPTSETTYP(int8_t, wcount, ptr); break;
case JSI_OPTION_UINT8: _JSI_OPTSETTYP(uint8_t, wcount, ptr) break;
case JSI_OPTION_INT16: _JSI_OPTSETTYP(int16_t, wcount, ptr); break;
case JSI_OPTION_UINT16: _JSI_OPTSETTYP(uint16_t, wcount, ptr); break;
case JSI_OPTION_INT32: _JSI_OPTSETTYP(int32_t, wcount, ptr); break;
case JSI_OPTION_UINT32: _JSI_OPTSETTYP(uint32_t, wcount, ptr); break;
case JSI_OPTION_INT64: _JSI_OPTSETTYP(int64_t, wcount, ptr); break;
case JSI_OPTION_UINT64: _JSI_OPTSETTYP(uint64_t, wcount, ptr); break; // TODO: might loose top sign bit...
default: break;
}
if (expType)
return Jsi_LogType("not a %s", expType);
isIncr = 0;
break;
case JSI_OPTION_NUMBER:
case JSI_OPTION_DOUBLE:
case JSI_OPTION_LDOUBLE:
case JSI_OPTION_FLOAT:
nv = 0;
if (argValue) {
if (!Jsi_ValueIsNumber(interp, argValue))
goto bail;
if (Jsi_GetNumberFromValue(interp, argValue, &nv) != JSI_OK) {
return JSI_ERROR;
}
}
switch (specPtr->id) {
#define _JSI_OPTSETNTYP(typ, n, ptr) if (!argValue) *(typ*)ptr = 0; else { if (isIncr) n += *((typ *)ptr); \
interp->cdataIncrVal = *((typ *)ptr) = (typ)(n); \
if (interp->strict && Jsi_NumberIsNaN((Jsi_Number)(*((typ *)ptr)))) return Jsi_LogError("not a number"); }
case JSI_OPTION_NUMBER: _JSI_OPTSETNTYP(Jsi_Number, nv, ptr); break;
case JSI_OPTION_LDOUBLE: _JSI_OPTSETNTYP(ldouble, nv, ptr); break;
case JSI_OPTION_FLOAT: _JSI_OPTSETNTYP(float, nv, ptr); break;
case JSI_OPTION_DOUBLE: _JSI_OPTSETNTYP(double, nv, ptr); break;
default: break;
}
isIncr = 0;
break;
case JSI_OPTION_STRKEY:
{
if (argValue == NULL || Jsi_ValueIsNull(interp, argValue))
*(const char**)ptr = NULL;
else {
const char *scp;
if (Jsi_GetStringFromValue(interp, argValue, &scp) != JSI_OK) {
return JSI_ERROR;
}
*(const char**)ptr = Jsi_KeyAdd(interp,scp);
}
}
break;
case JSI_OPTION_STRBUF:
{
if (argValue == NULL || Jsi_ValueIsNull(interp, argValue))
*(char*)ptr = 0;
else {
int sLen;
const char *scp = Jsi_ValueString(interp, argValue, &sLen);
if (!scp)
goto bail;
if (sLen>(int)(specPtr->size-1)) {
return Jsi_LogError("String too long");
//sLen = specPtr->size-1;
}
memcpy((char*)ptr, scp, sLen);
((char*)ptr)[sLen] = 0;
}
}
break;
#define _JSI_OPT_CHECKNULL(argValue) if (!argValue || Jsi_ValueIsNull(interp, argValue)) { \
if (*((Jsi_Value **)ptr)) \
Jsi_DecrRefCount(interp, *((Jsi_Value **)ptr)); \
*((Jsi_Value **)ptr) = NULL; \
break; \
}
#define _JSI_OPT_ARGSET(argValue, ptr) \
if (!(specPtr->flags&JSI_OPT_NO_DUPVALUE)) {\
Jsi_IncrRefCount(interp, argValue); \
if (*((Jsi_Value **)ptr)) Jsi_DecrRefCount(interp, *((Jsi_Value **)ptr)); \
}\
*((Jsi_Value **)ptr) = argValue;
case JSI_OPTION_STRING:
if (argValue == *((Jsi_Value **)ptr))
break;
_JSI_OPT_CHECKNULL(argValue);
if (!Jsi_ValueIsString(interp, argValue))
goto bail;
_JSI_OPT_ARGSET(argValue, ptr);
break;
case JSI_OPTION_DSTRING:
Jsi_DSInit((Jsi_DString *)ptr);
if (argValue && !Jsi_ValueIsNull(interp, argValue))
{
int sLen;
const char *scp = Jsi_ValueString(interp, argValue, &sLen);
if (!scp)
goto bail;
Jsi_DSAppendLen((Jsi_DString *)ptr, scp, sLen);
}
break;
case JSI_OPTION_TIME_D: {
if (argValue)
{
Jsi_Number nv = 0;
if (Jsi_ValueIsNumber(interp, argValue)) {
Jsi_GetNumberFromValue(interp, argValue, &nv);
*(double*)ptr = nv;
} else {
const char *scp;
if (Jsi_GetStringFromValue(interp, argValue, &scp) != JSI_OK) {
return JSI_ERROR;
}
if (JSI_OK != Jsi_DatetimeParse(interp, scp, "", 0, &nv, false))
return JSI_ERROR;
*(double*)ptr = nv;
}
} else {
*(double*)ptr = 0;
}
break;
}
case JSI_OPTION_TIME_W: {
if (argValue)
{
if (Jsi_ValueIsNumber(interp, argValue)) {
Jsi_GetNumberFromValue(interp, argValue, (Jsi_Number*)ptr);
} else {
const char *scp;
Jsi_Number num;
if (Jsi_GetStringFromValue(interp, argValue, &scp) != JSI_OK) {
return JSI_ERROR;
}
if (JSI_OK != Jsi_DatetimeParse(interp, scp, "", 0, &num, false))
return JSI_ERROR;
*(Jsi_Wide*)ptr = (Jsi_Wide)num;
}
} else {
*(Jsi_Wide*)ptr = 0;
}
break;
}
case JSI_OPTION_TIME_T: {
if (argValue)
{
if (Jsi_ValueIsNumber(interp, argValue)) {
Jsi_Number num;
Jsi_GetNumberFromValue(interp, argValue, &num);
*(time_t*)ptr = (time_t)num;
} else {
const char *scp;
if (Jsi_GetStringFromValue(interp, argValue, &scp) != JSI_OK) {
return JSI_ERROR;
}
Jsi_Number nval;
if (JSI_OK != Jsi_DatetimeParse(interp, scp, "", 0, &nval, false))
return JSI_ERROR;
*(time_t*)ptr = nval/1000LL;
}
} else {
*(time_t*)ptr = 0;
}
break;
}
case JSI_OPTION_VAR:
_JSI_OPT_CHECKNULL(argValue);
if (argValue->vt != JSI_VT_NULL && argValue->vt != JSI_VT_VARIABLE)
goto bail;
_JSI_OPT_ARGSET(argValue, ptr);
break;
case JSI_OPTION_FUNC:
_JSI_OPT_CHECKNULL(argValue);
if (argValue->vt != JSI_VT_OBJECT || argValue->d.obj->ot != JSI_OT_FUNCTION)
goto bail;
if (specPtr->data && (interp->typeCheck.run|interp->typeCheck.all))
if (!jsi_FuncArgCheck(interp, argValue->d.obj->d.fobj->func, (char*)specPtr->data))
return Jsi_LogError("failed setting func pointer for %s", specPtr->name);
_JSI_OPT_ARGSET(argValue, ptr);
break;
case JSI_OPTION_USEROBJ:
_JSI_OPT_CHECKNULL(argValue);
if (argValue->vt != JSI_VT_OBJECT || argValue->d.obj->ot != JSI_OT_USEROBJ)
goto bail;
if (specPtr->data && Jsi_Strcmp((char*)specPtr->data, argValue->d.obj->d.uobj->reg->name))
return Jsi_LogError("expected id %s for %s",(char*)specPtr->data, specPtr->name);
_JSI_OPT_ARGSET(argValue, ptr);
break;
case JSI_OPTION_REGEXP:
_JSI_OPT_CHECKNULL(argValue);
if (argValue->vt != JSI_VT_OBJECT || argValue->d.obj->ot != JSI_OT_REGEXP)
goto bail;
_JSI_OPT_ARGSET(argValue, ptr);
break;
case JSI_OPTION_OBJ:
_JSI_OPT_CHECKNULL(argValue);
if (argValue->vt != JSI_VT_OBJECT)
goto bail;
case JSI_OPTION_VALUE:
_JSI_OPT_CHECKNULL(argValue);
_JSI_OPT_ARGSET(argValue, ptr);
break;
case JSI_OPTION_ARRAY:
_JSI_OPT_CHECKNULL(argValue);
if (argValue->vt != JSI_VT_OBJECT || !argValue->d.obj->isarrlist)
goto bail;
_JSI_OPT_ARGSET(argValue, ptr);
break;
#ifdef __cplusplus
case JSI_OPTION_END:
#else
default:
#endif
Jsi_LogBug("invalid option id: %d", specPtr->id);
}
done:
specPtr->flags |= JSI_OPT_IS_SPECIFIED;
if (isIncr)
return Jsi_LogError("incr invalid for %s", specPtr->name);
return JSI_OK;
bail:
if (!emsg) {
emsg = jsi_OptTypeInfo[specPtr->id].cName;
epre = "expected ";
}
return Jsi_LogError("%s%s: for %s option \"%.40s\"", epre, emsg, (cust?cust->name:""), specPtr->name);
}
|
CWE-120
| null | 520,812 |
157683646005303427347067086805917583966
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
jsonGenArray(Jsi_Interp *interp, Jsi_JsonParser *p, const char *js, uint pos, uint *endPos)
{
if (js==NULL || !js[0])
return NULL;
Jsi_Value *v = Jsi_ValueNewArray(interp, 0, 0);
Jsi_Obj *nobj = v->d.obj;
uint i, n;
Jsi_JsonTok *tok;
tok = p->tokens+pos;
Jsi_ValueMakeArrayObject(interp, &v, nobj);
for (i=pos+1, n=0; i<p->toknext && n<tok->size; i++, n++) {
if (n >= nobj->arrMaxSize) {
if (Jsi_ObjArraySizer(interp, nobj, n+1)<=0) {
break;
}
}
nobj->arr[n] = jsonGen1Value(interp, p, js, i, &i, 1);
}
Jsi_ObjSetLength(interp, nobj, n);
if (endPos)
*endPos = i;
return v;
}
|
CWE-120
| null | 520,813 |
199349452076831520136043876184400973860
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC JSONCheckCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
int r;
Jsi_RC result = JSI_OK;
bool strict = 1;
const char *cp;
JSI_JSON_DECLARE(p, tokens, 0);
Jsi_Value *jsv = Jsi_ValueArrayIndex(interp, args, 1);
if (jsv && Jsi_ValueGetBoolean(interp, jsv, &strict) != JSI_OK)
return Jsi_LogError("Expected boolean");
p.strict = strict;
jsv = Jsi_ValueArrayIndex(interp, args, 0);
cp = Jsi_ValueToString(interp, jsv, NULL);
r = Jsi_JsonParse(&p, cp);
Jsi_ValueMakeBool(interp, ret, r == JSI_JSON_ERR_NONE);
Jsi_JsonFree(&p);
return result;
}
|
CWE-120
| null | 520,814 |
307688391675055032770152088788186660322
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_Value *Jsi_ValueDup(Jsi_Interp *interp, Jsi_Value *v) {
return ValueDup(interp, v);
}
|
CWE-120
| null | 520,815 |
312732558134080976608878397452682824158
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_RC Jsi_FSUnregister(Jsi_Filesystem *fsPtr) {
FSList *fsl = jsiFSList, *flast = NULL;
while (fsl) {
if (fsl->fsPtr == fsPtr) {
if (flast)
flast->next = fsl->next;
else
jsiFSList = fsl->next;
Jsi_Free(fsl);
break;
}
flast = fsl;
fsl = fsl->next;
}
return JSI_OK;
}
|
CWE-120
| null | 520,816 |
191219340173975403693906235556667998413
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC jsi_ValueToBitset(Jsi_Interp *interp, Jsi_OptionSpec* spec, Jsi_Value *inValue, const char *inStr, void *record, Jsi_Wide flags)
{
// TODO: change this to not use byte instead of int...
int i, argc, n;
char *s =(((char*)record) + spec->offset);
char **argv;
const char *cp, **list = (const char**)spec->data;
uint64_t m = 0, im = 0;
int fflags = ((flags|spec->flags)&JSI_OPT_CUST_NOCASE?JSI_CMP_NOCASE:0);
if (!list)
return Jsi_LogError("custom enum spec did not set data: %s", spec->name);
switch (spec->size) {
case 1: im = *(uint8_t*)s; break;
case 2: im = *(uint16_t*)s; break;
case 4: im = *(uint32_t*)s; break;
case 8: im = *(uint64_t*)s; break;
default:
return Jsi_LogError("bitset size must be 1, 2, 4, or 8: %s", spec->name);
}
#ifndef JSI_LITE_ONLY
if (!inStr && Jsi_ValueIsString(interp, inValue))
inStr = Jsi_ValueString(interp, inValue, NULL);
#endif
if (inStr) {
if (*inStr == '+') {
inStr++;
m = im;
}
if (*inStr) {
Jsi_DString sStr;
Jsi_DSInit(&sStr);
Jsi_SplitStr(inStr, &argc, &argv, ",", &sStr);
for (i=0; i<argc; i++) {
int isnot = 0;
cp = argv[i];
if (*cp == '!') { isnot = 1; cp++; }
if (JSI_OK != Jsi_GetIndex(interp, cp, list, "enum", fflags, &n))
return JSI_ERROR;
if (n >= (int)(spec->size*8))
return Jsi_LogError("list larger than field size: %s", spec->name);
if (isnot)
m &= ~(1<<n);
else
m |= (1<<n);
}
Jsi_DSFree(&sStr);
}
} else {
#ifndef JSI_LITE_ONLY
if (!inValue) {
*s = 0;
return JSI_OK;
}
if (Jsi_ValueIsObjType(interp, inValue, JSI_OT_OBJECT) && !Jsi_ValueIsArray(interp, inValue)) {
Jsi_TreeEntry *tPtr;
Jsi_TreeSearch search;
Jsi_Tree *tp = Jsi_TreeFromValue(interp, inValue);
m = im;
for (tPtr = (tp?Jsi_TreeSearchFirst(tp, &search, 0, NULL):NULL);
tPtr != NULL; tPtr = Jsi_TreeSearchNext(&search)) {
cp =(char*) Jsi_TreeKeyGet(tPtr);
Jsi_Value *optval = (Jsi_Value*)Jsi_TreeValueGet(tPtr);
if (JSI_OK != Jsi_GetIndex(interp, cp, list, "bitset", fflags, &n)) {
Jsi_TreeSearchDone(&search);
return JSI_ERROR;
}
if (!Jsi_ValueIsBoolean(interp, optval)) {
Jsi_TreeSearchDone(&search);
return Jsi_LogError("object member is not a bool: %s", cp);
}
bool vb;
Jsi_ValueGetBoolean(interp, optval, &vb);
if (!vb)
m &= ~(1<<n);
else
m |= (1<<n);
}
if (tp)
Jsi_TreeSearchDone(&search);
*s = m;
return JSI_OK;
}
if (!Jsi_ValueIsArray(interp, inValue))
return Jsi_LogError("expected array or object");
argc = Jsi_ValueGetLength(interp, inValue);
for (i=0; i<argc; i++) {
int isnot = 0;
Jsi_Value *v = Jsi_ValueArrayIndex(interp, inValue, i);
const char *cp = (v?Jsi_ValueString(interp, v, NULL):"");
if (!cp)
return Jsi_LogError("expected string");
if (i == 0) {
if (*cp == '+' && !cp[1]) {
m = im;
continue;
}
}
if (*cp == '!') { isnot = 1; cp++; }
if (JSI_OK != Jsi_GetIndex(interp, cp, list, "bitset", fflags, &n))
return JSI_ERROR;
if (isnot)
m &= ~(1<<n);
else
m |= (1<<n);
}
*s = m;
#endif
}
switch (spec->size) {
case 1: *(uint8_t*)s = (uint8_t)m; break;
case 2: *(uint16_t*)s = (uint16_t)m; break;
case 4: *(uint32_t*)s = (uint32_t)m; break;
case 8: *(uint64_t*)s = (uint64_t)m; break;
}
return JSI_OK;
}
|
CWE-120
| null | 520,817 |
138302737868754195957675211165374738747
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC SqliteConstructor(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
Jsi_RC rc = JSI_ERROR;
/* void *cd = clientData; */
int flags;
char *zErrMsg;
const char *zFile = NULL, *vfs = 0;
/* In normal use, each JSI interpreter runs in a single thread. So
** by default, we can turn of mutexing on SQLite database connections.
** However, for testing purposes it is useful to have mutexes turned
** on. So, by default, mutexes default off. But if compiled with
** SQLITE_JSI_DEFAULT_FULLMUTEX then mutexes default on.
*/
flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
#ifdef SQLITE_JSI_DEFAULT_FULLMUTEX
flags |= SQLITE_OPEN_FULLMUTEX;
#else
flags |= SQLITE_OPEN_NOMUTEX;
#endif
Jsi_Value *vFile = Jsi_ValueArrayIndex(interp, args, 0);
Jsi_Value *arg = Jsi_ValueArrayIndex(interp, args, 1);
Jsi_DString dStr = {};
int ismem = 0, create = 0;
Jsi_Obj *fobj;
Jsi_Value *toacc;
const char *vf;
const char *dbname = NULL;
if (vFile==NULL || Jsi_ValueIsNull(interp, vFile) ||
((vf = Jsi_ValueString(interp, vFile, NULL)) && !Jsi_Strcmp(vf,":memory:"))) {
zFile = ":memory:";
ismem = 1;
} else {
zFile = Jsi_ValueNormalPath(interp, vFile, &dStr);
if (zFile == NULL)
return Jsi_LogError("bad or missing file name");
Jsi_StatBuf st = {};
st.st_uid = -1;
create = (Jsi_Lstat(interp, vFile, &st) != 0);
}
zErrMsg = 0;
Jsi_Db *db = (Jsi_Db*)Jsi_Calloc(1, sizeof(*db) );
if( db==0 ) {
Jsi_DSFree(&dStr);
Jsi_LogError("malloc failed");
return JSI_ERROR;
}
db->sig = SQLITE_SIG_DB;
db->_ = &dbObjCmd;
db->_->newCnt++;
db->_->activeCnt++;
db->stmtCacheMax = NUM_PREPARED_STMTS;
db->hasOpts = 1;
if ((arg != NULL && !Jsi_ValueIsNull(interp,arg))
&& Jsi_OptionsProcess(interp, SqlOptions, db, arg, 0) < 0) {
rc = JSI_ERROR;
goto bail;
}
if (ismem == 0 &&
(Jsi_InterpAccess(interp, vFile, (db->readonly ? JSI_INTACCESS_READ : JSI_INTACCESS_WRITE)) != JSI_OK
|| (create && Jsi_InterpAccess(interp, vFile, JSI_INTACCESS_CREATE) != JSI_OK))) {
Jsi_LogError("Safe accces denied");
goto bail;
}
if (db->stmtCacheMax<0 || db->stmtCacheMax>MAX_PREPARED_STMTS) {
Jsi_LogError("option stmtCacheMax value %d is not in range 0..%d", db->stmtCacheMax, MAX_PREPARED_STMTS);
goto bail;
}
if (!db->udata) {
db->udata = Jsi_ValueNewObj(interp, NULL);
Jsi_IncrRefCount(interp, db->udata);
}
if (db->readonly) {
flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
flags |= SQLITE_OPEN_READONLY;
} else {
flags &= ~SQLITE_OPEN_READONLY;
flags |= SQLITE_OPEN_READWRITE;
if (db->noCreate) {
flags &= ~SQLITE_OPEN_CREATE;
}
}
if (db->vfs)
vfs = Jsi_ValueToString(interp, db->vfs, NULL);
if(db->mutex == MUTEX_NONE) {
flags |= SQLITE_OPEN_NOMUTEX;
flags &= ~SQLITE_OPEN_FULLMUTEX;
} else {
flags &= ~SQLITE_OPEN_NOMUTEX;
}
if(db->mutex ==MUTEX_FULL) {
flags |= SQLITE_OPEN_FULLMUTEX;
flags &= ~SQLITE_OPEN_NOMUTEX;
} else {
flags &= ~SQLITE_OPEN_FULLMUTEX;
}
if (SQLITE_OK != sqlite3_open_v2(zFile, &db->db, flags, vfs)) {
Jsi_LogError("db open failed: %s", zFile);
goto bail;
}
//Jsi_DSFree(&translatedFilename);
if( SQLITE_OK!=sqlite3_errcode(db->db) ) {
zErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(db->db));
DbClose(db->db);
db->db = 0;
}
if( db->db==0 ) {
sqlite3_free(zErrMsg);
goto bail;
}
;
toacc = NULL;
if (Jsi_FunctionIsConstructor(funcPtr)) {
toacc = _this;
} else {
Jsi_Obj *o = Jsi_ObjNew(interp);
Jsi_PrototypeObjSet(interp, "Sqlite", o);
Jsi_ValueMakeObject(interp, ret, o);
toacc = *ret;
}
sqlite3_create_function(db->db, "unixtime", -1, SQLITE_UTF8, db, jsiSqlFuncUnixTime, 0, 0);
fobj = Jsi_ValueGetObj(interp, toacc /* constructor obj*/);
if ((db->objId = Jsi_UserObjNew(interp, &sqliteobject, fobj, db))<0)
goto bail;
db->stmtHash = Jsi_HashNew(interp, JSI_KEYS_STRING, NULL);
db->fobj = fobj;
//dbSys->cnt = Jsi_UserObjCreate(interp, sqliteobject.name /*dbSys*/, fobj, db);
db->interp = interp;
db->optPtr = &db->queryOpts;
db->stmtCache = Jsi_ListNew((Jsi_Interp*)db, 0, dbStmtFreeProc);
rc = JSI_OK;
dbname = Jsi_DSValue(&db->name);
if (dbname[0])
sqlite3_db_config(db->db, SQLITE_DBCONFIG_MAINDBNAME, dbname);
Jsi_JSONParseFmt(interp, &db->version, "{libVer:\"%s\", hdrVer:\"%s\", hdrNum:%d, hdrSrcId:\"%s\", pkgVer:%d}",
(char *)sqlite3_libversion(), SQLITE_VERSION, SQLITE_VERSION_NUMBER, SQLITE_SOURCE_ID, jsi_DbPkgVersion);
dbSetupCallbacks(db, NULL);
bail:
if (rc != JSI_OK) {
if (db->hasOpts)
Jsi_OptionsFree(interp, SqlOptions, db, 0);
db->_->activeCnt--;
Jsi_Free(db);
}
Jsi_DSFree(&dStr);
Jsi_ValueMakeUndef(interp, ret);
return rc;
}
|
CWE-120
| null | 520,818 |
324403993487623428198958061697069378940
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
int Jsi_Scandir(Jsi_Interp *interp, Jsi_Value* path, Jsi_Dirent ***namelist,
int (*filter)(const Jsi_Dirent *), int (*compar)(const Jsi_Dirent **, const Jsi_Dirent**))
{
void *data;
Jsi_Filesystem *fsPtr = Jsi_FilesystemForPath(interp, path, &data);
if (fsPtr == NULL || !fsPtr->scandirProc) return -1;
return fsPtr->scandirProc(interp, path, namelist, filter, compar);
}
|
CWE-120
| null | 520,819 |
36097056298780909907795228720126398458
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
char* Jsi_NormalPath(Jsi_Interp *interp, const char *path, Jsi_DString *dStr) {
char prefix[3] = "";
char cdbuf[PATH_MAX];
Jsi_DSInit(dStr);
if (!path || !path[0]) return NULL;
if (*path == '/')
Jsi_DSAppend(dStr, path, NULL);
#ifdef __WIN32 /* TODO: add proper handling for windows paths. */
else if (*path && path[1] == ':') {
Jsi_DSAppend(dStr, path, NULL);
return Jsi_DSValue(dStr);
}
#endif
else if (path[0] == '~') {
Jsi_DSAppend(dStr, jsi_GetHomeDir(interp), (path[1] == '/' ? "" : "/"), path+1, NULL);
} else if (path[0] == '.' && path[1] == 0) {
if (jsiIntData.pwd) {
Jsi_DSAppend(dStr, jsiIntData.pwd, NULL);
} else {
Jsi_DSAppend(dStr, getcwd(cdbuf, sizeof(cdbuf)), NULL);
}
} else {
if (jsiIntData.pwd) {
Jsi_DSAppend(dStr, jsiIntData.pwd, "/", path, NULL);
} else {
Jsi_DSAppend(dStr, getcwd(cdbuf, sizeof(cdbuf)), "/", path, NULL);
}
}
Jsi_DString sStr = {};
char *cp = Jsi_DSValue(dStr);
#ifdef __WIN32
if (*cp && cp[1] == ':') {
prefix[0] = *cp;
prefix[1] = cp[1];
prefix[2] = 0;
cp += 2;
}
#endif
int i=0, n=0, m, nmax, unclean=0, slens[PATH_MAX];
char *sp = cp, *ss;
char *sptrs[PATH_MAX];
while (*cp && n<PATH_MAX) {
while (*cp && *cp == '/') {
cp++;
if (*cp == '/')
unclean = 1;
}
sptrs[n] = cp;
if (cp[0] == '.' && (cp[1] == '.' || cp[1] == '/'))
unclean = 1;
ss = cp++;
while (*ss && *ss != '/')
ss++;
slens[n++] = (ss-cp) + 1;
cp = ss;
}
if (!unclean)
return sp;
/* Need to remove //, /./, /../ */
nmax = n--;
while (n>0) {
if (slens[n]<=0) {
n--;
continue;
}
if (Jsi_Strncmp(sptrs[n],".",slens[n])==0)
slens[n] = 0;
else if (Jsi_Strncmp(ss,"..",slens[n])==0) {
int cnt = 0;
m = n-1;
while (m>=0 && cnt<1) {
if (slens[m])
cnt++;
slens[m] = 0;
m--;
}
if (cnt<1)
return sp; /* Can't fix it */
}
n--;
}
/* TODO: prefix for windows. */
Jsi_DSAppend(&sStr, prefix, NULL);
for (i=0; i<nmax; i++) {
if (slens[i]) {
#ifdef __WIN32
Jsi_DSAppend(&sStr, "/" /*"\\"*/, NULL);
#else
Jsi_DSAppend(&sStr, "/", NULL);
#endif
Jsi_DSAppendLen(&sStr, sptrs[i], slens[i]);
}
}
Jsi_DSSetLength(dStr, 0);
Jsi_DSAppend(dStr, Jsi_DSValue(&sStr), NULL);
Jsi_DSFree(&sStr);
return Jsi_DSValue(dStr);
}
|
CWE-120
| null | 520,820 |
46970591803922691067276402783128052662
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
void Jsi_TreeSearchDone(Jsi_TreeSearch *searchPtr)
{
if (searchPtr->Ptrs != searchPtr->staticPtrs)
Jsi_Free(searchPtr->Ptrs);
searchPtr->Ptrs = searchPtr->staticPtrs;
searchPtr->top = 0;
}
|
CWE-120
| null | 520,821 |
328554781565617157228227741528375466896
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
bool Jsi_NumberIsNormal(Jsi_Number a) { return (fpclassify(a) == FP_ZERO || isnormal(a)); }
|
CWE-120
| null | 520,822 |
29222421061700548862680302822233753924
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC jsi_AliasFree(Jsi_Interp *interp, Jsi_HashEntry *hPtr, void *data) {
/* TODO: deal with other copies of func may be floating around (refCount). */
AliasCmd *ac = (AliasCmd *)data;
if (!ac) return JSI_ERROR;
SIGASSERT(ac,ALIASCMD);
if (ac->func)
Jsi_DecrRefCount(ac->dinterp, ac->func);
if (ac->args)
Jsi_DecrRefCount(ac->dinterp, ac->args);
if (!ac->cmdVal)
return JSI_OK;
Jsi_Func *fobj = ac->cmdVal->d.obj->d.fobj->func;
fobj->cmdSpec->reserved[2] = NULL;
fobj->cmdSpec->proc = NULL;
if (ac->intobj && ac->intobj->subinterp) {
Jsi_CommandDelete(ac->intobj->subinterp, ac->cmdName);
//if (Jsi_Strchr(ac->cmdName, '.'))
// Jsi_LogBug("alias free with X.Y dot name leaks memory: %s", ac->cmdName);
} else
Jsi_DecrRefCount(ac->subinterp, ac->cmdVal);
_JSI_MEMCLEAR(ac);
Jsi_Free(ac);
return JSI_OK;
}
|
CWE-120
| null | 520,823 |
319840194440482524200086524734650873035
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
const char* jsi_opcode_string(uint opCode)
{
if (opCode >= (sizeof(jsi_op_names)/sizeof(jsi_op_names[0])))
return "NULL";
return jsi_op_names[opCode];
}
|
CWE-120
| null | 520,824 |
14280500947546927997662014647551846548
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
int Jsi_Access(Jsi_Interp *interp, Jsi_Value* path, int mode) {
void *data;
Jsi_Filesystem *fsPtr = Jsi_FilesystemForPath(interp, path, &data);
if (fsPtr == NULL || !fsPtr->accessProc) return -1;
if (interp->isSafe && fsPtr && fsPtr == &jsiFilesystem) {
int aflag = (mode&W_OK ? JSI_INTACCESS_WRITE : JSI_INTACCESS_READ);
if (Jsi_InterpAccess(interp, path, aflag) != JSI_OK)
return -1;
}
return fsPtr->accessProc(interp, path, mode);
}
|
CWE-120
| null | 520,825 |
119378819881375197499511516052586526733
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_OpCodes *code_jfalse(int off) { JSI_NEW_CODES(0,OP_JFALSE, off); }
|
CWE-120
| null | 520,826 |
246678083768070659511543725635597519437
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_OpCodes *code_ret(jsi_Pstate *p, jsi_Pline *line, int n) { JSI_NEW_CODESLN(0,OP_RET, n); }
|
CWE-120
| null | 520,827 |
27831969362938869860822041449867433829
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
char *Jsi_ValueArrayIndexToStr(Jsi_Interp *interp, Jsi_Value *args, int index, int *lenPtr)
{
Jsi_Value *arg = Jsi_ValueArrayIndex(interp, args, index);
if (!arg)
return NULL;
char *res = Jsi_ValueString(interp, arg, lenPtr);
if (res)
return res;
res = (char*)Jsi_ValueToString(interp, arg, NULL);
if (res && lenPtr)
*lenPtr = Jsi_Strlen(res);
return res;
}
|
CWE-120
| null | 520,828 |
123308294015387872884458578829218762073
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_Db* Jsi_DbNew(const char *zFile, int inFlags /* JSI_DBI_* */)
{
if (!jsi_dbVfsPtr) {
printf( "Sqlite unsupported\n");
return NULL;
}
return jsi_dbVfsPtr->dbNew(zFile, inFlags);
}
|
CWE-120
| null | 520,829 |
74605094012214070769747168500676042373
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC jsiInterpDelete(Jsi_Interp* interp, void *unused)
{
SIGASSERT(interp,INTERP);
bool isMainInt = (interp == jsiIntData.mainInterp);
int mainFlag = (isMainInt ? 2 : 1);
if (isMainInt)
DeleteAllInterps();
if (interp->opts.initProc)
(*interp->opts.initProc)(interp, mainFlag);
jsiIntData.delInterp = interp;
if (interp->gsc) jsi_ScopeChainFree(interp, interp->gsc);
if (interp->csc) Jsi_DecrRefCount(interp, interp->csc);
if (interp->ps) jsi_PstateFree(interp->ps);
int i;
for (i=0; i<interp->maxStack; i++) {
if (interp->Stack[i]) Jsi_DecrRefCount(interp, interp->Stack[i]);
if (interp->Obj_this[i]) Jsi_DecrRefCount(interp, interp->Obj_this[i]);
}
if (interp->Stack) {
Jsi_Free(interp->Stack);
Jsi_Free(interp->Obj_this);
}
if (interp->argv0)
Jsi_DecrRefCount(interp, interp->argv0);
if (interp->console)
Jsi_DecrRefCount(interp, interp->console);
if (interp->lastSubscriptFail)
Jsi_DecrRefCount(interp, interp->lastSubscriptFail);
if (interp->nullFuncRet)
Jsi_DecrRefCount(interp, interp->nullFuncRet);
Jsi_HashDelete(interp->codeTbl);
Jsi_MapDelete(interp->cmdSpecTbl);
Jsi_HashDelete(interp->fileTbl);
Jsi_HashDelete(interp->funcObjTbl);
Jsi_HashDelete(interp->funcsTbl);
if (interp->profileCnt) { // TODO: resolve some values from dbPtr, others not.
double endTime = jsi_GetTimestamp();
double coverage = (int)(100.0*interp->coverHit/interp->coverAll);
Jsi_DString dStr;
Jsi_DSInit(&dStr);
Jsi_DSPrintf(&dStr, "PROFILE: TOTAL: time=%.6f, func=%.6f, cmd=%.6f, #funcs=%d, #cmds=%d, cover=%2.1f%%, #values=%d, #objs=%d %s%s\n",
endTime-interp->startTime, interp->funcSelfTime, interp->cmdSelfTime, interp->funcCallCnt, interp->cmdCallCnt,
coverage, interp->dbPtr->valueAllocCnt, interp->dbPtr->objAllocCnt,
interp->parent?" ::":"", (interp->parent&&interp->name?interp->name:""));
Jsi_Puts(interp, jsi_Stderr, Jsi_DSValue(&dStr), -1);
Jsi_DSFree(&dStr);
}
if (isMainInt)
Jsi_HashDelete(interp->lexkeyTbl);
Jsi_HashDelete(interp->protoTbl);
if (interp->subthread)
jsiIntData.mainInterp->threadCnt--;
if (interp->subthread && interp->strKeyTbl == jsiIntData.mainInterp->strKeyTbl)
jsiIntData.mainInterp->threadShrCnt--;
if (!jsiIntData.mainInterp->threadShrCnt)
#ifdef JSI_USE_MANY_STRKEY
jsiIntData.mainInterp->strKeyTbl->v.tree->opts.lockTreeProc = NULL;
#else
jsiIntData.mainInterp->strKeyTbl->v.hash->opts.lockHashProc = NULL;
#endif
//Jsi_ValueMakeUndef(interp, &interp->ret);
Jsi_HashDelete(interp->thisTbl);
Jsi_HashDelete(interp->varTbl);
Jsi_HashDelete(interp->genValueTbl);
Jsi_HashDelete(interp->genObjTbl);
Jsi_HashDelete(interp->aliasHash);
if (interp->staticFuncsTbl)
Jsi_HashDelete(interp->staticFuncsTbl);
if (interp->breakpointHash)
Jsi_HashDelete(interp->breakpointHash);
if (interp->preserveTbl->numEntries!=0)
Jsi_LogBug("Preserves unbalanced");
Jsi_HashDelete(interp->preserveTbl);
if (interp->curDir)
Jsi_Free(interp->curDir);
if (isMainInt) {
jsi_InitFilesys(interp, mainFlag);
}
#ifndef JSI_OMIT_VFS
jsi_InitVfs(interp, 1);
#endif
#ifndef JSI_OMIT_CDATA
jsi_InitCData(interp, mainFlag);
#endif
#if JSI__MYSQL==1
Jsi_InitMySql(interp, mainFlag);
#endif
while (interp->interpStrEvents) {
InterpStrEvent *se = interp->interpStrEvents;
interp->interpStrEvents = se->next;
if (se->acfunc)
Jsi_DecrRefCount(interp, se->acfunc);
if (se->acdata)
Jsi_Free(se->acdata);
Jsi_Free(se);
}
if (interp->Mutex)
Jsi_MutexDelete(interp, interp->Mutex);
if (interp->QMutex) {
Jsi_MutexDelete(interp, interp->QMutex);
Jsi_DSFree(&interp->interpEvalQ);
}
if (interp->nullFuncArg)
Jsi_DecrRefCount(interp, interp->nullFuncArg);
if (interp->NullValue)
Jsi_DecrRefCount(interp, interp->NullValue);
if (interp->Function_prototype_prototype) {
if (interp->Function_prototype_prototype->refCnt>1)
Jsi_DecrRefCount(interp, interp->Function_prototype_prototype);
Jsi_DecrRefCount(interp, interp->Function_prototype_prototype);
}
if (interp->Object_prototype) {
Jsi_DecrRefCount(interp, interp->Object_prototype);
}
Jsi_HashDelete(interp->regexpTbl);
Jsi_OptionsFree(interp, InterpOptions, interp, 0);
Jsi_HashDelete(interp->userdataTbl);
Jsi_HashDelete(interp->eventTbl);
if (interp->inopts)
Jsi_DecrRefCount(interp, interp->inopts);
if (interp->safeWriteDirs)
Jsi_DecrRefCount(interp, interp->safeWriteDirs);
if (interp->safeReadDirs)
Jsi_DecrRefCount(interp, interp->safeReadDirs);
if (interp->pkgDirs)
Jsi_DecrRefCount(interp, interp->pkgDirs);
for (i=0; interp->cleanObjs[i]; i++) {
interp->cleanObjs[i]->tree->opts.freeHashProc = 0;
Jsi_ObjFree(interp, interp->cleanObjs[i]);
}
Jsi_HashDelete(interp->bindTbl);
for (i = 0; i <= interp->cur_scope; i++)
jsi_ScopeStrsFree(interp, interp->scopes[i]);
#if JSI__ZVFS==1
Jsi_InitZvfs(interp, mainFlag);
#endif
if (!interp->parent)
Jsi_HashDelete(interp->loadTbl);
if (interp->packageHash)
Jsi_HashDelete(interp->packageHash);
Jsi_HashDelete(interp->assocTbl);
interp->cleanup = 1;
jsi_AllObjOp(interp, NULL, -1);
#ifdef JSI_MEM_DEBUG
jsi_DebugDumpValues(interp);
#endif
if (isMainInt || interp->strKeyTbl != jsiIntData.mainInterp->strKeyTbl)
Jsi_MapDelete(interp->strKeyTbl);
if (isMainInt)
jsiIntData.mainInterp = NULL;
_JSI_MEMCLEAR(interp);
jsiIntData.delInterp = NULL;
Jsi_Free(interp);
return JSI_OK;
}
|
CWE-120
| null | 520,830 |
302172862607614676321022664759488867616
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC SqliteBackupCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
Jsi_Db *jdb;
Jsi_RC rv = JSI_OK;
int rc;
const char *zDestFile;
const char *zSrcDb;
sqlite3 *pDest;
sqlite3_backup *pBackup;
if (!(jdb = dbGetDbHandle(interp, _this, funcPtr))) return JSI_ERROR;
Jsi_Value *vFile = Jsi_ValueArrayIndex(interp, args, 0);
int argc = Jsi_ValueGetLength(interp, args);
if( argc==1 ) {
zSrcDb = "main";
} else {
zSrcDb = Jsi_ValueArrayIndexToStr(interp, args, 1, NULL);
}
Jsi_DString dStr = {};
if (!vFile)
zDestFile = ":memory:";
else {
zDestFile = Jsi_ValueNormalPath(interp, vFile, &dStr);
if (zDestFile == NULL)
return Jsi_LogError("bad or missing file name");
}
rc = sqlite3_open(zDestFile, &pDest);
if( rc!=SQLITE_OK ) {
Jsi_LogError("cannot open target database %s: %s", zDestFile, sqlite3_errmsg(pDest));
DbClose(pDest);
Jsi_DSFree(&dStr);
return JSI_ERROR;
}
pBackup = sqlite3_backup_init(pDest, "main", jdb->db, zSrcDb);
if( pBackup==0 ) {
Jsi_LogError("backup failed: %s", sqlite3_errmsg(pDest));
DbClose(pDest);
Jsi_DSFree(&dStr);
return JSI_ERROR;
}
while( (rc = sqlite3_backup_step(pBackup,100))==SQLITE_OK ) {}
sqlite3_backup_finish(pBackup);
if( rc==SQLITE_DONE ) {
rv = JSI_OK;
} else {
Jsi_LogError("backup failed: %s", sqlite3_errmsg(pDest));
rv = JSI_ERROR;
}
Jsi_DSFree(&dStr);
DbClose(pDest);
return rv;
}
|
CWE-120
| null | 520,831 |
287797511138616496090863051467655376350
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC jsi_wsFileRead(Jsi_Interp *interp, Jsi_Value *name, Jsi_DString *dStr, jsi_wsCmdObj *cmdPtr, jsi_wsPss *pss) {
Jsi_StatBuf sb;
Jsi_RC rc = JSI_ERROR;
int n = Jsi_Stat(interp, name, &sb);
if (!n && sb.st_size>0) {
char fdir[PATH_MAX];
const char* cr = cmdPtr->curRoot, *fpath=NULL;
if (!Jsi_FSNative(interp, name) || ((fpath= Jsi_Realpath(interp, name, fdir))
&& cr && !Jsi_Strncmp(fpath, cr, Jsi_Strlen(cr)))) {
rc = Jsi_FileRead(interp, name, dStr);
if (rc == JSI_OK && cmdPtr->onModify && Jsi_FSNative(interp, name))
jsi_wsFileAdd(interp, cmdPtr, name);
} else
fprintf(stderr, "Skip read file %s in %s\n", Jsi_ValueString(interp, name, NULL), (cr?cr:""));
}
if (cmdPtr->noWarn)
return JSI_OK;
return rc;
}
|
CWE-120
| null | 520,832 |
275738563978025661576385743406084017765
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_OpCodes *code_not() { JSI_NEW_CODES(0,OP_NOT, 0); }
|
CWE-120
| null | 520,833 |
80437198012218991139496953338783524868
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_Value* Jsi_ValueMakeBlob(Jsi_Interp *interp, Jsi_Value **vPtr, unsigned char *s, int len) {
Jsi_Value *v = (vPtr?*vPtr:NULL);
if (!v)
v = Jsi_ValueNew(interp);
else
Jsi_ValueReset(interp, vPtr);
Jsi_Obj *obj = Jsi_ObjNewType(interp, JSI_OT_STRING);
Jsi_ValueMakeObject(interp, &v, obj);
obj->d.s.str = (char*)s;
obj->d.s.len = len;
obj->isBlob = 1;
return v;
}
|
CWE-120
| null | 520,834 |
32588635446332505107133000196982430404
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void dbOutputQuotedString(Jsi_DString *dStr, const char *z) {
int i;
int nSingle = 0;
for(i=0; z[i]; i++) {
if( z[i]=='\'' ) nSingle++;
}
if( nSingle==0 ) {
Jsi_DSAppend(dStr,"'", z, "'", NULL);
} else {
Jsi_DSAppend(dStr,"'", NULL);
while( *z ) {
for(i=0; z[i] && z[i]!='\''; i++) {}
if( i==0 ) {
Jsi_DSAppend(dStr,"''", NULL);
z++;
} else if( z[i]=='\'' ) {
Jsi_DSAppendLen(dStr,z, i);
Jsi_DSAppend(dStr,"''", NULL);
z += i+1;
} else {
Jsi_DSAppend(dStr, z, NULL);
break;
}
}
Jsi_DSAppend(dStr,"'", NULL);
}
}
|
CWE-120
| null | 520,835 |
130903615847837961598026137019466954777
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_TreeEntry* maximum_node(Jsi_TreeEntry* n) {
Assert (n != NULL);
while (n->right != NULL) {
n = n->right;
}
return n;
}
|
CWE-120
| null | 520,836 |
65896377080567944129957632735608271951
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC jsi_AliasCreateCmd(Jsi_Interp* interp, const char* key, AliasCmd* ac) {
if (Jsi_InterpGone(interp))
return JSI_ERROR;
key = Jsi_KeyAdd(interp, key);
Jsi_Value *cmd = jsi_CommandCreate(interp, key, jsi_AliasInvoke, NULL, 0, 0);
if (!cmd)
return Jsi_LogBug("command create failure");
ac->cmdVal = cmd;
Jsi_Func *fobj = cmd->d.obj->d.fobj->func;
fobj->cmdSpec->reserved[2] = ac;
cmd->d.obj->isNoOp = (ac->func->d.obj->d.fobj->func->callback == jsi_NoOpCmd);
return JSI_OK;
}
|
CWE-120
| null | 520,837 |
130046881757911782259259991226364735289
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
int Jsi_Rename(Jsi_Interp *interp, Jsi_Value *src, Jsi_Value *dst) {
void *data;
Jsi_Filesystem *fsPtr = Jsi_FilesystemForPath(interp, src, &data);
if (fsPtr != Jsi_FilesystemForPath(interp, src, &data)) return -1;
if (fsPtr == NULL || !fsPtr->renameProc) return -1;
return fsPtr->renameProc(interp, src,dst);
}
|
CWE-120
| null | 520,838 |
320193625098956422813642940989809776610
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_Value* dbGetValueGet(Jsi_Interp *interp, sqlite3_value *pIn)
{
Jsi_Value *v = Jsi_ValueNew(interp);
switch (sqlite3_value_type(pIn)) {
case SQLITE_BLOB: {
int bytes;
bytes = sqlite3_value_bytes(pIn);
const char *zBlob = (char*) sqlite3_value_blob(pIn);
if(!zBlob ) {
return Jsi_ValueMakeNull(interp, &v);
}
unsigned char *uptr = (unsigned char*)Jsi_Malloc(bytes+1);
memcpy(uptr, zBlob, bytes);
uptr[bytes] = 0;
return Jsi_ValueMakeBlob(interp, &v, uptr, bytes);
}
case SQLITE_INTEGER: {
sqlite_int64 n = sqlite3_value_int64(pIn);
if( n>=-2147483647 && n<=2147483647 ) {
return Jsi_ValueMakeNumber(interp, &v, n);
} else {
return Jsi_ValueMakeNumber(interp, &v, n);
}
}
case SQLITE_FLOAT: {
return Jsi_ValueMakeNumber(interp, &v, (Jsi_Number)sqlite3_value_double(pIn));
}
case SQLITE_NULL: {
return Jsi_ValueMakeNull(interp, &v);
}
default:
return Jsi_ValueMakeStringDup(interp, &v, (char *)sqlite3_value_text(pIn));
}
return v;
}
|
CWE-120
| null | 520,839 |
119881605549927028398155337424489853357
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC SqliteRestoreCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
Jsi_Db *jdb;
const char *zSrcFile;
const char *zDestDb;
sqlite3 *pSrc;
sqlite3_backup *pBackup;
int nTimeout = 0;
int rc;
if (!(jdb = dbGetDbHandle(interp, _this, funcPtr))) return JSI_ERROR;
Jsi_Value *vFile = Jsi_ValueArrayIndex(interp, args, 0);
int argc = Jsi_ValueGetLength(interp, args);
if( argc==1 ) {
zDestDb = "main";
} else {
zDestDb = Jsi_ValueArrayIndexToStr(interp, args, 1, NULL);
}
Jsi_DString dStr = {};
if (!vFile)
zSrcFile = ":memory:";
else {
zSrcFile = Jsi_ValueNormalPath(interp, vFile, &dStr);
if (zSrcFile == NULL)
return Jsi_LogError("bad or missing file name");
}
rc = sqlite3_open_v2(zSrcFile, &pSrc, SQLITE_OPEN_READONLY, 0);
if( rc!=SQLITE_OK ) {
Jsi_LogError("cannot open source database: %s", sqlite3_errmsg(pSrc));
DbClose(pSrc);
Jsi_DSFree(&dStr);
return JSI_ERROR;
}
pBackup = sqlite3_backup_init(jdb->db, zDestDb, pSrc, "main");
if( pBackup==0 ) {
Jsi_LogError("restore failed: %s", sqlite3_errmsg(jdb->db));
DbClose(pSrc);
Jsi_DSFree(&dStr);
return JSI_ERROR;
}
while( (rc = sqlite3_backup_step(pBackup,100))==SQLITE_OK
|| rc==SQLITE_BUSY ) {
if( rc==SQLITE_BUSY ) {
if( nTimeout++ >= 3 ) break;
sqlite3_sleep(100);
}
}
sqlite3_backup_finish(pBackup);
Jsi_RC rv;
if( rc==SQLITE_DONE ) {
rv = JSI_OK;
} else if( rc==SQLITE_BUSY || rc==SQLITE_LOCKED ) {
Jsi_LogError("restore failed: source database busy");
rv = JSI_ERROR;
} else {
Jsi_LogError("restore failed: %s", sqlite3_errmsg(jdb->db));
rv = JSI_ERROR;
}
Jsi_DSFree(&dStr);
DbClose(pSrc);
return rv;
}
|
CWE-120
| null | 520,840 |
142372436249694695219169913932445207166
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_HashEntryNew(Jsi_Hash *tablePtr, const void *key, bool *newPtr)
{
if (tablePtr->opts.lockHashProc && (*tablePtr->opts.lockHashProc)(tablePtr, 1) != JSI_OK)
return NULL;
Jsi_HashEntry *hPtr = (*((tablePtr)->createProc))(tablePtr, key, newPtr);
#ifdef JSI_HAS_SIG_HASHENTRY
SIGINIT(hPtr, HASHENTRY);
#endif
if (tablePtr->opts.lockHashProc)
(*tablePtr->opts.lockHashProc)(tablePtr, 0);
return hPtr;
}
|
CWE-120
| null | 520,841 |
191793464692407912189644078663262290171
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_RC Jsi_ValueInsert(Jsi_Interp *interp, Jsi_Value *target, const char *key, Jsi_Value *val, int flags)
{
if (target == NULL)
target = interp->csc;
if (target->vt != JSI_VT_OBJECT) {
if (interp->strict)
Jsi_LogWarn("Target is not object");
return JSI_ERROR;
}
target->f.flag |= flags;
if (Jsi_ObjInsert(interp, target->d.obj, key, val, flags))
return JSI_OK;
return JSI_ERROR;
}
|
CWE-120
| null | 520,842 |
216759233267259816676252116024109437280
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_Value* jsi_ValueMakeBlobDup(Jsi_Interp *interp, Jsi_Value **ret, unsigned char *s, int len) {
if (len<0) len = Jsi_Strlen((char*)s);
uchar *dp = (uchar*)Jsi_Malloc(len+1);
memcpy(dp, s, len);
dp[len] = 0;
return Jsi_ValueMakeBlob(interp, ret, dp, len);
}
|
CWE-120
| null | 520,843 |
67105688402476941397835285526249174872
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void dbEvalRowInfo(
DbEvalContext *p, /* Evaluation context */
int *pnCol, /* OUT: Number of column names */
char ***papColName, /* OUT: Array of column names */
int **papColType
) {
/* Compute column names */
// Jsi_Interp *interp = p->jdb->interp;
if( 0==p->apColName ) {
sqlite3_stmt *pStmt = p->pPreStmt->pStmt;
uint i; /* Iterator variable */
uint nCol; /* Number of columns returned by pStmt */
char **apColName = 0; /* Array of column names */
int *apColType = 0;
const char *zColName; /* Column name */
int numRid = 0; /* Number of times rowid seen. */
p->nCol = nCol = sqlite3_column_count(pStmt);
if( nCol>0 && (papColName || p->pArray) ) {
uint cnLen = sizeof(char*)*nCol, cnStart = cnLen;
for(i=0; i<nCol && cnLen<sizeof(p->staticColNames); i++)
cnLen += Jsi_Strlen(sqlite3_column_name(pStmt,i))+1;
if (cnLen>=sizeof(p->staticColNames)) {
apColName = (char**)Jsi_Calloc(nCol, sizeof(char*) );
cnStart = 0;
} else {
apColName = (char**)p->staticColNames;
}
if (papColType) {
if (nCol < SQL_MAX_STATIC_TYPES)
apColType = p->staticColTypes;
else
apColType = (int*)Jsi_Calloc(nCol, sizeof(int));
}
for(i=0; i<nCol; i++) {
zColName = sqlite3_column_name(pStmt,i);
if (cnStart==0)
apColName[i] = Jsi_Strdup(zColName);
else {
apColName[i] = p->staticColNames+cnStart;
Jsi_Strcpy(apColName[i], zColName);
cnStart += Jsi_Strlen(zColName)+1;
}
if (apColType)
apColType[i] = sqlite3_column_type(pStmt,i);
/* Check if rowid appears first, and more than once. */
if ((i == 0 || numRid>0) &&
(zColName[0] == 'r' && Jsi_Strcmp(zColName,"rowid") == 0)) {
numRid++;
}
}
/* Change first rowid to oid. */
if (numRid > 1) {
if (apColName != (char**)p->staticColNames) {
Jsi_Free(apColName[0]);
apColName[0] = Jsi_Strdup("oid");
} else {
Jsi_Strcpy(apColName[0], "oid");
}
}
p->apColName = apColName;
p->apColType = apColType;
}
}
if( papColName ) {
*papColName = p->apColName;
}
if( papColType ) {
*papColType = p->apColType;
}
if( pnCol ) {
*pnCol = p->nCol;
}
}
|
CWE-120
| null | 520,844 |
337352074491800880653070031059960609334
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_OpCodes *code_scatch(jsi_Pstate *p, jsi_Pline *line, const char *var) { JSI_NEW_CODESLN(0,OP_SCATCH, var); }
|
CWE-120
| null | 520,845 |
88634172918017975172043325859592956287
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
void Jsi_RegExpFree(Jsi_Regex* re) {
regfree(&re->reg);
_JSI_MEMCLEAR(re);
Jsi_Free(re);
}
|
CWE-120
| null | 520,846 |
160408553768672134234006875087965684115
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_OpCodes *code_eval(jsi_Pstate *p, jsi_Pline *line, int argc, Jsi_OpCodes *c) {
jsi_FreeOpcodes(c); // Eliminate leak of unused opcodes.
JSI_NEW_CODESLN(0,OP_EVAL, argc);
}
|
CWE-120
| null | 520,847 |
167362401823471434944223520409819138100
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
int Jsi_DecrRefCount(Jsi_Interp* interp, Jsi_Value *v) {
SIGASSERT(v,VALUE);
if (v->refCnt<=0) {
#ifdef JSI_MEM_DEBUG
fprintf(stderr, "Value decr with ref %d: VD.Idx=%d\n", v->refCnt, v->VD.Idx);
#endif
return -2;
}
int ref;
jsi_DebugValue(v,"Decr", jsi_DebugValueCallIdx(), interp);
if ((ref = --(v->refCnt)) <= 0) {
v->refCnt = -1;
Jsi_ValueFree(interp, v);
}
return ref;
}
|
CWE-120
| null | 520,848 |
178161553770608622780478518425151846498
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void NormalizeUnixPath(Jsi_Interp *interp, char *path) {
char **argv; int argc, i;
if (!Jsi_Strstr(path, "./")) return;
Jsi_DString dStr = {}, eStr = {};
if (path[0] != '/' && Jsi_Strstr(path, "..")) {
char *npath = Jsi_GetCwd(interp, &eStr);
if (npath && Jsi_Strcmp(npath,"/")) {
Jsi_DSAppend(&eStr, "/", path, NULL);
path = Jsi_DSValue(&eStr);
}
}
Jsi_DString sStr;
Jsi_DSInit(&sStr);
Jsi_SplitStr(path, &argc, &argv, "/", &sStr);
char *cp = path;
*cp = 0;
for (i=0; i<argc; i++) {
if (i == 0 && argv[0][0] == 0) {
continue;
} else if (argv[i][0] == 0) {
continue;
} else if (i && !Jsi_Strcmp(argv[i],".")) {
continue;
} else if (!Jsi_Strcmp(argv[i],"..")) {
char *pcp = Jsi_DSValue(&dStr), *lcp = pcp;
pcp = Jsi_Strrchr(pcp, '/');
if (pcp && pcp != Jsi_DSValue(&dStr)) {
*pcp = 0;
Jsi_DSSetLength(&dStr, Jsi_Strlen(lcp));
}
continue;
} else {
Jsi_DSAppend(&dStr, (i>0?"/":""), argv[i], NULL);
}
}
Jsi_DSFree(&sStr);
Jsi_Strcpy(path, Jsi_DSValue(&dStr));
Jsi_DSFree(&dStr);
Jsi_DSFree(&eStr);
}
|
CWE-120
| null | 520,849 |
306727425377773586713227803038295820506
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
void dbTypeNameHashInit(Jsi_Db *jdb) {
Jsi_Interp *interp = jdb->interp;
Jsi_Hash *hPtr = jdb->typeNameHash = Jsi_HashNew(interp, JSI_KEYS_STRING, NULL);
Jsi_HashSet(hPtr, (void*)"blob", (void*)JSI_OPTION_STRBUF);
Jsi_HashSet(hPtr, (void*)"string", (void*)JSI_OPTION_STRING);
Jsi_HashSet(hPtr, (void*)"double", (void*)JSI_OPTION_DOUBLE);
Jsi_HashSet(hPtr, (void*)"integer", (void*)JSI_OPTION_INT64);
Jsi_HashSet(hPtr, (void*)"bool", (void*)JSI_OPTION_BOOL);
Jsi_HashSet(hPtr, (void*)"time_d", (void*)JSI_OPTION_TIME_D);
Jsi_HashSet(hPtr, (void*)"time_w", (void*)JSI_OPTION_TIME_W);
Jsi_HashSet(hPtr, (void*)"time_t", (void*)JSI_OPTION_TIME_T);
Jsi_HashSet(hPtr, (void*)"date", (void*)JSI_OPTION_TIME_W);
Jsi_HashSet(hPtr, (void*)"time", (void*)JSI_OPTION_TIME_W);
Jsi_HashSet(hPtr, (void*)"datetime", (void*)JSI_OPTION_TIME_W);
}
|
CWE-120
| null | 520,850 |
41771294971745420749832661675544850938
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static int jsi_FSWriteProc(Jsi_Channel chan, const char *buf, int size) {
return fwrite(buf, 1, size, _JSI_GETFP(chan,0));
}
|
CWE-120
| null | 520,851 |
214117554182952700684312667999288867419
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_OpCodes *code_unref() { JSI_NEW_CODES(0,OP_UNREF, 0); }
|
CWE-120
| null | 520,852 |
131271809104035919825079183465539702471
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC FilesysWriteCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
int sum = 0, n, m;
UdfGet(udf, _this, funcPtr);
char *buf = Jsi_ValueArrayIndexToStr(interp, args, 0, &m);
if (!udf->filename) {
goto bail;
}
while (m > 0 && sum < MAX_LOOP_COUNT && (n = Jsi_Write(interp, udf->chan, buf, m)) > 0) {
/* TODO: limit max size. */
sum += n;
m -= n;
}
bail:
Jsi_ValueMakeNumber(interp, ret, (Jsi_Number)sum);
return JSI_OK;
}
|
CWE-120
| null | 520,853 |
40335412017752904868023924310755172998
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static jsi_JmpPopInfo *jpinfo_new(int off, int topop)
{
jsi_JmpPopInfo *r = (jsi_JmpPopInfo *)Jsi_Calloc(1, sizeof(*r));
r->off = off;
r->topop = topop;
return r;
}
|
CWE-120
| null | 520,854 |
176839203850547729934258750576290250586
| null | null |
other
|
retdec
|
517298bafaaff0a8e3dd60dd055a67c41b545807
| 0 |
llvm::SwitchInst* Decoder::transformToSwitch(
llvm::CallInst* pseudo,
llvm::Value* val,
llvm::BasicBlock* defaultBb,
const std::vector<llvm::BasicBlock*>& cases)
{
unsigned numCases = 0;
for (auto* c : cases)
{
if (c != defaultBb)
{
++numCases;
}
}
// If we do not do this, this can happen:
// "Instruction does not dominate all uses"
auto* insn = dyn_cast<Instruction>(val);
if (insn && insn->getType())
{
auto* gv = new GlobalVariable(
*insn->getModule(),
insn->getType(),
false,
GlobalValue::ExternalLinkage,
nullptr);
auto* s = new StoreInst(insn, gv);
s->insertAfter(insn);
val = new LoadInst(gv, "", pseudo);
}
auto* term = pseudo->getParent()->getTerminator();
assert(pseudo->getNextNode() == term);
auto* intType = cast<IntegerType>(val->getType());
auto* sw = SwitchInst::Create(val, defaultBb, numCases, term);
unsigned cntr = 0;
for (auto& c : cases)
{
if (c != defaultBb)
{
sw->addCase(ConstantInt::get(intType, cntr), c);
}
++cntr;
}
term->eraseFromParent();
return sw;
}
|
CWE-787
| null | 520,966 |
64325302912213818012957063436333323353
| null | null |
other
|
retdec
|
517298bafaaff0a8e3dd60dd055a67c41b545807
| 0 |
bool Decoder::canSplitFunctionOn(llvm::BasicBlock* bb)
{
for (auto* u : bb->users())
{
// All users must be unconditional branch instructions.
//
auto* br = dyn_cast<BranchInst>(u);
if (br == nullptr || br->isConditional())
{
LOG << "\t\t\t\t\t\t" << "!CAN : user not uncond for "
<< llvmObjToString(u)
<< ", user = " << llvmObjToString(br) << std::endl;
return false;
}
// Branch can not come from istruction right before basic block.
// This expects that such branches were created
// TODO: if
//
AsmInstruction brAsm(br);
AsmInstruction bbAsm(bb);
if (brAsm.getEndAddress() == bbAsm.getAddress())
{
LOG << "\t\t\t\t\t\t" << "branch from ASM insn right before: "
<< brAsm.getAddress() << " -> " << bbAsm.getAddress()
<< std::endl;
return false;
}
// BB must be true branch in all users.
//
// if (br->getSuccessor(0) != bb)
// {
// return false;
// }
}
return true;
}
|
CWE-787
| null | 520,967 |
70917799482309863435221416203876462104
| null | null |
other
|
retdec
|
517298bafaaff0a8e3dd60dd055a67c41b545807
| 0 |
llvm::Function* Decoder::splitFunctionOn(
utils::Address addr,
llvm::BasicBlock* splitOnBb)
{
LOG << "\t\t\t\t" << "S: splitFunctionOn @ " << addr << " on "
<< splitOnBb->getName().str() << std::endl;
if (splitOnBb->getPrevNode() == nullptr)
{
LOG << "\t\t\t\t" << "S: BB first @ " << addr << std::endl;
return splitOnBb->getParent();
}
std::set<BasicBlock*> newFncStarts;
if (!canSplitFunctionOn(addr, splitOnBb, newFncStarts))
{
LOG << "\t\t\t\t" << "S: !canSplitFunctionOn() @ " << addr << std::endl;
return nullptr;
}
llvm::Function* ret = nullptr;
std::set<Function*> newFncs;
for (auto* splitBb : newFncStarts)
{
Address splitAddr = getBasicBlockAddress(splitBb);
LOG << "\t\t\t\t" << "S: splitting @ " << splitAddr << " on "
<< splitBb->getName().str() << std::endl;
std::string name = _names->getPreferredNameForAddress(splitAddr);
if (name.empty())
{
name = names::generateFunctionName(splitAddr, _config->getConfig().isIda());
}
Function* oldFnc = splitBb->getParent();
Function* newFnc = Function::Create(
FunctionType::get(oldFnc->getReturnType(), false),
oldFnc->getLinkage(),
name);
oldFnc->getParent()->getFunctionList().insertAfter(
oldFnc->getIterator(),
newFnc);
addFunction(splitAddr, newFnc);
newFnc->getBasicBlockList().splice(
newFnc->begin(),
oldFnc->getBasicBlockList(),
splitBb->getIterator(),
oldFnc->getBasicBlockList().end());
newFncs.insert(oldFnc);
newFncs.insert(newFnc);
if (splitOnBb == splitBb)
{
ret = newFnc;
}
}
assert(ret);
for (Function* f : newFncs)
for (BasicBlock& b : *f)
{
auto* br = dyn_cast<BranchInst>(b.getTerminator());
if (br
&& (br->getSuccessor(0)->getParent() != br->getFunction()
|| br->getSuccessor(0)->getPrevNode() == nullptr))
{
auto* callee = br->getSuccessor(0)->getParent();
auto* c = CallInst::Create(callee, "", br);
if (auto* retObj = getCallReturnObject())
{
auto* cc = cast<Instruction>(
IrModifier::convertValueToTypeAfter(c, retObj->getValueType(), c));
auto* s = new StoreInst(cc, retObj);
s->insertAfter(cc);
}
ReturnInst::Create(
br->getModule()->getContext(),
UndefValue::get(br->getFunction()->getReturnType()),
br);
br->eraseFromParent();
}
// Test.
for (auto* s : successors(&b))
{
if (b.getParent() != s->getParent())
{
dumpModuleToFile(_module, _config->getOutputDirectory());
}
assert(b.getParent() == s->getParent());
}
}
return ret;
}
|
CWE-787
| null | 520,968 |
258444308870766831862205803170214876049
| null | null |
other
|
retdec
|
517298bafaaff0a8e3dd60dd055a67c41b545807
| 0 |
llvm::CallInst* Decoder::transformToCondCall(
llvm::CallInst* pseudo,
llvm::Value* cond,
llvm::Function* callee,
llvm::BasicBlock* falseBb)
{
auto* oldBb = pseudo->getParent();
auto* newBb = oldBb->splitBasicBlock(pseudo);
// We do NOT want to name or give address to this block.
auto* oldTerm = oldBb->getTerminator();
BranchInst::Create(newBb, falseBb, cond, oldTerm);
oldTerm->eraseFromParent();
auto* newTerm = newBb->getTerminator();
BranchInst::Create(falseBb, newTerm);
newTerm->eraseFromParent();
auto* c = CallInst::Create(callee);
c->insertAfter(pseudo);
return c;
}
|
CWE-787
| null | 520,969 |
34135905091989027508596513618111967706
| null | null |
other
|
retdec
|
517298bafaaff0a8e3dd60dd055a67c41b545807
| 0 |
llvm::Function* Decoder::splitFunctionOn(utils::Address addr)
{
if (auto* bb = getBasicBlockAtAddress(addr))
{
LOG << "\t\t\t\t" << "S: splitFunctionOn @ " << addr << std::endl;
return bb->getPrevNode()
? splitFunctionOn(addr, bb)
: bb->getParent();
}
// There is an instruction at address, but not BB -> do not split
// existing blocks to create functions.
//
else if (auto ai = AsmInstruction(_module, addr))
{
if (ai.isInvalid())
{
LOG << "\t\t\t\t" << "S: invalid ASM @ " << addr << std::endl;
return nullptr;
}
else
{
LOG << "\t\t\t\t" << "S: ASM @ " << addr << std::endl;
return nullptr;
}
}
else if (getFunctionContainingAddress(addr))
{
LOG << "\t\t\t\t" << "S: getFunctionContainingAddress() @ " << addr << std::endl;
auto* before = getBasicBlockBeforeAddress(addr);
assert(before);
auto* newBb = createBasicBlock(addr, before->getParent(), before);
return splitFunctionOn(addr, newBb);
}
else
{
LOG << "\t\t\t\t" << "S: createFunction() @ " << addr << std::endl;
return createFunction(addr);
}
}
|
CWE-787
| null | 520,970 |
90913152591173520365836434106778631943
| null | null |
other
|
retdec
|
517298bafaaff0a8e3dd60dd055a67c41b545807
| 0 |
llvm::GlobalVariable* Decoder::getCallReturnObject()
{
if (_config->getConfig().architecture.isX86_32())
{
return _abi->getRegister(X86_REG_EAX);
}
else if (_config->getConfig().architecture.isX86_64())
{
return _abi->getRegister(X86_REG_RAX);
}
else if (_config->getConfig().architecture.isMipsOrPic32())
{
return _abi->getRegister(MIPS_REG_V0);
}
else if (_config->getConfig().architecture.isPpc())
{
return _abi->getRegister(PPC_REG_R3);
}
else if (_config->getConfig().architecture.isArm32OrThumb())
{
return _abi->getRegister(ARM_REG_R0);
}
else if (_config->getConfig().architecture.isArm64())
{
return _config->getLlvmRegister("r0");
}
assert(false);
return nullptr;
}
|
CWE-787
| null | 520,971 |
194201201388244134187782940446750963442
| null | null |
other
|
retdec
|
517298bafaaff0a8e3dd60dd055a67c41b545807
| 0 |
void Decoder::getOrCreateCallTarget(
utils::Address addr,
llvm::Function*& tFnc,
llvm::BasicBlock*& tBb)
{
tBb = nullptr;
tFnc = nullptr;
if (auto* f = getFunctionAtAddress(addr))
{
tFnc = f;
tBb = tFnc->empty() ? nullptr : &tFnc->front();
LOG << "\t\t\t\t" << "F: getFunctionAtAddress() @ " << addr << std::endl;
}
else if (auto* f = splitFunctionOn(addr))
{
tFnc = f;
tBb = tFnc->empty() ? nullptr : &tFnc->front();
LOG << "\t\t\t\t" << "F: splitFunctionOn() @ " << addr << std::endl;
}
else if (auto* bb = getBasicBlockAtAddress(addr))
{
tBb = bb;
LOG << "\t\t\t\t" << "F: getBasicBlockAtAddress() @ " << addr << std::endl;
}
else if (getBasicBlockContainingAddress(addr))
{
// Nothing - we are not splitting BBs here.
LOG << "\t\t\t\t" << "F: getBasicBlockContainingAddress() @ "
<< addr << std::endl;
}
else if (getFunctionContainingAddress(addr))
{
auto* bb = getBasicBlockBeforeAddress(addr);
assert(bb);
tBb = createBasicBlock(addr, bb->getParent(), bb);
LOG << "\t\t\t\t" << "F: getFunctionContainingAddress() @ "
<< addr << std::endl;
}
else
{
tFnc = createFunction(addr);
tBb = tFnc && !tFnc->empty() ? &tFnc->front() : nullptr;
LOG << "\t\t\t\t" << "F: createFunction() @ "
<< addr << std::endl;
}
}
|
CWE-787
| null | 520,972 |
70078658160050780082053864823080284087
| null | null |
other
|
retdec
|
517298bafaaff0a8e3dd60dd055a67c41b545807
| 0 |
llvm::ReturnInst* Decoder::transformToReturn(llvm::CallInst* pseudo)
{
auto* term = pseudo->getParent()->getTerminator();
assert(pseudo->getNextNode() == term);
auto* r = ReturnInst::Create(
pseudo->getModule()->getContext(),
UndefValue::get(pseudo->getFunction()->getReturnType()),
term);
term->eraseFromParent();
return r;
}
|
CWE-787
| null | 520,973 |
37251372237368867650467181995349800225
| null | null |
other
|
retdec
|
517298bafaaff0a8e3dd60dd055a67c41b545807
| 0 |
llvm::BranchInst* Decoder::transformToBranch(
llvm::CallInst* pseudo,
llvm::BasicBlock* branchee)
{
auto* term = pseudo->getParent()->getTerminator();
assert(pseudo->getNextNode() == term);
auto* br = BranchInst::Create(branchee, term);
term->eraseFromParent();
return br;
}
|
CWE-787
| null | 520,974 |
337007638793569797285115178164446978227
| null | null |
other
|
retdec
|
517298bafaaff0a8e3dd60dd055a67c41b545807
| 0 |
llvm::CallInst* Decoder::transformToCall(
llvm::CallInst* pseudo,
llvm::Function* callee)
{
auto* c = CallInst::Create(callee);
c->insertAfter(pseudo);
if (auto* retObj = getCallReturnObject())
{
auto* cc = cast<Instruction>(
IrModifier::convertValueToTypeAfter(c, retObj->getValueType(), c));
auto* s = new StoreInst(cc, retObj);
s->insertAfter(cc);
}
return c;
}
|
CWE-787
| null | 520,975 |
98895435461726803553832243302846510610
| null | null |
other
|
retdec
|
517298bafaaff0a8e3dd60dd055a67c41b545807
| 0 |
bool Decoder::canSplitFunctionOn(
utils::Address addr,
llvm::BasicBlock* splitBb,
std::set<llvm::BasicBlock*>& newFncStarts)
{
newFncStarts.insert(splitBb);
auto* f = splitBb->getParent();
auto fAddr = getFunctionAddress(f);
auto fSzIt = _fnc2sz.find(f);
if (fSzIt != _fnc2sz.end())
{
if (fAddr <= addr && addr < (fAddr+fSzIt->second))
{
LOG << "\t\t\t\t\t" << "!CAN S: addr cond @ " << addr << std::endl;
return false;
}
}
std::set<Address> fncStarts;
fncStarts.insert(fAddr);
fncStarts.insert(addr);
LOG << "\t\t\t\t\t" << "CAN S: split @ " << fAddr << std::endl;
LOG << "\t\t\t\t\t" << "CAN S: split @ " << addr << std::endl;
bool changed = true;
while (changed)
{
changed = false;
for (BasicBlock& b : *f)
{
// Address bAddr = getBasicBlockAddress(&b);
Address bAddr;
// TODO: shitty
BasicBlock* bPrev = &b;
while (bAddr.isUndefined() && bPrev)
{
bAddr = getBasicBlockAddress(bPrev);
bPrev = bPrev->getPrevNode();
}
if (bAddr.isUndefined())
{
continue;
}
auto up = fncStarts.upper_bound(bAddr);
if (up == fncStarts.begin()) {
return false;
}
--up;
Address bFnc = *up;
for (auto* p : predecessors(&b))
{
// Address pAddr = getBasicBlockAddress(p);
Address pAddr;
// TODO: shitty
BasicBlock* pPrev = p;
while (pAddr.isUndefined() && pPrev)
{
pAddr = getBasicBlockAddress(pPrev);
pPrev = pPrev->getPrevNode();
}
if (pAddr.isUndefined())
{
continue;
}
auto up = fncStarts.upper_bound(pAddr);
if (up == fncStarts.begin()) {
return false;
}
--up;
Address pFnc = *up;
if (bFnc != pFnc)
{
if (!canSplitFunctionOn(&b))
{
return false;
}
changed |= newFncStarts.insert(&b).second;
changed |= fncStarts.insert(bAddr).second;
LOG << "\t\t\t\t\t" << "CAN S: split @ " << bAddr << std::endl;
}
}
}
}
return true;
}
|
CWE-787
| null | 520,976 |
233302201956625152068667191302051945266
| null | null |
other
|
retdec
|
517298bafaaff0a8e3dd60dd055a67c41b545807
| 0 |
void Decoder::getOrCreateBranchTarget(
utils::Address addr,
llvm::BasicBlock*& tBb,
llvm::Function*& tFnc,
llvm::Instruction* from)
{
tBb = nullptr;
tFnc = nullptr;
auto* fromFnc = from->getFunction();
if (auto* bb = getBasicBlockAtAddress(addr))
{
tBb = bb;
LOG << "\t\t\t\t" << "B: getBasicBlockAtAddress() @ " << addr << std::endl;
}
else if (getBasicBlockContainingAddress(addr))
{
auto ai = AsmInstruction(_module, addr);
if (ai.isInvalid())
{
// Target in existing block, but not at existing instruction.
// Something is wrong, nothing we can do.
LOG << "\t\t\t\t" << "B: invalid ASM @ " << addr << std::endl;
return;
}
else if (ai.getFunction() == fromFnc)
{
tBb = ai.makeStart();
addBasicBlock(addr, tBb);
LOG << "\t\t\t\t" << "B: addBasicBlock @ " << addr << std::endl;
}
else
{
// Target at existing instruction, but in different function.
// Do not split existing block in other functions here.
LOG << "\t\t\t\t" << "B: ASM in diff fnc @ " << addr << std::endl;
return;
}
}
// Function without BBs (e.g. import declarations).
else if (auto* targetFnc = getFunctionAtAddress(addr))
{
tFnc = targetFnc;
LOG << "\t\t\t\t" << "B: getFunctionAtAddress() @ " << addr << std::endl;
}
else if (auto* bb = getBasicBlockBeforeAddress(addr))
{
tBb = createBasicBlock(addr, bb->getParent(), bb);
LOG << "\t\t\t\t" << "B: getBasicBlockBeforeAddress() @ " << addr << std::endl;
}
else
{
tFnc = createFunction(addr);
tBb = tFnc && !tFnc->empty() ? &tFnc->front() : nullptr;
LOG << "\t\t\t\t" << "B: default @ " << addr << std::endl;
}
if (tBb && tBb->getPrevNode() == nullptr)
{
tFnc = tBb->getParent();
}
if (tBb && tBb->getParent() == fromFnc)
{
return;
}
if (tFnc)
{
return;
}
LOG << "\t\t\t\t" << "B: splitFunctionOn @ " << addr << std::endl;
tFnc = splitFunctionOn(addr);
tBb = tFnc && !tFnc->empty() ? &tFnc->front() : tBb;
}
|
CWE-787
| null | 520,977 |
336078973902674893622646251479919128860
| null | null |
other
|
retdec
|
517298bafaaff0a8e3dd60dd055a67c41b545807
| 0 |
llvm::BranchInst* Decoder::transformToCondBranch(
llvm::CallInst* pseudo,
llvm::Value* cond,
llvm::BasicBlock* trueBb,
llvm::BasicBlock* falseBb)
{
auto* term = pseudo->getParent()->getTerminator();
assert(pseudo->getNextNode() == term);
auto* br = BranchInst::Create(trueBb, falseBb, cond, term);
term->eraseFromParent();
return br;
}
|
CWE-787
| null | 520,978 |
78995073582086351102505189450027263404
| null | null |
other
|
oocborrt
|
539851c66778f68a244633985f6f8d0df94ea3b3
| 0 |
static int cborTagNotSupp (OSCTXT* pctxt, OSOCTET tag)
{
char numbuf[10];
char errtext[80];
rtxUIntToCharStr (tag, numbuf, sizeof(numbuf), 0);
rtxStrJoin (errtext, sizeof(errtext), "CBOR tag ", numbuf, 0, 0, 0);
rtxErrAddStrParm (pctxt, errtext);
return RTERR_NOTSUPP;
}
|
CWE-908
| null | 520,979 |
302806066688511386225935369114448004363
| null | null |
other
|
oocborrt
|
539851c66778f68a244633985f6f8d0df94ea3b3
| 0 |
static int cborElemNameToJson (OSCTXT* pCborCtxt, OSCTXT* pJsonCtxt)
{
char* pElemName = 0;
OSOCTET ub;
int ret;
/* Read byte from stream */
ret = rtxReadBytes (pCborCtxt, &ub, 1);
if (0 != ret) return LOG_RTERR (pCborCtxt, ret);
/* Decode element name (note: only string type is currently supported) */
ret = rtCborDecDynUTF8Str (pCborCtxt, ub, &pElemName);
if (0 != ret) return LOG_RTERR (pCborCtxt, ret);
/* Encode map element name as string */
ret = rtJsonEncStringValue (pJsonCtxt, (const OSUTF8CHAR*)pElemName);
rtxMemFreePtr (pCborCtxt, pElemName);
if (0 != ret) return LOG_RTERR (pJsonCtxt, ret);
OSRTSAFEPUTCHAR (pJsonCtxt, ':');
return 0;
}
|
CWE-908
| null | 520,980 |
91838581447491005893728128775518674702
| null | null |
other
|
oocborrt
|
539851c66778f68a244633985f6f8d0df94ea3b3
| 0 |
int main (int argc, char** argv)
{
OSCTXT jsonCtxt, cborCtxt;
OSOCTET* pMsgBuf = 0;
size_t msglen;
OSBOOL verbose = FALSE;
const char* filename = "message.cbor";
const char* outfname = "message.json";
int ret;
/* Process command line arguments */
if (argc > 1) {
int i;
for (i = 1; i < argc; i++) {
if (!strcmp (argv[i], "-v")) verbose = TRUE;
else if (!strcmp (argv[i], "-i")) filename = argv[++i];
else if (!strcmp (argv[i], "-o")) outfname = argv[++i];
else {
printf ("usage: cbor2json [-v] [-i <filename>] [-o filename]\n");
printf (" -v verbose mode: print trace info\n");
printf (" -i <filename> read CBOR msg from <filename>\n");
printf (" -o <filename> write JSON data to <filename>\n");
return 1;
}
}
}
/* Initialize context structures */
ret = rtxInitContext (&jsonCtxt);
if (ret != 0) {
rtxErrPrint (&jsonCtxt);
return ret;
}
rtxErrInit();
/* rtxSetDiag (&jsonCtxt, verbose); */
ret = rtxInitContext (&cborCtxt);
if (ret != 0) {
rtxErrPrint (&cborCtxt);
return ret;
}
/* rtxSetDiag (&cborCtxt, verbose); */
/* Create file input stream */
#if 0
/* Streaming not supported in open source version
ret = rtxStreamFileCreateReader (&jsonCtxt, filename);
*/
#else
/* Read input file into memory buffer */
ret = rtxFileReadBinary (&cborCtxt, filename, &pMsgBuf, &msglen);
if (0 == ret) {
ret = rtxInitContextBuffer (&cborCtxt, pMsgBuf, msglen);
}
#endif
if (0 != ret) {
rtxErrPrint (&jsonCtxt);
rtxFreeContext (&jsonCtxt);
rtxFreeContext (&cborCtxt);
return ret;
}
/* Init JSON output buffer */
ret = rtxInitContextBuffer (&jsonCtxt, 0, 0);
if (0 != ret) {
rtxErrPrint (&jsonCtxt);
rtxFreeContext (&jsonCtxt);
rtxFreeContext (&cborCtxt);
return ret;
}
/* Invoke the translation function */
ret = cbor2json (&cborCtxt, &jsonCtxt);
if (0 == ret && cborCtxt.level != 0)
ret = LOG_RTERR (&cborCtxt, RTERR_UNBAL);
if (0 == ret && 0 != outfname) {
/* Write encoded JSON data to output file */
OSRTSAFEPUTCHAR (&jsonCtxt, '\0'); /* null terminate buffer */
int fileret = rtxFileWriteText
(outfname, (const char*)jsonCtxt.buffer.data);
if (0 != fileret) {
printf ("unable to write message data to '%s', status = %d\n",
outfname, fileret);
}
}
if (0 != ret) {
rtxErrPrint (&jsonCtxt);
rtxErrPrint (&cborCtxt);
}
rtxFreeContext (&jsonCtxt);
rtxFreeContext (&cborCtxt);
return ret;
}
|
CWE-908
| null | 520,981 |
99441021234785124365928056219319899125
| null | null |
other
|
oocborrt
|
539851c66778f68a244633985f6f8d0df94ea3b3
| 0 |
static int cbor2json (OSCTXT* pCborCtxt, OSCTXT* pJsonCtxt)
{
int ret = 0;
OSOCTET tag, ub;
/* Read byte from stream */
ret = rtxReadBytes (pCborCtxt, &ub, 1);
if (0 != ret) return LOG_RTERR (pCborCtxt, ret);
tag = ub >> 5;
/* Switch on tag value */
switch (tag) {
case OSRTCBOR_UINT: {
OSUINTTYPE value;
ret = rtCborDecUInt (pCborCtxt, ub, &value);
if (0 != ret) return LOG_RTERR (pCborCtxt, ret);
/* Encode JSON */
#ifndef _NO_INT64_SUPPORT
ret = rtJsonEncUInt64Value (pJsonCtxt, value);
#else
ret = rtJsonEncUIntValue (pJsonCtxt, value);
#endif
if (0 != ret) return LOG_RTERR (pJsonCtxt, ret);
break;
}
case OSRTCBOR_NEGINT: {
OSINTTYPE value;
ret = rtCborDecInt (pCborCtxt, ub, &value);
if (0 != ret) return LOG_RTERR (pCborCtxt, ret);
/* Encode JSON */
#ifndef _NO_INT64_SUPPORT
ret = rtJsonEncInt64Value (pJsonCtxt, value);
#else
ret = rtJsonEncIntValue (pJsonCtxt, value);
#endif
if (0 != ret) return LOG_RTERR (pJsonCtxt, ret);
break;
}
case OSRTCBOR_BYTESTR: {
OSDynOctStr64 byteStr;
ret = rtCborDecDynByteStr (pCborCtxt, ub, &byteStr);
if (0 != ret) return LOG_RTERR (pCborCtxt, ret);
/* Encode JSON */
ret = rtJsonEncHexStr (pJsonCtxt, byteStr.numocts, byteStr.data);
rtxMemFreePtr (pCborCtxt, byteStr.data);
if (0 != ret) return LOG_RTERR (pJsonCtxt, ret);
break;
}
case OSRTCBOR_UTF8STR: {
OSUTF8CHAR* utf8str;
ret = rtCborDecDynUTF8Str (pCborCtxt, ub, (char**)&utf8str);
if (0 != ret) return LOG_RTERR (pCborCtxt, ret);
ret = rtJsonEncStringValue (pJsonCtxt, utf8str);
rtxMemFreePtr (pCborCtxt, utf8str);
if (0 != ret) return LOG_RTERR (pJsonCtxt, ret);
break;
}
case OSRTCBOR_ARRAY:
case OSRTCBOR_MAP: {
OSOCTET len = ub & 0x1F;
char startChar = (tag == OSRTCBOR_ARRAY) ? '[' : '{';
char endChar = (tag == OSRTCBOR_ARRAY) ? ']' : '}';
OSRTSAFEPUTCHAR (pJsonCtxt, startChar);
if (len == OSRTCBOR_INDEF) {
OSBOOL first = TRUE;
for (;;) {
if (OSRTCBOR_MATCHEOC (pCborCtxt)) {
pCborCtxt->buffer.byteIndex++;
break;
}
if (!first)
OSRTSAFEPUTCHAR (pJsonCtxt, ',');
else
first = FALSE;
/* If map, decode object name */
if (tag == OSRTCBOR_MAP) {
ret = cborElemNameToJson (pCborCtxt, pJsonCtxt);
}
/* Make recursive call */
if (0 == ret)
ret = cbor2json (pCborCtxt, pJsonCtxt);
if (0 != ret) {
OSCTXT* pctxt =
(rtxErrGetErrorCnt(pJsonCtxt) > 0) ? pJsonCtxt : pCborCtxt;
return LOG_RTERR (pctxt, ret);
}
}
}
else { /* definite length */
OSSIZE nitems;
/* Decode tag and number of items */
ret = rtCborDecSize (pCborCtxt, len, &nitems);
if (0 == ret) {
OSSIZE i;
/* Loop to decode array items */
for (i = 0; i < nitems; i++) {
if (0 != i) OSRTSAFEPUTCHAR (pJsonCtxt, ',');
/* If map, decode object name */
if (tag == OSRTCBOR_MAP) {
ret = cborElemNameToJson (pCborCtxt, pJsonCtxt);
}
/* Make recursive call */
if (0 == ret)
ret = cbor2json (pCborCtxt, pJsonCtxt);
if (0 != ret) {
OSCTXT* pctxt =
(rtxErrGetErrorCnt(pJsonCtxt) > 0) ? pJsonCtxt : pCborCtxt;
return LOG_RTERR (pctxt, ret);
}
}
}
}
OSRTSAFEPUTCHAR (pJsonCtxt, endChar);
break;
}
case OSRTCBOR_FLOAT:
if (tag == OSRTCBOR_FALSEENC || tag == OSRTCBOR_TRUEENC) {
OSBOOL boolval = (ub == OSRTCBOR_TRUEENC) ? TRUE : FALSE;
ret = rtJsonEncBoolValue (pJsonCtxt, boolval);
if (0 != ret) return LOG_RTERR (pJsonCtxt, ret);
}
else if (tag == OSRTCBOR_FLT16ENC ||
tag == OSRTCBOR_FLT32ENC ||
tag == OSRTCBOR_FLT64ENC) {
OSDOUBLE fltval;
ret = rtCborDecFloat (pCborCtxt, ub, &fltval);
if (0 != ret) return LOG_RTERR (pCborCtxt, ret);
/* Encode JSON */
ret = rtJsonEncDoubleValue (pJsonCtxt, fltval, 0);
if (0 != ret) return LOG_RTERR (pJsonCtxt, ret);
}
else {
ret = cborTagNotSupp (pCborCtxt, tag);
}
break;
default:
ret = cborTagNotSupp (pCborCtxt, tag);
}
return ret;
}
|
CWE-908
| null | 520,982 |
110318887320859724419832151719883220577
| null | null |
other
|
sqlcipher
|
cb71f53e8cea4802509f182fa5bead0ac6ab0e7f
| 0 |
int sqlcipher_codec_pragma(sqlite3* db, int iDb, Parse *pParse, const char *zLeft, const char *zRight) {
struct Db *pDb = &db->aDb[iDb];
codec_ctx *ctx = NULL;
int rc;
if(pDb->pBt) {
ctx = (codec_ctx*) sqlite3PagerGetCodec(pDb->pBt->pBt->pPager);
}
CODEC_TRACE("sqlcipher_codec_pragma: entered db=%p iDb=%d pParse=%p zLeft=%s zRight=%s ctx=%p\n", db, iDb, pParse, zLeft, zRight, ctx);
#ifdef SQLCIPHER_EXT
if( sqlite3StrICmp(zLeft, "cipher_license")==0 && zRight ){
char *license_result = sqlite3_mprintf("%d", sqlcipher_license_key(zRight));
codec_vdbe_return_string(pParse, "cipher_license", license_result, P4_DYNAMIC);
} else
if( sqlite3StrICmp(zLeft, "cipher_license")==0 && !zRight ){
if(ctx) {
char *license_result = sqlite3_mprintf("%d", ctx
? sqlcipher_license_key_status(ctx->provider)
: SQLITE_ERROR);
codec_vdbe_return_string(pParse, "cipher_license", license_result, P4_DYNAMIC);
}
} else
#endif
#ifdef SQLCIPHER_TEST
if( sqlite3StrICmp(zLeft,"cipher_fail_next_encrypt")==0 ){
if( zRight ) {
cipher_fail_next_encrypt = sqlite3GetBoolean(zRight,1);
} else {
char *fail = sqlite3_mprintf("%d", cipher_fail_next_encrypt);
codec_vdbe_return_string(pParse, "cipher_fail_next_encrypt", fail, P4_DYNAMIC);
}
}else
if( sqlite3StrICmp(zLeft,"cipher_fail_next_decrypt")==0 ){
if( zRight ) {
cipher_fail_next_decrypt = sqlite3GetBoolean(zRight,1);
} else {
char *fail = sqlite3_mprintf("%d", cipher_fail_next_decrypt);
codec_vdbe_return_string(pParse, "cipher_fail_next_decrypt", fail, P4_DYNAMIC);
}
}else
#endif
if( sqlite3StrICmp(zLeft, "cipher_fips_status")== 0 && !zRight ){
if(ctx) {
char *fips_mode_status = sqlite3_mprintf("%d", sqlcipher_codec_fips_status(ctx));
codec_vdbe_return_string(pParse, "cipher_fips_status", fips_mode_status, P4_DYNAMIC);
}
} else
if( sqlite3StrICmp(zLeft, "cipher_store_pass")==0 && zRight ) {
if(ctx) {
char *deprecation = "PRAGMA cipher_store_pass is deprecated, please remove from use";
sqlcipher_codec_set_store_pass(ctx, sqlite3GetBoolean(zRight, 1));
codec_vdbe_return_string(pParse, "cipher_store_pass", deprecation, P4_TRANSIENT);
sqlite3_log(SQLITE_WARNING, deprecation);
}
} else
if( sqlite3StrICmp(zLeft, "cipher_store_pass")==0 && !zRight ) {
if(ctx){
char *store_pass_value = sqlite3_mprintf("%d", sqlcipher_codec_get_store_pass(ctx));
codec_vdbe_return_string(pParse, "cipher_store_pass", store_pass_value, P4_DYNAMIC);
}
}
if( sqlite3StrICmp(zLeft, "cipher_profile")== 0 && zRight ){
char *profile_status = sqlite3_mprintf("%d", sqlcipher_cipher_profile(db, zRight));
codec_vdbe_return_string(pParse, "cipher_profile", profile_status, P4_DYNAMIC);
} else
if( sqlite3StrICmp(zLeft, "cipher_add_random")==0 && zRight ){
if(ctx) {
char *add_random_status = sqlite3_mprintf("%d", sqlcipher_codec_add_random(ctx, zRight, sqlite3Strlen30(zRight)));
codec_vdbe_return_string(pParse, "cipher_add_random", add_random_status, P4_DYNAMIC);
}
} else
if( sqlite3StrICmp(zLeft, "cipher_migrate")==0 && !zRight ){
if(ctx){
char *migrate_status = sqlite3_mprintf("%d", sqlcipher_codec_ctx_migrate(ctx));
codec_vdbe_return_string(pParse, "cipher_migrate", migrate_status, P4_DYNAMIC);
}
} else
if( sqlite3StrICmp(zLeft, "cipher_provider")==0 && !zRight ){
if(ctx) { codec_vdbe_return_string(pParse, "cipher_provider",
sqlcipher_codec_get_cipher_provider(ctx), P4_TRANSIENT);
}
} else
if( sqlite3StrICmp(zLeft, "cipher_provider_version")==0 && !zRight){
if(ctx) { codec_vdbe_return_string(pParse, "cipher_provider_version",
sqlcipher_codec_get_provider_version(ctx), P4_TRANSIENT);
}
} else
if( sqlite3StrICmp(zLeft, "cipher_version")==0 && !zRight ){
codec_vdbe_return_string(pParse, "cipher_version", sqlcipher_version(), P4_DYNAMIC);
}else
if( sqlite3StrICmp(zLeft, "cipher")==0 ){
if(ctx) {
if( zRight ) {
const char* message = "PRAGMA cipher is no longer supported.";
codec_vdbe_return_string(pParse, "cipher", message, P4_TRANSIENT);
sqlite3_log(SQLITE_WARNING, message);
}else {
codec_vdbe_return_string(pParse, "cipher", sqlcipher_codec_ctx_get_cipher(ctx), P4_TRANSIENT);
}
}
}else
if( sqlite3StrICmp(zLeft, "rekey_cipher")==0 && zRight ){
const char* message = "PRAGMA rekey_cipher is no longer supported.";
codec_vdbe_return_string(pParse, "rekey_cipher", message, P4_TRANSIENT);
sqlite3_log(SQLITE_WARNING, message);
}else
if( sqlite3StrICmp(zLeft,"cipher_default_kdf_iter")==0 ){
if( zRight ) {
sqlcipher_set_default_kdf_iter(atoi(zRight)); /* change default KDF iterations */
} else {
char *kdf_iter = sqlite3_mprintf("%d", sqlcipher_get_default_kdf_iter());
codec_vdbe_return_string(pParse, "cipher_default_kdf_iter", kdf_iter, P4_DYNAMIC);
}
}else
if( sqlite3StrICmp(zLeft, "kdf_iter")==0 ){
if(ctx) {
if( zRight ) {
sqlcipher_codec_ctx_set_kdf_iter(ctx, atoi(zRight)); /* change of RW PBKDF2 iteration */
} else {
char *kdf_iter = sqlite3_mprintf("%d", sqlcipher_codec_ctx_get_kdf_iter(ctx));
codec_vdbe_return_string(pParse, "kdf_iter", kdf_iter, P4_DYNAMIC);
}
}
}else
if( sqlite3StrICmp(zLeft, "fast_kdf_iter")==0){
if(ctx) {
if( zRight ) {
char *deprecation = "PRAGMA fast_kdf_iter is deprecated, please remove from use";
sqlcipher_codec_ctx_set_fast_kdf_iter(ctx, atoi(zRight)); /* change of RW PBKDF2 iteration */
codec_vdbe_return_string(pParse, "fast_kdf_iter", deprecation, P4_TRANSIENT);
sqlite3_log(SQLITE_WARNING, deprecation);
} else {
char *fast_kdf_iter = sqlite3_mprintf("%d", sqlcipher_codec_ctx_get_fast_kdf_iter(ctx));
codec_vdbe_return_string(pParse, "fast_kdf_iter", fast_kdf_iter, P4_DYNAMIC);
}
}
}else
if( sqlite3StrICmp(zLeft, "rekey_kdf_iter")==0 && zRight ){
const char* message = "PRAGMA rekey_kdf_iter is no longer supported.";
codec_vdbe_return_string(pParse, "rekey_kdf_iter", message, P4_TRANSIENT);
sqlite3_log(SQLITE_WARNING, message);
}else
if( sqlite3StrICmp(zLeft,"cipher_page_size")==0 ){
if(ctx) {
if( zRight ) {
int size = atoi(zRight);
rc = sqlcipher_codec_ctx_set_pagesize(ctx, size);
if(rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, rc);
rc = codec_set_btree_to_codec_pagesize(db, pDb, ctx);
if(rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, rc);
} else {
char * page_size = sqlite3_mprintf("%d", sqlcipher_codec_ctx_get_pagesize(ctx));
codec_vdbe_return_string(pParse, "cipher_page_size", page_size, P4_DYNAMIC);
}
}
}else
if( sqlite3StrICmp(zLeft,"cipher_default_page_size")==0 ){
if( zRight ) {
sqlcipher_set_default_pagesize(atoi(zRight));
} else {
char *default_page_size = sqlite3_mprintf("%d", sqlcipher_get_default_pagesize());
codec_vdbe_return_string(pParse, "cipher_default_page_size", default_page_size, P4_DYNAMIC);
}
}else
if( sqlite3StrICmp(zLeft,"cipher_default_use_hmac")==0 ){
if( zRight ) {
sqlcipher_set_default_use_hmac(sqlite3GetBoolean(zRight,1));
} else {
char *default_use_hmac = sqlite3_mprintf("%d", sqlcipher_get_default_use_hmac());
codec_vdbe_return_string(pParse, "cipher_default_use_hmac", default_use_hmac, P4_DYNAMIC);
}
}else
if( sqlite3StrICmp(zLeft,"cipher_use_hmac")==0 ){
if(ctx) {
if( zRight ) {
rc = sqlcipher_codec_ctx_set_use_hmac(ctx, sqlite3GetBoolean(zRight,1));
if(rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, rc);
/* since the use of hmac has changed, the page size may also change */
rc = codec_set_btree_to_codec_pagesize(db, pDb, ctx);
if(rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, rc);
} else {
char *hmac_flag = sqlite3_mprintf("%d", sqlcipher_codec_ctx_get_use_hmac(ctx));
codec_vdbe_return_string(pParse, "cipher_use_hmac", hmac_flag, P4_DYNAMIC);
}
}
}else
if( sqlite3StrICmp(zLeft,"cipher_hmac_pgno")==0 ){
if(ctx) {
if(zRight) {
char *deprecation = "PRAGMA cipher_hmac_pgno is deprecated, please remove from use";
/* clear both pgno endian flags */
if(sqlite3StrICmp(zRight, "le") == 0) {
sqlcipher_codec_ctx_unset_flag(ctx, CIPHER_FLAG_BE_PGNO);
sqlcipher_codec_ctx_set_flag(ctx, CIPHER_FLAG_LE_PGNO);
} else if(sqlite3StrICmp(zRight, "be") == 0) {
sqlcipher_codec_ctx_unset_flag(ctx, CIPHER_FLAG_LE_PGNO);
sqlcipher_codec_ctx_set_flag(ctx, CIPHER_FLAG_BE_PGNO);
} else if(sqlite3StrICmp(zRight, "native") == 0) {
sqlcipher_codec_ctx_unset_flag(ctx, CIPHER_FLAG_LE_PGNO);
sqlcipher_codec_ctx_unset_flag(ctx, CIPHER_FLAG_BE_PGNO);
}
codec_vdbe_return_string(pParse, "cipher_hmac_pgno", deprecation, P4_TRANSIENT);
sqlite3_log(SQLITE_WARNING, deprecation);
} else {
if(sqlcipher_codec_ctx_get_flag(ctx, CIPHER_FLAG_LE_PGNO)) {
codec_vdbe_return_string(pParse, "cipher_hmac_pgno", "le", P4_TRANSIENT);
} else if(sqlcipher_codec_ctx_get_flag(ctx, CIPHER_FLAG_BE_PGNO)) {
codec_vdbe_return_string(pParse, "cipher_hmac_pgno", "be", P4_TRANSIENT);
} else {
codec_vdbe_return_string(pParse, "cipher_hmac_pgno", "native", P4_TRANSIENT);
}
}
}
}else
if( sqlite3StrICmp(zLeft,"cipher_hmac_salt_mask")==0 ){
if(ctx) {
if(zRight) {
char *deprecation = "PRAGMA cipher_hmac_salt_mask is deprecated, please remove from use";
if (sqlite3StrNICmp(zRight ,"x'", 2) == 0 && sqlite3Strlen30(zRight) == 5) {
unsigned char mask = 0;
const unsigned char *hex = (const unsigned char *)zRight+2;
cipher_hex2bin(hex,2,&mask);
sqlcipher_set_hmac_salt_mask(mask);
}
codec_vdbe_return_string(pParse, "cipher_hmac_salt_mask", deprecation, P4_TRANSIENT);
sqlite3_log(SQLITE_WARNING, deprecation);
} else {
char *hmac_salt_mask = sqlite3_mprintf("%02x", sqlcipher_get_hmac_salt_mask());
codec_vdbe_return_string(pParse, "cipher_hmac_salt_mask", hmac_salt_mask, P4_DYNAMIC);
}
}
}else
if( sqlite3StrICmp(zLeft,"cipher_plaintext_header_size")==0 ){
if(ctx) {
if( zRight ) {
int size = atoi(zRight);
/* deliberately ignore result code, if size is invalid it will be set to -1
and trip the error later in the codec */
sqlcipher_codec_ctx_set_plaintext_header_size(ctx, size);
} else {
char *size = sqlite3_mprintf("%d", sqlcipher_codec_ctx_get_plaintext_header_size(ctx));
codec_vdbe_return_string(pParse, "cipher_plaintext_header_size", size, P4_DYNAMIC);
}
}
}else
if( sqlite3StrICmp(zLeft,"cipher_default_plaintext_header_size")==0 ){
if( zRight ) {
sqlcipher_set_default_plaintext_header_size(atoi(zRight));
} else {
char *size = sqlite3_mprintf("%d", sqlcipher_get_default_plaintext_header_size());
codec_vdbe_return_string(pParse, "cipher_default_plaintext_header_size", size, P4_DYNAMIC);
}
}else
if( sqlite3StrICmp(zLeft,"cipher_salt")==0 ){
if(ctx) {
if(zRight) {
if (sqlite3StrNICmp(zRight ,"x'", 2) == 0 && sqlite3Strlen30(zRight) == (FILE_HEADER_SZ*2)+3) {
unsigned char *salt = (unsigned char*) sqlite3_malloc(FILE_HEADER_SZ);
const unsigned char *hex = (const unsigned char *)zRight+2;
cipher_hex2bin(hex,FILE_HEADER_SZ*2,salt);
sqlcipher_codec_ctx_set_kdf_salt(ctx, salt, FILE_HEADER_SZ);
sqlite3_free(salt);
}
} else {
void *salt;
char *hexsalt = (char*) sqlite3_malloc((FILE_HEADER_SZ*2)+1);
if((rc = sqlcipher_codec_ctx_get_kdf_salt(ctx, &salt)) == SQLITE_OK) {
cipher_bin2hex(salt, FILE_HEADER_SZ, hexsalt);
codec_vdbe_return_string(pParse, "cipher_salt", hexsalt, P4_DYNAMIC);
} else {
sqlite3_free(hexsalt);
sqlcipher_codec_ctx_set_error(ctx, rc);
}
}
}
}else
if( sqlite3StrICmp(zLeft,"cipher_hmac_algorithm")==0 ){
if(ctx) {
if(zRight) {
rc = SQLITE_ERROR;
if(sqlite3StrICmp(zRight, SQLCIPHER_HMAC_SHA1_LABEL) == 0) {
rc = sqlcipher_codec_ctx_set_hmac_algorithm(ctx, SQLCIPHER_HMAC_SHA1);
} else if(sqlite3StrICmp(zRight, SQLCIPHER_HMAC_SHA256_LABEL) == 0) {
rc = sqlcipher_codec_ctx_set_hmac_algorithm(ctx, SQLCIPHER_HMAC_SHA256);
} else if(sqlite3StrICmp(zRight, SQLCIPHER_HMAC_SHA512_LABEL) == 0) {
rc = sqlcipher_codec_ctx_set_hmac_algorithm(ctx, SQLCIPHER_HMAC_SHA512);
}
if (rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR);
rc = codec_set_btree_to_codec_pagesize(db, pDb, ctx);
if (rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR);
} else {
int algorithm = sqlcipher_codec_ctx_get_hmac_algorithm(ctx);
if(algorithm == SQLCIPHER_HMAC_SHA1) {
codec_vdbe_return_string(pParse, "cipher_hmac_algorithm", SQLCIPHER_HMAC_SHA1_LABEL, P4_TRANSIENT);
} else if(algorithm == SQLCIPHER_HMAC_SHA256) {
codec_vdbe_return_string(pParse, "cipher_hmac_algorithm", SQLCIPHER_HMAC_SHA256_LABEL, P4_TRANSIENT);
} else if(algorithm == SQLCIPHER_HMAC_SHA512) {
codec_vdbe_return_string(pParse, "cipher_hmac_algorithm", SQLCIPHER_HMAC_SHA512_LABEL, P4_TRANSIENT);
}
}
}
}else
if( sqlite3StrICmp(zLeft,"cipher_default_hmac_algorithm")==0 ){
if(zRight) {
rc = SQLITE_ERROR;
if(sqlite3StrICmp(zRight, SQLCIPHER_HMAC_SHA1_LABEL) == 0) {
rc = sqlcipher_set_default_hmac_algorithm(SQLCIPHER_HMAC_SHA1);
} else if(sqlite3StrICmp(zRight, SQLCIPHER_HMAC_SHA256_LABEL) == 0) {
rc = sqlcipher_set_default_hmac_algorithm(SQLCIPHER_HMAC_SHA256);
} else if(sqlite3StrICmp(zRight, SQLCIPHER_HMAC_SHA512_LABEL) == 0) {
rc = sqlcipher_set_default_hmac_algorithm(SQLCIPHER_HMAC_SHA512);
}
} else {
int algorithm = sqlcipher_get_default_hmac_algorithm();
if(algorithm == SQLCIPHER_HMAC_SHA1) {
codec_vdbe_return_string(pParse, "cipher_default_hmac_algorithm", SQLCIPHER_HMAC_SHA1_LABEL, P4_TRANSIENT);
} else if(algorithm == SQLCIPHER_HMAC_SHA256) {
codec_vdbe_return_string(pParse, "cipher_default_hmac_algorithm", SQLCIPHER_HMAC_SHA256_LABEL, P4_TRANSIENT);
} else if(algorithm == SQLCIPHER_HMAC_SHA512) {
codec_vdbe_return_string(pParse, "cipher_default_hmac_algorithm", SQLCIPHER_HMAC_SHA512_LABEL, P4_TRANSIENT);
}
}
}else
if( sqlite3StrICmp(zLeft,"cipher_kdf_algorithm")==0 ){
if(ctx) {
if(zRight) {
rc = SQLITE_ERROR;
if(sqlite3StrICmp(zRight, SQLCIPHER_PBKDF2_HMAC_SHA1_LABEL) == 0) {
rc = sqlcipher_codec_ctx_set_kdf_algorithm(ctx, SQLCIPHER_PBKDF2_HMAC_SHA1);
} else if(sqlite3StrICmp(zRight, SQLCIPHER_PBKDF2_HMAC_SHA256_LABEL) == 0) {
rc = sqlcipher_codec_ctx_set_kdf_algorithm(ctx, SQLCIPHER_PBKDF2_HMAC_SHA256);
} else if(sqlite3StrICmp(zRight, SQLCIPHER_PBKDF2_HMAC_SHA512_LABEL) == 0) {
rc = sqlcipher_codec_ctx_set_kdf_algorithm(ctx, SQLCIPHER_PBKDF2_HMAC_SHA512);
}
if (rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR);
} else {
int algorithm = sqlcipher_codec_ctx_get_kdf_algorithm(ctx);
if(algorithm == SQLCIPHER_PBKDF2_HMAC_SHA1) {
codec_vdbe_return_string(pParse, "cipher_kdf_algorithm", SQLCIPHER_PBKDF2_HMAC_SHA1_LABEL, P4_TRANSIENT);
} else if(algorithm == SQLCIPHER_PBKDF2_HMAC_SHA256) {
codec_vdbe_return_string(pParse, "cipher_kdf_algorithm", SQLCIPHER_PBKDF2_HMAC_SHA256_LABEL, P4_TRANSIENT);
} else if(algorithm == SQLCIPHER_PBKDF2_HMAC_SHA512) {
codec_vdbe_return_string(pParse, "cipher_kdf_algorithm", SQLCIPHER_PBKDF2_HMAC_SHA512_LABEL, P4_TRANSIENT);
}
}
}
}else
if( sqlite3StrICmp(zLeft,"cipher_default_kdf_algorithm")==0 ){
if(zRight) {
rc = SQLITE_ERROR;
if(sqlite3StrICmp(zRight, SQLCIPHER_PBKDF2_HMAC_SHA1_LABEL) == 0) {
rc = sqlcipher_set_default_kdf_algorithm(SQLCIPHER_PBKDF2_HMAC_SHA1);
} else if(sqlite3StrICmp(zRight, SQLCIPHER_PBKDF2_HMAC_SHA256_LABEL) == 0) {
rc = sqlcipher_set_default_kdf_algorithm(SQLCIPHER_PBKDF2_HMAC_SHA256);
} else if(sqlite3StrICmp(zRight, SQLCIPHER_PBKDF2_HMAC_SHA512_LABEL) == 0) {
rc = sqlcipher_set_default_kdf_algorithm(SQLCIPHER_PBKDF2_HMAC_SHA512);
}
} else {
int algorithm = sqlcipher_get_default_kdf_algorithm();
if(algorithm == SQLCIPHER_PBKDF2_HMAC_SHA1) {
codec_vdbe_return_string(pParse, "cipher_default_kdf_algorithm", SQLCIPHER_PBKDF2_HMAC_SHA1_LABEL, P4_TRANSIENT);
} else if(algorithm == SQLCIPHER_PBKDF2_HMAC_SHA256) {
codec_vdbe_return_string(pParse, "cipher_default_kdf_algorithm", SQLCIPHER_PBKDF2_HMAC_SHA256_LABEL, P4_TRANSIENT);
} else if(algorithm == SQLCIPHER_PBKDF2_HMAC_SHA512) {
codec_vdbe_return_string(pParse, "cipher_default_kdf_algorithm", SQLCIPHER_PBKDF2_HMAC_SHA512_LABEL, P4_TRANSIENT);
}
}
}else
if( sqlite3StrICmp(zLeft,"cipher_compatibility")==0 ){
if(ctx) {
if(zRight) {
int version = atoi(zRight);
switch(version) {
case 1:
rc = sqlcipher_codec_ctx_set_pagesize(ctx, 1024);
if (rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR);
rc = sqlcipher_codec_ctx_set_hmac_algorithm(ctx, SQLCIPHER_HMAC_SHA1);
if (rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR);
rc = sqlcipher_codec_ctx_set_kdf_algorithm(ctx, SQLCIPHER_PBKDF2_HMAC_SHA1);
if (rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR);
rc = sqlcipher_codec_ctx_set_kdf_iter(ctx, 4000);
if (rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR);
rc = sqlcipher_codec_ctx_set_use_hmac(ctx, 0);
if (rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR);
break;
case 2:
rc = sqlcipher_codec_ctx_set_pagesize(ctx, 1024);
if (rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR);
rc = sqlcipher_codec_ctx_set_hmac_algorithm(ctx, SQLCIPHER_HMAC_SHA1);
if (rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR);
rc = sqlcipher_codec_ctx_set_kdf_algorithm(ctx, SQLCIPHER_PBKDF2_HMAC_SHA1);
if (rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR);
rc = sqlcipher_codec_ctx_set_kdf_iter(ctx, 4000);
if (rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR);
rc = sqlcipher_codec_ctx_set_use_hmac(ctx, 1);
if (rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR);
break;
case 3:
rc = sqlcipher_codec_ctx_set_pagesize(ctx, 1024);
if (rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR);
rc = sqlcipher_codec_ctx_set_hmac_algorithm(ctx, SQLCIPHER_HMAC_SHA1);
if (rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR);
rc = sqlcipher_codec_ctx_set_kdf_algorithm(ctx, SQLCIPHER_PBKDF2_HMAC_SHA1);
if (rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR);
rc = sqlcipher_codec_ctx_set_kdf_iter(ctx, 64000);
if (rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR);
rc = sqlcipher_codec_ctx_set_use_hmac(ctx, 1);
if (rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR);
break;
default:
rc = sqlcipher_codec_ctx_set_pagesize(ctx, 4096);
if (rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR);
rc = sqlcipher_codec_ctx_set_hmac_algorithm(ctx, SQLCIPHER_HMAC_SHA512);
if (rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR);
rc = sqlcipher_codec_ctx_set_kdf_algorithm(ctx, SQLCIPHER_PBKDF2_HMAC_SHA512);
if (rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR);
rc = sqlcipher_codec_ctx_set_kdf_iter(ctx, 256000);
if (rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR);
rc = sqlcipher_codec_ctx_set_use_hmac(ctx, 1);
if (rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR);
break;
}
rc = codec_set_btree_to_codec_pagesize(db, pDb, ctx);
if (rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR);
}
}
}else
if( sqlite3StrICmp(zLeft,"cipher_default_compatibility")==0 ){
if(zRight) {
int version = atoi(zRight);
switch(version) {
case 1:
sqlcipher_set_default_pagesize(1024);
sqlcipher_set_default_hmac_algorithm(SQLCIPHER_HMAC_SHA1);
sqlcipher_set_default_kdf_algorithm(SQLCIPHER_PBKDF2_HMAC_SHA1);
sqlcipher_set_default_kdf_iter(4000);
sqlcipher_set_default_use_hmac(0);
break;
case 2:
sqlcipher_set_default_pagesize(1024);
sqlcipher_set_default_hmac_algorithm(SQLCIPHER_HMAC_SHA1);
sqlcipher_set_default_kdf_algorithm(SQLCIPHER_PBKDF2_HMAC_SHA1);
sqlcipher_set_default_kdf_iter(4000);
sqlcipher_set_default_use_hmac(1);
break;
case 3:
sqlcipher_set_default_pagesize(1024);
sqlcipher_set_default_hmac_algorithm(SQLCIPHER_HMAC_SHA1);
sqlcipher_set_default_kdf_algorithm(SQLCIPHER_PBKDF2_HMAC_SHA1);
sqlcipher_set_default_kdf_iter(64000);
sqlcipher_set_default_use_hmac(1);
break;
default:
sqlcipher_set_default_pagesize(4096);
sqlcipher_set_default_hmac_algorithm(SQLCIPHER_HMAC_SHA512);
sqlcipher_set_default_kdf_algorithm(SQLCIPHER_PBKDF2_HMAC_SHA512);
sqlcipher_set_default_kdf_iter(256000);
sqlcipher_set_default_use_hmac(1);
break;
}
}
}else
if( sqlite3StrICmp(zLeft,"cipher_memory_security")==0 ){
if( zRight ) {
sqlcipher_set_mem_security(sqlite3GetBoolean(zRight,1));
} else {
char *on = sqlite3_mprintf("%d", sqlcipher_get_mem_security());
codec_vdbe_return_string(pParse, "cipher_memory_security", on, P4_DYNAMIC);
}
}else
if( sqlite3StrICmp(zLeft,"cipher_settings")==0 ){
if(ctx) {
int algorithm;
char *pragma;
pragma = sqlite3_mprintf("PRAGMA kdf_iter = %d;", sqlcipher_codec_ctx_get_kdf_iter(ctx));
codec_vdbe_return_string(pParse, "pragma", pragma, P4_DYNAMIC);
pragma = sqlite3_mprintf("PRAGMA cipher_page_size = %d;", sqlcipher_codec_ctx_get_pagesize(ctx));
codec_vdbe_return_string(pParse, "pragma", pragma, P4_DYNAMIC);
pragma = sqlite3_mprintf("PRAGMA cipher_use_hmac = %d;", sqlcipher_codec_ctx_get_use_hmac(ctx));
codec_vdbe_return_string(pParse, "pragma", pragma, P4_DYNAMIC);
pragma = sqlite3_mprintf("PRAGMA cipher_plaintext_header_size = %d;", sqlcipher_codec_ctx_get_plaintext_header_size(ctx));
codec_vdbe_return_string(pParse, "pragma", pragma, P4_DYNAMIC);
algorithm = sqlcipher_codec_ctx_get_hmac_algorithm(ctx);
pragma = NULL;
if(algorithm == SQLCIPHER_HMAC_SHA1) {
pragma = sqlite3_mprintf("PRAGMA cipher_hmac_algorithm = %s;", SQLCIPHER_HMAC_SHA1_LABEL);
} else if(algorithm == SQLCIPHER_HMAC_SHA256) {
pragma = sqlite3_mprintf("PRAGMA cipher_hmac_algorithm = %s;", SQLCIPHER_HMAC_SHA256_LABEL);
} else if(algorithm == SQLCIPHER_HMAC_SHA512) {
pragma = sqlite3_mprintf("PRAGMA cipher_hmac_algorithm = %s;", SQLCIPHER_HMAC_SHA512_LABEL);
}
codec_vdbe_return_string(pParse, "pragma", pragma, P4_DYNAMIC);
algorithm = sqlcipher_codec_ctx_get_kdf_algorithm(ctx);
pragma = NULL;
if(algorithm == SQLCIPHER_PBKDF2_HMAC_SHA1) {
pragma = sqlite3_mprintf("PRAGMA cipher_kdf_algorithm = %s;", SQLCIPHER_PBKDF2_HMAC_SHA1_LABEL);
} else if(algorithm == SQLCIPHER_PBKDF2_HMAC_SHA256) {
pragma = sqlite3_mprintf("PRAGMA cipher_kdf_algorithm = %s;", SQLCIPHER_PBKDF2_HMAC_SHA256_LABEL);
} else if(algorithm == SQLCIPHER_PBKDF2_HMAC_SHA512) {
pragma = sqlite3_mprintf("PRAGMA cipher_kdf_algorithm = %s;", SQLCIPHER_PBKDF2_HMAC_SHA512_LABEL);
}
codec_vdbe_return_string(pParse, "pragma", pragma, P4_DYNAMIC);
}
}else
if( sqlite3StrICmp(zLeft,"cipher_default_settings")==0 ){
int algorithm;
char *pragma;
pragma = sqlite3_mprintf("PRAGMA cipher_default_kdf_iter = %d;", sqlcipher_get_default_kdf_iter());
codec_vdbe_return_string(pParse, "pragma", pragma, P4_DYNAMIC);
pragma = sqlite3_mprintf("PRAGMA cipher_default_page_size = %d;", sqlcipher_get_default_pagesize());
codec_vdbe_return_string(pParse, "pragma", pragma, P4_DYNAMIC);
pragma = sqlite3_mprintf("PRAGMA cipher_default_use_hmac = %d;", sqlcipher_get_default_use_hmac());
codec_vdbe_return_string(pParse, "pragma", pragma, P4_DYNAMIC);
pragma = sqlite3_mprintf("PRAGMA cipher_default_plaintext_header_size = %d;", sqlcipher_get_default_plaintext_header_size());
codec_vdbe_return_string(pParse, "pragma", pragma, P4_DYNAMIC);
algorithm = sqlcipher_get_default_hmac_algorithm();
pragma = NULL;
if(algorithm == SQLCIPHER_HMAC_SHA1) {
pragma = sqlite3_mprintf("PRAGMA cipher_default_hmac_algorithm = %s;", SQLCIPHER_HMAC_SHA1_LABEL);
} else if(algorithm == SQLCIPHER_HMAC_SHA256) {
pragma = sqlite3_mprintf("PRAGMA cipher_default_hmac_algorithm = %s;", SQLCIPHER_HMAC_SHA256_LABEL);
} else if(algorithm == SQLCIPHER_HMAC_SHA512) {
pragma = sqlite3_mprintf("PRAGMA cipher_default_hmac_algorithm = %s;", SQLCIPHER_HMAC_SHA512_LABEL);
}
codec_vdbe_return_string(pParse, "pragma", pragma, P4_DYNAMIC);
algorithm = sqlcipher_get_default_kdf_algorithm();
pragma = NULL;
if(algorithm == SQLCIPHER_PBKDF2_HMAC_SHA1) {
pragma = sqlite3_mprintf("PRAGMA cipher_default_kdf_algorithm = %s;", SQLCIPHER_PBKDF2_HMAC_SHA1_LABEL);
} else if(algorithm == SQLCIPHER_PBKDF2_HMAC_SHA256) {
pragma = sqlite3_mprintf("PRAGMA cipher_default_kdf_algorithm = %s;", SQLCIPHER_PBKDF2_HMAC_SHA256_LABEL);
} else if(algorithm == SQLCIPHER_PBKDF2_HMAC_SHA512) {
pragma = sqlite3_mprintf("PRAGMA cipher_default_kdf_algorithm = %s;", SQLCIPHER_PBKDF2_HMAC_SHA512_LABEL);
}
codec_vdbe_return_string(pParse, "pragma", pragma, P4_DYNAMIC);
}else
if( sqlite3StrICmp(zLeft,"cipher_integrity_check")==0 ){
if(ctx) {
sqlcipher_codec_ctx_integrity_check(ctx, pParse, "cipher_integrity_check");
}
}else {
return 0;
}
return 1;
}
|
CWE-476
| null | 521,499 |
246631142493626414477211419116763626944
| null | null |
other
|
sqlcipher
|
cb71f53e8cea4802509f182fa5bead0ac6ab0e7f
| 0 |
void sqlite3_activate_see(const char* in) {
/* do nothing, security enhancements are always active */
}
|
CWE-476
| null | 521,500 |
303275014243123859154865438352729135657
| null | null |
other
|
sqlcipher
|
cb71f53e8cea4802509f182fa5bead0ac6ab0e7f
| 0 |
int sqlite3CodecAttach(sqlite3* db, int nDb, const void *zKey, int nKey) {
struct Db *pDb = &db->aDb[nDb];
CODEC_TRACE("sqlite3CodecAttach: entered db=%p, nDb=%d zKey=%s, nKey=%d\n", db, nDb, (char *)zKey, nKey);
if(nKey && zKey && pDb->pBt) {
int rc;
Pager *pPager = pDb->pBt->pBt->pPager;
sqlite3_file *fd;
codec_ctx *ctx;
/* check if the sqlite3_file is open, and if not force handle to NULL */
if((fd = sqlite3PagerFile(pPager))->pMethods == 0) fd = NULL;
CODEC_TRACE("sqlite3CodecAttach: calling sqlcipher_activate()\n");
sqlcipher_activate(); /* perform internal initialization for sqlcipher */
CODEC_TRACE_MUTEX("sqlite3CodecAttach: entering database mutex %p\n", db->mutex);
sqlite3_mutex_enter(db->mutex);
CODEC_TRACE_MUTEX("sqlite3CodecAttach: entered database mutex %p\n", db->mutex);
#ifdef SQLCIPHER_EXT
if((rc = sqlite3_set_authorizer(db, sqlcipher_license_authorizer, db)) != SQLITE_OK) {
sqlite3_mutex_leave(db->mutex);
return rc;
}
#endif
/* point the internal codec argument against the contet to be prepared */
CODEC_TRACE("sqlite3CodecAttach: calling sqlcipher_codec_ctx_init()\n");
rc = sqlcipher_codec_ctx_init(&ctx, pDb, pDb->pBt->pBt->pPager, zKey, nKey);
if(rc != SQLITE_OK) {
/* initialization failed, do not attach potentially corrupted context */
CODEC_TRACE("sqlite3CodecAttach: context initialization failed with rc=%d\n", rc);
/* force an error at the pager level, such that even the upstream caller ignores the return code
the pager will be in an error state and will process no further operations */
sqlite3pager_error(pPager, rc);
pDb->pBt->pBt->db->errCode = rc;
CODEC_TRACE_MUTEX("sqlite3CodecAttach: leaving database mutex %p (early return on rc=%d)\n", db->mutex, rc);
sqlite3_mutex_leave(db->mutex);
CODEC_TRACE_MUTEX("sqlite3CodecAttach: left database mutex %p (early return on rc=%d)\n", db->mutex, rc);
return rc;
}
CODEC_TRACE("sqlite3CodecAttach: calling sqlite3PagerSetCodec()\n");
sqlite3PagerSetCodec(sqlite3BtreePager(pDb->pBt), sqlite3Codec, NULL, sqlite3FreeCodecArg, (void *) ctx);
CODEC_TRACE("sqlite3CodecAttach: calling codec_set_btree_to_codec_pagesize()\n");
codec_set_btree_to_codec_pagesize(db, pDb, ctx);
/* force secure delete. This has the benefit of wiping internal data when deleted
and also ensures that all pages are written to disk (i.e. not skipped by
sqlite3PagerDontWrite optimizations) */
CODEC_TRACE("sqlite3CodecAttach: calling sqlite3BtreeSecureDelete()\n");
sqlite3BtreeSecureDelete(pDb->pBt, 1);
/* if fd is null, then this is an in-memory database and
we dont' want to overwrite the AutoVacuum settings
if not null, then set to the default */
if(fd != NULL) {
CODEC_TRACE("sqlite3CodecAttach: calling sqlite3BtreeSetAutoVacuum()\n");
sqlite3BtreeSetAutoVacuum(pDb->pBt, SQLITE_DEFAULT_AUTOVACUUM);
}
CODEC_TRACE_MUTEX("sqlite3CodecAttach: leaving database mutex %p\n", db->mutex);
sqlite3_mutex_leave(db->mutex);
CODEC_TRACE_MUTEX("sqlite3CodecAttach: left database mutex %p\n", db->mutex);
}
return SQLITE_OK;
}
|
CWE-476
| null | 521,501 |
256689894825409373386090361770702149336
| null | null |
other
|
sqlcipher
|
cb71f53e8cea4802509f182fa5bead0ac6ab0e7f
| 0 |
static int sqlcipher_finalize(sqlite3 *db, sqlite3_stmt *pStmt, char **pzErrMsg){
int rc;
rc = sqlite3VdbeFinalize((Vdbe*)pStmt);
if( rc ){
sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
}
return rc;
}
|
CWE-476
| null | 521,502 |
95595809861209249306358439667207645898
| null | null |
other
|
sqlcipher
|
cb71f53e8cea4802509f182fa5bead0ac6ab0e7f
| 0 |
static int codec_set_pass_key(sqlite3* db, int nDb, const void *zKey, int nKey, int for_ctx) {
struct Db *pDb = &db->aDb[nDb];
CODEC_TRACE("codec_set_pass_key: entered db=%p nDb=%d zKey=%s nKey=%d for_ctx=%d\n", db, nDb, (char *)zKey, nKey, for_ctx);
if(pDb->pBt) {
codec_ctx *ctx = (codec_ctx*) sqlite3PagerGetCodec(pDb->pBt->pBt->pPager);
if(ctx) return sqlcipher_codec_ctx_set_pass(ctx, zKey, nKey, for_ctx);
}
return SQLITE_ERROR;
}
|
CWE-476
| null | 521,503 |
147982856689334410670576621083464838055
| null | null |
other
|
sqlcipher
|
cb71f53e8cea4802509f182fa5bead0ac6ab0e7f
| 0 |
static int sqlcipher_execExecSql(sqlite3 *db, char **pzErrMsg, const char *zSql){
sqlite3_stmt *pStmt;
int rc;
rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
if( rc!=SQLITE_OK ) return rc;
while( SQLITE_ROW==sqlite3_step(pStmt) ){
rc = sqlcipher_execSql(db, pzErrMsg, (char*)sqlite3_column_text(pStmt, 0));
if( rc!=SQLITE_OK ){
sqlcipher_finalize(db, pStmt, pzErrMsg);
return rc;
}
}
return sqlcipher_finalize(db, pStmt, pzErrMsg);
}
|
CWE-476
| null | 521,504 |
115513673762776193604506815165323236052
| null | null |
other
|
sqlcipher
|
cb71f53e8cea4802509f182fa5bead0ac6ab0e7f
| 0 |
static void codec_vdbe_return_string(Parse *pParse, const char *zLabel, const char *value, int value_type){
Vdbe *v = sqlite3GetVdbe(pParse);
sqlite3VdbeSetNumCols(v, 1);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC);
sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, value, value_type);
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
}
|
CWE-476
| null | 521,505 |
61280890484992941665983955600861900045
| null | null |
other
|
sqlcipher
|
cb71f53e8cea4802509f182fa5bead0ac6ab0e7f
| 0 |
void sqlcipher_exportFunc(sqlite3_context *context, int argc, sqlite3_value **argv) {
sqlite3 *db = sqlite3_context_db_handle(context);
const char* targetDb, *sourceDb;
int targetDb_idx = 0;
u64 saved_flags = db->flags; /* Saved value of the db->flags */
u32 saved_mDbFlags = db->mDbFlags; /* Saved value of the db->mDbFlags */
int saved_nChange = db->nChange; /* Saved value of db->nChange */
int saved_nTotalChange = db->nTotalChange; /* Saved value of db->nTotalChange */
u8 saved_mTrace = db->mTrace; /* Saved value of db->mTrace */
int rc = SQLITE_OK; /* Return code from service routines */
char *zSql = NULL; /* SQL statements */
char *pzErrMsg = NULL;
if(argc != 1 && argc != 2) {
rc = SQLITE_ERROR;
pzErrMsg = sqlite3_mprintf("invalid number of arguments (%d) passed to sqlcipher_export", argc);
goto end_of_export;
}
if(sqlite3_value_type(argv[0]) == SQLITE_NULL) {
rc = SQLITE_ERROR;
pzErrMsg = sqlite3_mprintf("target database can't be NULL");
goto end_of_export;
}
targetDb = (const char*) sqlite3_value_text(argv[0]);
sourceDb = "main";
if(argc == 2) {
if(sqlite3_value_type(argv[1]) == SQLITE_NULL) {
rc = SQLITE_ERROR;
pzErrMsg = sqlite3_mprintf("target database can't be NULL");
goto end_of_export;
}
sourceDb = (char *) sqlite3_value_text(argv[1]);
}
/* if the name of the target is not main, but the index returned is zero
there is a mismatch and we should not proceed */
targetDb_idx = sqlcipher_find_db_index(db, targetDb);
if(targetDb_idx == 0 && targetDb != NULL && sqlite3StrICmp("main", targetDb) != 0) {
rc = SQLITE_ERROR;
pzErrMsg = sqlite3_mprintf("unknown database %s", targetDb);
goto end_of_export;
}
db->init.iDb = targetDb_idx;
db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks;
db->mDbFlags |= DBFLAG_PreferBuiltin | DBFLAG_Vacuum;
db->flags &= ~(u64)(SQLITE_ForeignKeys | SQLITE_ReverseOrder | SQLITE_Defensive | SQLITE_CountRows);
db->mTrace = 0;
/* Query the schema of the main database. Create a mirror schema
** in the temporary database.
*/
zSql = sqlite3_mprintf(
"SELECT sql "
" FROM %s.sqlite_master WHERE type='table' AND name!='sqlite_sequence'"
" AND rootpage>0"
, sourceDb);
rc = (zSql == NULL) ? SQLITE_NOMEM : sqlcipher_execExecSql(db, &pzErrMsg, zSql);
if( rc!=SQLITE_OK ) goto end_of_export;
sqlite3_free(zSql);
zSql = sqlite3_mprintf(
"SELECT sql "
" FROM %s.sqlite_master WHERE sql LIKE 'CREATE INDEX %%' "
, sourceDb);
rc = (zSql == NULL) ? SQLITE_NOMEM : sqlcipher_execExecSql(db, &pzErrMsg, zSql);
if( rc!=SQLITE_OK ) goto end_of_export;
sqlite3_free(zSql);
zSql = sqlite3_mprintf(
"SELECT sql "
" FROM %s.sqlite_master WHERE sql LIKE 'CREATE UNIQUE INDEX %%'"
, sourceDb);
rc = (zSql == NULL) ? SQLITE_NOMEM : sqlcipher_execExecSql(db, &pzErrMsg, zSql);
if( rc!=SQLITE_OK ) goto end_of_export;
sqlite3_free(zSql);
/* Loop through the tables in the main database. For each, do
** an "INSERT INTO rekey_db.xxx SELECT * FROM main.xxx;" to copy
** the contents to the temporary database.
*/
zSql = sqlite3_mprintf(
"SELECT 'INSERT INTO %s.' || quote(name) "
"|| ' SELECT * FROM %s.' || quote(name) || ';'"
"FROM %s.sqlite_master "
"WHERE type = 'table' AND name!='sqlite_sequence' "
" AND rootpage>0"
, targetDb, sourceDb, sourceDb);
rc = (zSql == NULL) ? SQLITE_NOMEM : sqlcipher_execExecSql(db, &pzErrMsg, zSql);
if( rc!=SQLITE_OK ) goto end_of_export;
sqlite3_free(zSql);
/* Copy over the contents of the sequence table
*/
zSql = sqlite3_mprintf(
"SELECT 'INSERT INTO %s.' || quote(name) "
"|| ' SELECT * FROM %s.' || quote(name) || ';' "
"FROM %s.sqlite_master WHERE name=='sqlite_sequence';"
, targetDb, sourceDb, targetDb);
rc = (zSql == NULL) ? SQLITE_NOMEM : sqlcipher_execExecSql(db, &pzErrMsg, zSql);
if( rc!=SQLITE_OK ) goto end_of_export;
sqlite3_free(zSql);
/* Copy the triggers, views, and virtual tables from the main database
** over to the temporary database. None of these objects has any
** associated storage, so all we have to do is copy their entries
** from the SQLITE_MASTER table.
*/
zSql = sqlite3_mprintf(
"INSERT INTO %s.sqlite_master "
" SELECT type, name, tbl_name, rootpage, sql"
" FROM %s.sqlite_master"
" WHERE type='view' OR type='trigger'"
" OR (type='table' AND rootpage=0)"
, targetDb, sourceDb);
rc = (zSql == NULL) ? SQLITE_NOMEM : sqlcipher_execSql(db, &pzErrMsg, zSql);
if( rc!=SQLITE_OK ) goto end_of_export;
sqlite3_free(zSql);
zSql = NULL;
end_of_export:
db->init.iDb = 0;
db->flags = saved_flags;
db->mDbFlags = saved_mDbFlags;
db->nChange = saved_nChange;
db->nTotalChange = saved_nTotalChange;
db->mTrace = saved_mTrace;
if(zSql) sqlite3_free(zSql);
if(rc) {
if(pzErrMsg != NULL) {
sqlite3_result_error(context, pzErrMsg, -1);
sqlite3DbFree(db, pzErrMsg);
} else {
sqlite3_result_error(context, sqlite3ErrStr(rc), -1);
}
}
}
|
CWE-476
| null | 521,506 |
22620265715441669292024280266706204313
| null | null |
other
|
sqlcipher
|
cb71f53e8cea4802509f182fa5bead0ac6ab0e7f
| 0 |
int sqlite3_key(sqlite3 *db, const void *pKey, int nKey) {
CODEC_TRACE("sqlite3_key entered: db=%p pKey=%s nKey=%d\n", db, (char *)pKey, nKey);
return sqlite3_key_v2(db, "main", pKey, nKey);
}
|
CWE-476
| null | 521,507 |
98603646823205579631165897423533521782
| null | null |
other
|
sqlcipher
|
cb71f53e8cea4802509f182fa5bead0ac6ab0e7f
| 0 |
static int codec_set_btree_to_codec_pagesize(sqlite3 *db, Db *pDb, codec_ctx *ctx) {
int rc, page_sz, reserve_sz;
page_sz = sqlcipher_codec_ctx_get_pagesize(ctx);
reserve_sz = sqlcipher_codec_ctx_get_reservesize(ctx);
CODEC_TRACE("codec_set_btree_to_codec_pagesize: sqlite3BtreeSetPageSize() size=%d reserve=%d\n", page_sz, reserve_sz);
CODEC_TRACE_MUTEX("codec_set_btree_to_codec_pagesize: entering database mutex %p\n", db->mutex);
sqlite3_mutex_enter(db->mutex);
CODEC_TRACE_MUTEX("codec_set_btree_to_codec_pagesize: entered database mutex %p\n", db->mutex);
db->nextPagesize = page_sz;
/* before forcing the page size we need to unset the BTS_PAGESIZE_FIXED flag, else
sqliteBtreeSetPageSize will block the change */
pDb->pBt->pBt->btsFlags &= ~BTS_PAGESIZE_FIXED;
rc = sqlite3BtreeSetPageSize(pDb->pBt, page_sz, reserve_sz, 0);
CODEC_TRACE("codec_set_btree_to_codec_pagesize: sqlite3BtreeSetPageSize returned %d\n", rc);
CODEC_TRACE_MUTEX("codec_set_btree_to_codec_pagesize: leaving database mutex %p\n", db->mutex);
sqlite3_mutex_leave(db->mutex);
CODEC_TRACE_MUTEX("codec_set_btree_to_codec_pagesize: left database mutex %p\n", db->mutex);
return rc;
}
|
CWE-476
| null | 521,508 |
103653842200947024022232180460680522092
| null | null |
other
|
sqlcipher
|
cb71f53e8cea4802509f182fa5bead0ac6ab0e7f
| 0 |
static void* sqlite3Codec(void *iCtx, void *data, Pgno pgno, int mode) {
codec_ctx *ctx = (codec_ctx *) iCtx;
int offset = 0, rc = 0;
int page_sz = sqlcipher_codec_ctx_get_pagesize(ctx);
unsigned char *pData = (unsigned char *) data;
void *buffer = sqlcipher_codec_ctx_get_data(ctx);
int plaintext_header_sz = sqlcipher_codec_ctx_get_plaintext_header_size(ctx);
int cctx = CIPHER_READ_CTX;
CODEC_TRACE("sqlite3Codec: entered pgno=%d, mode=%d, page_sz=%d\n", pgno, mode, page_sz);
#ifdef SQLCIPHER_EXT
if(sqlcipher_license_check(ctx) != SQLITE_OK) return NULL;
#endif
/* call to derive keys if not present yet */
if((rc = sqlcipher_codec_key_derive(ctx)) != SQLITE_OK) {
sqlcipher_codec_ctx_set_error(ctx, rc);
return NULL;
}
/* if the plaintext_header_size is negative that means an invalid size was set via
PRAGMA. We can't set the error state on the pager at that point because the pager
may not be open yet. However, this is a fatal error state, so abort the codec */
if(plaintext_header_sz < 0) {
sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR);
return NULL;
}
if(pgno == 1) /* adjust starting pointers in data page for header offset on first page*/
offset = plaintext_header_sz ? plaintext_header_sz : FILE_HEADER_SZ;
CODEC_TRACE("sqlite3Codec: switch mode=%d offset=%d\n", mode, offset);
switch(mode) {
case CODEC_READ_OP: /* decrypt */
if(pgno == 1) /* copy initial part of file header or SQLite magic to buffer */
memcpy(buffer, plaintext_header_sz ? pData : (void *) SQLITE_FILE_HEADER, offset);
rc = sqlcipher_page_cipher(ctx, cctx, pgno, CIPHER_DECRYPT, page_sz - offset, pData + offset, (unsigned char*)buffer + offset);
#ifdef SQLCIPHER_TEST
if(cipher_fail_next_decrypt) rc = SQLITE_ERROR;
#endif
if(rc != SQLITE_OK) { /* clear results of failed cipher operation and set error */
sqlcipher_memset((unsigned char*) buffer+offset, 0, page_sz-offset);
sqlcipher_codec_ctx_set_error(ctx, rc);
}
memcpy(pData, buffer, page_sz); /* copy buffer data back to pData and return */
return pData;
break;
case CODEC_WRITE_OP: /* encrypt database page, operate on write context and fall through to case 7, so the write context is used*/
cctx = CIPHER_WRITE_CTX;
case CODEC_JOURNAL_OP: /* encrypt journal page, operate on read context use to get the original page data from the database */
if(pgno == 1) { /* copy initial part of file header or salt to buffer */
void *kdf_salt = NULL;
/* retrieve the kdf salt */
if((rc = sqlcipher_codec_ctx_get_kdf_salt(ctx, &kdf_salt)) != SQLITE_OK) {
sqlcipher_codec_ctx_set_error(ctx, rc);
return NULL;
}
memcpy(buffer, plaintext_header_sz ? pData : kdf_salt, offset);
}
rc = sqlcipher_page_cipher(ctx, cctx, pgno, CIPHER_ENCRYPT, page_sz - offset, pData + offset, (unsigned char*)buffer + offset);
#ifdef SQLCIPHER_TEST
if(cipher_fail_next_encrypt) rc = SQLITE_ERROR;
#endif
if(rc != SQLITE_OK) { /* clear results of failed cipher operation and set error */
sqlcipher_memset((unsigned char*)buffer+offset, 0, page_sz-offset);
sqlcipher_codec_ctx_set_error(ctx, rc);
return NULL;
}
return buffer; /* return persistent buffer data, pData remains intact */
break;
default:
sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR); /* unsupported mode, set error */
return pData;
break;
}
}
|
CWE-476
| null | 521,509 |
54971204450906547864034334814669445937
| null | null |
other
|
sqlcipher
|
cb71f53e8cea4802509f182fa5bead0ac6ab0e7f
| 0 |
int sqlite3_rekey_v2(sqlite3 *db, const char *zDb, const void *pKey, int nKey) {
CODEC_TRACE("sqlite3_rekey_v2: entered db=%p zDb=%s pKey=%s, nKey=%d\n", db, zDb, (char *)pKey, nKey);
if(db && pKey && nKey) {
int db_index = sqlcipher_find_db_index(db, zDb);
struct Db *pDb = &db->aDb[db_index];
CODEC_TRACE("sqlite3_rekey_v2: database pDb=%p db_index:%d\n", pDb, db_index);
if(pDb->pBt) {
codec_ctx *ctx;
int rc, page_count;
Pgno pgno;
PgHdr *page;
Pager *pPager = pDb->pBt->pBt->pPager;
ctx = (codec_ctx*) sqlite3PagerGetCodec(pDb->pBt->pBt->pPager);
if(ctx == NULL) {
/* there was no codec attached to this database, so this should do nothing! */
CODEC_TRACE("sqlite3_rekey_v2: no codec attached to db, exiting\n");
return SQLITE_OK;
}
CODEC_TRACE_MUTEX("sqlite3_rekey_v2: entering database mutex %p\n", db->mutex);
sqlite3_mutex_enter(db->mutex);
CODEC_TRACE_MUTEX("sqlite3_rekey_v2: entered database mutex %p\n", db->mutex);
codec_set_pass_key(db, db_index, pKey, nKey, CIPHER_WRITE_CTX);
/* do stuff here to rewrite the database
** 1. Create a transaction on the database
** 2. Iterate through each page, reading it and then writing it.
** 3. If that goes ok then commit and put ctx->rekey into ctx->key
** note: don't deallocate rekey since it may be used in a subsequent iteration
*/
rc = sqlite3BtreeBeginTrans(pDb->pBt, 1, 0); /* begin write transaction */
sqlite3PagerPagecount(pPager, &page_count);
for(pgno = 1; rc == SQLITE_OK && pgno <= (unsigned int)page_count; pgno++) { /* pgno's start at 1 see pager.c:pagerAcquire */
if(!sqlite3pager_is_mj_pgno(pPager, pgno)) { /* skip this page (see pager.c:pagerAcquire for reasoning) */
rc = sqlite3PagerGet(pPager, pgno, &page, 0);
if(rc == SQLITE_OK) { /* write page see pager_incr_changecounter for example */
rc = sqlite3PagerWrite(page);
if(rc == SQLITE_OK) {
sqlite3PagerUnref(page);
} else {
CODEC_TRACE("sqlite3_rekey_v2: error %d occurred writing page %d\n", rc, pgno);
}
} else {
CODEC_TRACE("sqlite3_rekey_v2: error %d occurred getting page %d\n", rc, pgno);
}
}
}
/* if commit was successful commit and copy the rekey data to current key, else rollback to release locks */
if(rc == SQLITE_OK) {
CODEC_TRACE("sqlite3_rekey_v2: committing\n");
rc = sqlite3BtreeCommit(pDb->pBt);
sqlcipher_codec_key_copy(ctx, CIPHER_WRITE_CTX);
} else {
CODEC_TRACE("sqlite3_rekey_v2: rollback\n");
sqlite3BtreeRollback(pDb->pBt, SQLITE_ABORT_ROLLBACK, 0);
}
CODEC_TRACE_MUTEX("sqlite3_rekey_v2: leaving database mutex %p\n", db->mutex);
sqlite3_mutex_leave(db->mutex);
CODEC_TRACE_MUTEX("sqlite3_rekey_v2: left database mutex %p\n", db->mutex);
}
return SQLITE_OK;
}
return SQLITE_ERROR;
}
|
CWE-476
| null | 521,510 |
9502611895732815870648349520733475855
| null | null |
other
|
sqlcipher
|
cb71f53e8cea4802509f182fa5bead0ac6ab0e7f
| 0 |
static void sqlite3FreeCodecArg(void *pCodecArg) {
codec_ctx *ctx = (codec_ctx *) pCodecArg;
if(pCodecArg == NULL) return;
sqlcipher_codec_ctx_free(&ctx); /* wipe and free allocated memory for the context */
sqlcipher_deactivate(); /* cleanup related structures, OpenSSL etc, when codec is detatched */
}
|
CWE-476
| null | 521,511 |
135294191443075897023867965603691767210
| null | null |
other
|
sqlcipher
|
cb71f53e8cea4802509f182fa5bead0ac6ab0e7f
| 0 |
static int sqlcipher_execSql(sqlite3 *db, char **pzErrMsg, const char *zSql){
sqlite3_stmt *pStmt;
VVA_ONLY( int rc; )
if( !zSql ){
return SQLITE_NOMEM;
}
if( SQLITE_OK!=sqlite3_prepare(db, zSql, -1, &pStmt, 0) ){
sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db));
return sqlite3_errcode(db);
}
VVA_ONLY( rc = ) sqlite3_step(pStmt);
assert( rc!=SQLITE_ROW );
return sqlcipher_finalize(db, pStmt, pzErrMsg);
}
|
CWE-476
| null | 521,512 |
173317170852294577239896925822232833330
| null | null |
other
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.