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_OpCodes *code_sfinal(jsi_Pstate *p, jsi_Pline *line) { JSI_NEW_CODESLN(0,OP_SFINAL, 0); }
|
CWE-120
| null | 520,286 |
299724626865350677211423708097309580775
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void jsi_pop_try(Jsi_Interp* interp, jsi_TryList **head)
{
interp->framePtr->tryDepth--;
jsi_TryList *t = (*head)->next;
Jsi_Free(*head);
*head = t;
interp->tryList = t;
}
|
CWE-120
| null | 520,287 |
131809525452993718097035993158943694434
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_Value *jsi_hashFmtKey(Jsi_MapEntry* h, struct Jsi_MapOpts *opts, int flags)
{
Jsi_HashEntry* hPtr = (Jsi_HashEntry*)h;
void *key = Jsi_HashKeyGet(hPtr);
if (opts->keyType == JSI_KEYS_ONEWORD)
return Jsi_ValueNewNumber(opts->interp, (Jsi_Number)(intptr_t)key);
char nbuf[JSI_MAX_NUMBER_STRING];
snprintf(nbuf, sizeof(nbuf), "%p", key);
return Jsi_ValueNewStringDup(opts->interp, nbuf);
}
|
CWE-120
| null | 520,288 |
338198533308190484040323910911833123189
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
bool Jsi_FSNative(Jsi_Interp *interp, Jsi_Value *file) {
void *data;
Jsi_Filesystem *fsPtr = Jsi_FilesystemForPath(interp, file, &data);
if (fsPtr && fsPtr == &jsiFilesystem)
return 1;
else
return 0;
}
|
CWE-120
| null | 520,289 |
7447625978568502418617159574018609830
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_CmdSpec *Jsi_FunctionGetSpecs(Jsi_Func *funcPtr)
{
return funcPtr->cmdSpec;
}
|
CWE-120
| null | 520,290 |
296966707783993979700458442886110477837
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC sqliteObjFree(Jsi_Interp *interp, void *data)
{
Jsi_Db *db = (Jsi_Db*)data;
SQLSIGASSERT(db,DB);
db->_->activeCnt--;
sqliteObjErase(db);
_JSI_MEMCLEAR(db);
Jsi_Free(db);
return JSI_OK;
}
|
CWE-120
| null | 520,291 |
31873183044213155124805085596684190600
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
const char *Jsi_ValueTypeStr(Jsi_Interp *interp, Jsi_Value *v)
{
switch (v->vt) {
case JSI_VT_BOOL: return "boolean"; break;
case JSI_VT_UNDEF: return "undefined"; break;
case JSI_VT_NULL: return "null"; break;
case JSI_VT_NUMBER: return "number"; break;
case JSI_VT_STRING: return "string"; break;
case JSI_VT_VARIABLE: return "variable"; break;
case JSI_VT_OBJECT: return Jsi_ObjTypeStr(interp, v->d.obj);
}
return "";
}
|
CWE-120
| null | 520,292 |
334477914907406927212984669084885420259
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void mysqlObjErase(MySqlObj *jdb)
{
mdbDeleteCmd(jdb);
jdb->db = NULL;
}
|
CWE-120
| null | 520,293 |
207976166425160354525996132647236747090
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_HashSearchNext(Jsi_HashSearch *searchPtr)
{
Jsi_HashEntry *hPtr;
Jsi_Hash *tablePtr = searchPtr->tablePtr;
int locked = 0;
while (searchPtr->nextEntryPtr == NULL) {
if (searchPtr->nextIndex >= (size_t)tablePtr->numBuckets) {
if (tablePtr->opts.lockHashProc && locked)
(*tablePtr->opts.lockHashProc)(tablePtr, 0);
return NULL;
}
if (tablePtr->opts.lockHashProc && locked == 0 && (*tablePtr->opts.lockHashProc)(tablePtr, locked++) != JSI_OK)
return NULL;
searchPtr->nextEntryPtr =
tablePtr->buckets[searchPtr->nextIndex];
searchPtr->nextIndex++;
}
if (tablePtr->opts.lockHashProc && locked)
(*tablePtr->opts.lockHashProc)(tablePtr, 0);
hPtr = searchPtr->nextEntryPtr;
searchPtr->nextEntryPtr = hPtr->nextPtr;
return hPtr;
}
|
CWE-120
| null | 520,294 |
228360958722714382559665558802683797745
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC mdbPrepareAndBind(MyDbEvalContext *p)
{
if (mdbPrepareStmt(p) != JSI_OK)
return JSI_ERROR;
MysqlPrep *prep = p->prep;
MySqlObj *jdb = p->jdb;
Jsi_Interp *interp = jdb->interp;
Jsi_Value *pv = NULL, *apv = NULL;
char tname[50];
Jsi_RC rc = JSI_OK;
int i, n, nVar = prep->numParam;
if (nVar<=0)
return rc;
if (!prep->bindParam)
prep->bindParam = (MYSQL_BIND*)Jsi_Calloc(nVar, sizeof(MYSQL_BIND));
else
memset(prep->bindParam, 0, (nVar * sizeof(MYSQL_BIND)));
for(i=1; i<=nVar; i++) {
int btype = 0;
int isInt = 0;
int isBlob = 0;
const char *zVar = mysqlGetbindParamName(prep, i);
tname[0] = 0;
if (zVar == NULL) {
if (!jdb->optPtr || !(apv=jdb->optPtr->values))
return Jsi_LogError("? bind without values for param %d", i);
if (!(pv =Jsi_ValueArrayIndex(interp, apv, i-1)))
return Jsi_LogError("array element %d missing", nVar);
}
else if ((zVar[0]!='$' && zVar[0]!=':' && zVar[0]!='@') )
return Jsi_LogError("can not find bind var %s", zVar); else {
int zvLen = Jsi_Strlen(zVar);
char *zcp;
if (zVar[0] =='$' && ((zcp = Jsi_Strchr(zVar,'('))) && zVar[zvLen-1] == ')')
{
Jsi_DString vStr;
Jsi_DSInit(&vStr);
Jsi_DSAppendLen(&vStr, zVar+1, (zcp-zVar-1));
int slen = Jsi_Strlen(zcp);
const char *ttp;
if (jdb->optPtr->typeCheck!=mdbTypeCheck_None && (ttp = Jsi_Strchr(zVar,':'))) {
// Extract bind-type.
Jsi_DString tStr = {};
int tlen = Jsi_Strlen(ttp+1);
Jsi_DSAppendLen(&tStr, ttp+1, tlen-1);
snprintf(tname, sizeof(tname), "%s", Jsi_DSValue(&tStr));
Jsi_HashEntry *hPtr = Jsi_HashEntryFind(jdb->typeNameHash, tname);
assert(hPtr);
btype = (long)Jsi_HashValueGet(hPtr);
Jsi_DSFree(&tStr);
slen -= tlen;
}
if (isdigit(zcp[1])) {
Jsi_DSAppendLen(&vStr, "[", 1);
Jsi_DSAppendLen(&vStr, zcp+1, slen-2);
Jsi_DSAppendLen(&vStr, "]", 1);
} else {
if (zcp[1] != '[')
Jsi_DSAppendLen(&vStr, ".", 1);
Jsi_DSAppendLen(&vStr, zcp+1, slen-2);
}
pv = Jsi_NameLookup(interp, Jsi_DSValue(&vStr));
Jsi_DSFree(&vStr);
} else
pv = Jsi_VarLookup(interp, &zVar[1]);
}
Jsi_Number r;
SqlFieldResults *fres = prep->fieldParam+i-1;
MYSQL_BIND *bind = prep->bindParam+i-1;
memset(bind, 0, sizeof(*bind));
// Now create binding.
if(!pv ) {
if (!jdb->bindWarn) {
rc = Jsi_LogError("unknown bind param: %s", zVar);
break;
} else
Jsi_LogWarn("unknown bind param: %s", zVar);
} else {
if (btype && !Jsi_ValueIsUndef(interp, pv)) {
int done = 0, match = 1, cast = (jdb->optPtr->typeCheck==mdbTypeCheck_Cast);
switch (btype) {
case MYSQL_TYPE_BLOB:
isBlob = 1;
case MYSQL_TYPE_STRING:
if (cast)
Jsi_ValueToString(interp, pv, &n);
else
match = Jsi_ValueIsString(interp, pv);
break;
case MYSQL_TYPE_DOUBLE:
if (cast)
Jsi_ValueToNumber(interp, pv);
else
match = Jsi_ValueIsNumber(interp, pv);
break;
case MYSQL_TYPE_LONGLONG:
isInt = 1;
if (cast)
Jsi_ValueToNumber(interp, pv);
else
match = Jsi_ValueIsNumber(interp, pv);
break;
case MYSQL_TYPE_TINY:
if (cast)
Jsi_ValueToBool(interp, pv);
else
match = Jsi_ValueIsBoolean(interp, pv);
break;
case MYSQL_TYPE_TIME:
case MYSQL_TYPE_DATE:
case MYSQL_TYPE_DATETIME:
case MYSQL_TYPE_TIMESTAMP:
if (cast)
Jsi_ValueToNumber(interp, pv);
else if (!Jsi_ValueIsNumber(interp, pv))
goto errout;
Jsi_GetNumberFromValue(interp, pv, &r);
bind->buffer_type = (enum enum_field_types)btype;
bind->buffer=&fres->buffer.timestamp;
bind->buffer_length = sizeof(fres->buffer.timestamp);
bind->length = NULL;
mdbJsToMyTime(r, &fres->buffer.timestamp, 1);
done = 1;
break;
default:
Jsi_LogBug("Unhandled bind type: %s = %d", tname, btype);
}
if (done)
continue;
if (cast == 0 && match == 0)
errout:
{
int ltyp = (jdb->optPtr->typeCheck==mdbTypeCheck_Error?JSI_LOG_ERROR:JSI_LOG_WARN);
Jsi_LogMsg(interp, ltyp, "bind param \"%s\" type is not \"%s\"", zVar, tname);
if (ltyp == JSI_LOG_ERROR)
return JSI_ERROR;
}
}
if (Jsi_ValueIsBoolean(interp, pv)) {
bool nb;
Jsi_GetBoolFromValue(interp, pv, &nb);
n = nb;
bind->buffer_type = MYSQL_TYPE_TINY;
bind->buffer = &fres->buffer.vchar;
bind->buffer_length = sizeof(fres->buffer.vchar);
bind->length = &fres->len;
//bind->is_null = &fres->isnull;
fres->buffer.vchar = n;
} else if (Jsi_ValueIsNumber(interp, pv)) {
Jsi_Number r;
Jsi_Wide wv;
Jsi_GetNumberFromValue(interp, pv, &r);
wv = (Jsi_Wide)r;
bind->buffer_type = MYSQL_TYPE_DOUBLE;
bind->buffer = &fres->buffer.vdouble;
bind->buffer_length = sizeof(fres->buffer.vdouble);
bind->length = &fres->len;
fres->buffer.vdouble = (double)r;
if (isInt || (jdb->forceInt && (((Jsi_Number)wv)-r)==0)) {
bind->buffer = &fres->buffer.vlonglong;
bind->buffer_type = MYSQL_TYPE_LONGLONG;
bind->buffer_length = sizeof(fres->buffer.vlonglong);
fres->buffer.vlonglong = wv;
}
} else if (Jsi_ValueIsNull(interp, pv) || (Jsi_ValueIsUndef(interp, pv) && jdb->optPtr->mapundef)) {
bindnull:
bind->buffer_type = MYSQL_TYPE_NULL;
bind->buffer = &fres->buffer.vchar;
bind->buffer_length = sizeof(fres->buffer.vchar);
bind->length = &fres->len;
fres->buffer.vchar = 0;
} else if (Jsi_ValueIsString(interp, pv)) {
char *sstr = Jsi_ValueGetStringLen(interp, pv, &n);
bind->buffer_type = MYSQL_TYPE_STRING;
bind->buffer=sstr;
bind->buffer_length = n;
bind->length = NULL;
if (isBlob)
bind->buffer_type = MYSQL_TYPE_BLOB;
} else {
if (!jdb->bindWarn) {
rc = Jsi_LogError("bind param must be string/number/bool/null: %s", zVar);
break;
} else {
Jsi_LogWarn("bind param must be string/number/bool/null: %s", zVar);
goto bindnull;
}
}
}
}
if (mysql_stmt_bind_param(prep->myStmt, prep->bindParam))
rc = Jsi_LogError("bind failed: %s", mysql_error(jdb->db));
return rc;
}
|
CWE-120
| null | 520,295 |
38343716904009630039589875167029227851
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC NumberToPrecisionCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
char buf[JSI_MAX_NUMBER_STRING*2];
int prec = 0, skip = 0;
Jsi_Number num;
Jsi_Value *v;
ChkStringN(_this, funcPtr, v);
if (Jsi_GetIntFromValue(interp, Jsi_ValueArrayIndex(interp, args, skip), &prec) != JSI_OK)
return JSI_ERROR;
if (prec<=0 || prec>JSI_MAX_NUMBER_STRING) return Jsi_LogError("precision must be between 1 and %d", JSI_MAX_NUMBER_STRING);
Jsi_GetDoubleFromValue(interp, v, &num);
snprintf(buf, sizeof(buf),"%.*" JSI_NUMFFMT, prec, num);
if (num<0)
prec++;
buf[prec+1] = 0;
if (buf[prec] == '.')
buf[prec] = 0;
Jsi_ValueMakeStringDup(interp, ret, buf);
return JSI_OK;
}
|
CWE-120
| null | 520,296 |
331937973223465695797475682525756761160
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC FilesysFlushCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
UdfGet(udf, _this, funcPtr);
int pos = Jsi_Flush(interp, udf->chan);
Jsi_ValueMakeNumber(interp, ret, (Jsi_Number)pos);
return JSI_OK;
}
|
CWE-120
| null | 520,297 |
306070621585281694248855878996039471023
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC jsi_ParentFuncToValue(Jsi_Interp *interp, Jsi_OptionSpec* spec, Jsi_Value **outValue, Jsi_DString *outStr, void *record, Jsi_Wide flags)
{
if (outStr)
return JSI_ERROR;
Jsi_Value **v = (Jsi_Value **)(((char*)record) + spec->offset);
//const char *s, *subspec = (const char *)spec->data;
if (!*v) {
Jsi_ValueMakeNull(interp, outValue);
return JSI_OK;
}
if (!interp->parent)
return Jsi_LogError("no parent interp");
if (spec->data) {
Jsi_DString dStr = {};
Jsi_DSPrintf(&dStr, "func(%s)", (char*)spec->data);
Jsi_ValueFromDS(interp, &dStr, outValue);
}
return JSI_OK;
}
|
CWE-120
| null | 520,298 |
96165589057971703707354767379400620128
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void mdbDeleteCmd(MySqlObj *jdb)
{
Jsi_Interp *interp = jdb->interp;
if (jdb->debug & mdbTMODE_DELETE)
JSI_DBQUERY_PRINTF( "DEBUG: delete\n");
if (jdb->stmtCache)
mdbFlushStmtCache(jdb);
if (jdb->stmtHash)
Jsi_HashDelete(jdb->stmtHash);
//closeIncrblobChannels(jdb);
if (jdb->db) {
mdbClose(jdb->db);
}
while( jdb->pFunc ) {
SqlFunc *pFunc = jdb->pFunc;
jdb->pFunc = pFunc->pNext;
Jsi_DSFree(&pFunc->dScript);
Jsi_DecrRefCount(interp, pFunc->tocall);
Jsi_Free((char*)pFunc);
}
if( jdb->zNull ) {
Jsi_Free(jdb->zNull);
}
if (jdb->typeNameHash)
Jsi_HashDelete(jdb->typeNameHash);
Jsi_OptionsFree(interp, SqlOptions, jdb, 0);
if (jdb->stmtCache)
Jsi_ListDelete(jdb->stmtCache);
}
|
CWE-120
| null | 520,299 |
39975413753129508231904674441009481020
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static bool sqliteObjEqual(void *data1, void *data2)
{
//SQLSIGASSERT(data1,DB);
//SQLSIGASSERT(data2,DB);
return (data1 == data2);
}
|
CWE-120
| null | 520,300 |
110984136594663888748038214009308681799
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void delete_case3(Jsi_TreeEntry* n) {
Jsi_TreeEntry* s = sibling(n);
if (node_color(n->parent) == _JSI_TREE_BLACK &&
node_color(s) == _JSI_TREE_BLACK &&
node_color(s->left) == _JSI_TREE_BLACK &&
node_color(s->right) == _JSI_TREE_BLACK)
{
set_color(s, _JSI_TREE_RED);
delete_case1(n->parent);
} else
delete_case4(n);
}
|
CWE-120
| null | 520,301 |
265817416547289551093740466010119160044
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_OpCodes *code_jmp(int off) { JSI_NEW_CODES(0,OP_JMP, off); }
|
CWE-120
| null | 520,302 |
139198427899033199792308963204995307127
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void jsi_VerifyFree(Jsi_Interp *interp, Jsi_OptionSpec* spec, void *ptr)
{
Jsi_Value **v = (Jsi_Value**)ptr;
if (v && *v)
Jsi_DecrRefCount(interp, *v);
}
|
CWE-120
| null | 520,303 |
206478559005847571209588622209907569098
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void rotate_left(Jsi_TreeEntry* n) {
Jsi_TreeEntry* r;
Assert(n);
r = n->right;
replace_node(n, r);
n->right = r->left;
if (r->left != NULL) {
r->left->parent = n;
}
r->left = n;
n->parent = r;
}
|
CWE-120
| null | 520,304 |
197266749997539164880771935879625754565
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static jsi_CaseList *caselist_new(jsi_Pstate *pstate, jsi_CaseExprStat *es)
{
jsi_CaseList *a = (jsi_CaseList*)Jsi_Calloc(1,sizeof(*a));
a->sig = JSI_SIG_CASELIST;
a->es = es;
a->tail = a;
return a;
}
|
CWE-120
| null | 520,305 |
127235087435711459428979572873905242810
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC mdbEvalInit(
Jsi_Interp *interp,
MyDbEvalContext *p, /* Pointer to structure to initialize */
MySqlObj *jdb, /* Database handle */
const char* zSql, /* Value containing SQL script */
Jsi_DString *dStr,
Jsi_Obj *pArray, /* Name of Jsi array to set (*) element of */
Jsi_Obj *pValVar /* Name element in array for list. */
) {
p->dzSql = dStr;
p->zSql = Jsi_DSAppend(p->dzSql, zSql?zSql:"", NULL);
p->jdb = jdb;
return JSI_OK;
}
|
CWE-120
| null | 520,306 |
142850299007969514096169459495324334948
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void mdbReleaseStmt( MySqlObj *jdb, MysqlPrep *prep, int discard ) {
if( jdb->maxStmts<=0 || discard ) {
/* If the cache is turned off, deallocated the statement */
mdbRelease1Stmt(jdb, prep);
} else {
/* Add the prepared statement to the beginning of the cache list. */
if (!prep->elPtr)
prep->elPtr = Jsi_ListPushFrontNew(jdb->stmtCache, prep);
else
Jsi_ListPushFront(jdb->stmtCache, prep->elPtr);
mdbStmtLimit(jdb);
}
}
|
CWE-120
| null | 520,307 |
57054680505493491787049672030458907691
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void delete_case6(Jsi_TreeEntry* n) {
Jsi_TreeEntry* s = sibling(n);
set_color(s, node_color(n->parent));
set_color(n->parent, _JSI_TREE_BLACK);
if (n == n->parent->left) {
Assert (node_color(s->right) == _JSI_TREE_RED);
set_color(s->right, _JSI_TREE_BLACK);
rotate_left(n->parent);
}
else
{
//Assert (node_color(s->left) == _JSI_TREE_RED);
set_color(s->left, _JSI_TREE_BLACK);
rotate_right(n->parent);
}
}
|
CWE-120
| null | 520,308 |
184527273566998682052246680604511179306
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_OpCodes *code_delete(int n) { JSI_NEW_CODES(0,OP_DELETE, n); }
|
CWE-120
| null | 520,309 |
313875760403941667416300154690320431894
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static jsi_Pstate* jsiNewParser(Jsi_Interp* interp, const char *codeStr, Jsi_Channel fp, int iseval)
{
bool isNew;
Jsi_HashEntry *hPtr = NULL;
hPtr = Jsi_HashEntryNew(interp->codeTbl, (void*)codeStr, &isNew);
if (!hPtr) return NULL;
jsi_Pstate *ps, *topPs;
if (isNew==0 && ((ps = (jsi_Pstate *)Jsi_HashValueGet(hPtr)))) {
interp->codeCacheHit++;
return ps;
}
ps = jsi_PstateNew(interp);
ps->eval_flag = iseval;
if (codeStr)
jsi_PstateSetString(ps, codeStr);
else
jsi_PstateSetFile(ps, fp, 1);
interp->inParse++;
topPs = interp->parsePs;
interp->parsePs = ps;
yyparse(ps);
interp->parsePs = topPs;
interp->inParse--;
if (ps->err_count) {
Jsi_HashEntryDelete(hPtr);
jsi_PstateFree(ps);
return NULL;
}
if (isNew) {
Jsi_HashValueSet(hPtr, ps);
ps->hPtr = hPtr;
}
return ps;
}
|
CWE-120
| null | 520,310 |
103853546413012083700809763419575376502
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_RC jsi_InterpInfo(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
Jsi_Interp *sinterp = interp;
Jsi_DString dStr = {}, cStr = {};
char tbuf[1024];
Jsi_Value *v = Jsi_ValueArrayIndex(interp, args, 0);
tbuf[0] = 0;
if (v) {
InterpObj *udf = NULL;
if (v && v->vt == JSI_VT_OBJECT && v->d.obj->ot == JSI_OT_USEROBJ)
udf = (InterpObj *)v->d.obj->d.uobj->data;
if (udf && udf->subinterp) {
SIGASSERT(udf, INTERPOBJ);
sinterp = udf->subinterp;
} else
return Jsi_LogError("unknown interp");
}
if (sinterp->subthread)
snprintf(tbuf, sizeof(tbuf), ", thread:{errorCnt:%u, evalCnt:%u, msgCnt:%u }",
sinterp->threadErrCnt, sinterp->threadEvalCnt, sinterp->threadMsgCnt );
const char *funcstr = sinterp->framePtr->funcName;
if (!funcstr)
funcstr = "";
int curLine = (sinterp->curIp?sinterp->curIp->Line:0);
Jsi_DSPrintf(&dStr, "{curLevel:%d, curLine:%d, curFile:\"%s\", curFunc:\"%s\", hasExited:%d, "
"opCnt:%d, isSafe:%s, depth:%d, codeCacheHits: %d, typeMismatchCnt:%d, "
"funcCallCnt:%d, cmdCallCnt:%d, includeCnt:%d, includeDepth:%d, pkgReqDepth:%d, "
"cwd:\"%s\", lockTimeout: %d, name, \"%s\" %s%s};",
sinterp->level, curLine, jsi_GetCurFile(sinterp), funcstr?funcstr:"",
sinterp->exited, sinterp->opCnt, sinterp->isSafe?"true":"false",
sinterp->interpDepth, sinterp->codeCacheHit, sinterp->typeMismatchCnt,
sinterp->funcCallCnt, sinterp->cmdCallCnt, sinterp->includeCnt, sinterp->includeDepth, sinterp->pkgReqDepth,
(sinterp->curDir?sinterp->curDir:Jsi_GetCwd(sinterp,&cStr)),
sinterp->lockTimeout, sinterp->name?sinterp->name:"", tbuf[0]?",":"", tbuf);
Jsi_RC rc = Jsi_JSONParse(interp, Jsi_DSValue(&dStr), ret, 0);
if (rc != JSI_OK)
puts(Jsi_DSValue(&dStr));
Jsi_DSFree(&dStr);
Jsi_DSFree(&cStr);
return rc;
}
|
CWE-120
| null | 520,311 |
238581163957846993384610149938575493349
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void dbEvalFinalize(DbEvalContext *p) {
// Jsi_Interp *interp = p->jdb->interp;
if( p->pPreStmt ) {
sqlite3_reset(p->pPreStmt->pStmt);
dbReleaseStmt(p->jdb, p->pPreStmt, p->nocache);
p->pPreStmt = 0;
}
if (p->dSql)
Jsi_DSFree(p->dSql);
dbReleaseColumnNames(p);
}
|
CWE-120
| null | 520,312 |
56134798121387240227552873106876987879
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC DebugInfoCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
if (!interp->breakpointHash) {
Jsi_ValueMakeArrayObject(interp, ret, NULL);
return JSI_OK;
}
int argc = Jsi_ValueGetLength(interp, args);
if (argc == 0)
return Jsi_HashKeysDump(interp, interp->breakpointHash, ret, 0);
Jsi_Value *val = Jsi_ValueArrayIndex(interp, args, 0);
int num;
char nbuf[JSI_MAX_NUMBER_STRING];
if (Jsi_GetIntFromValue(interp, val, &num) != JSI_OK)
return Jsi_LogError("bad number");
snprintf(nbuf, sizeof(nbuf), "%d", num);
Jsi_HashEntry *hPtr = Jsi_HashEntryFind(interp->breakpointHash, nbuf);
if (!hPtr)
return Jsi_LogError("unknown breakpoint");
jsi_BreakPoint* bp = (jsi_BreakPoint*)Jsi_HashValueGet(hPtr);
if (!bp) return JSI_ERROR;
Jsi_DString dStr = {};
if (bp->func)
Jsi_DSPrintf(&dStr, "{id:%d, type:\"func\", func:\"%s\", hits:%d, enabled:%s, temporary:%s}",
bp->id, bp->func, bp->hits, bp->enabled?"true":"false", bp->temp?"true":"false");
else
Jsi_DSPrintf(&dStr, "{id:%d, type:\"line\", file:\"%s\", line:%d, hits:%d, enabled:%s}",
bp->id, bp->file?bp->file:"", bp->line, bp->hits, bp->enabled?"true":"false");
Jsi_RC rc = Jsi_JSONParse(interp, Jsi_DSValue(&dStr), ret, 0);
Jsi_DSFree(&dStr);
return rc;
}
|
CWE-120
| null | 520,313 |
206114633557068007968903452247788917694
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC FilesysTruncateCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
UdfGet(udf, _this, funcPtr);
Jsi_Value *vPos = Jsi_ValueArrayIndex(interp, args, 0);
Jsi_Number num;
if (Jsi_ValueGetNumber(interp, vPos, &num) != JSI_OK)
return JSI_ERROR;
num = (Jsi_Number)Jsi_Truncate(interp, udf->chan, (unsigned int)num);
Jsi_ValueMakeNumber(interp, ret, num);
return JSI_OK;
}
|
CWE-120
| null | 520,314 |
132693708209307006931659081236434003120
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void dbEvalSetColumn(DbEvalContext *p, int iCol, Jsi_DString *dStr) {
Jsi_Interp *interp = p->jdb->interp;
char nbuf[JSI_MAX_NUMBER_STRING];
sqlite3_stmt *pStmt = p->pPreStmt->pStmt;
switch( sqlite3_column_type(pStmt, iCol) ) {
case SQLITE_BLOB: {
int bytes = sqlite3_column_bytes(pStmt, iCol);
const char *zBlob = (char*)sqlite3_column_blob(pStmt, iCol);
if( !zBlob ) {
return;
}
Jsi_DSAppendLen(dStr, zBlob, bytes);
return;
}
case SQLITE_INTEGER: {
sqlite_int64 v = sqlite3_column_int64(pStmt, iCol);
if (v==0 || v==1) {
const char *dectyp = sqlite3_column_decltype(pStmt, iCol);
if (dectyp && !Jsi_Strncasecmp(dectyp,"bool", 4)) {
Jsi_DSAppend(dStr, (v?"true":"false"), NULL);
return;
}
}
#ifdef __WIN32
snprintf(nbuf, sizeof(nbuf), "%" PRId64, (Jsi_Wide)v);
#else
snprintf(nbuf, sizeof(nbuf), "%lld", v);
#endif
Jsi_DSAppend(dStr, nbuf, NULL);
return;
}
case SQLITE_FLOAT: {
Jsi_NumberToString(interp, sqlite3_column_double(pStmt, iCol), nbuf, sizeof(nbuf));
Jsi_DSAppend(dStr, nbuf, NULL);
return;
}
case SQLITE_NULL: {
return;
}
}
const char *str = (char*)sqlite3_column_text(pStmt, iCol );
if (!str)
str = p->jdb->optPtr->nullvalue;
Jsi_DSAppend(dStr, str?str:"", NULL);
}
|
CWE-120
| null | 520,315 |
213899777622213898678251555156149988213
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC jsiValueGetString(Jsi_Interp *interp, Jsi_Value* v, Jsi_DString *dStr, objwalker *owPtr)
{
char buf[JSI_MAX_NUMBER_STRING], *str;
Jsi_DString eStr;
Jsi_DSInit(&eStr);
if (interp->maxDepth>0 && owPtr->depth > interp->maxDepth)
return Jsi_LogError("recursive ToString");
int quote = owPtr->quote;
int isjson = owPtr->quote&JSI_OUTPUT_JSON;
Jsi_Number num;
switch(v->vt) {
case JSI_VT_UNDEF:
Jsi_DSAppend(dStr, "undefined", NULL);
return JSI_OK;
case JSI_VT_NULL:
Jsi_DSAppend(dStr, "null", NULL);
return JSI_OK;
case JSI_VT_VARIABLE:
Jsi_DSAppend(dStr, "variable", NULL);
return JSI_OK;
case JSI_VT_BOOL:
Jsi_DSAppend(dStr, (v->d.val ? "true":"false"), NULL);
return JSI_OK;
case JSI_VT_NUMBER:
num = v->d.num;
outnum:
if (isjson && !Jsi_NumberIsNormal(num)) {
Jsi_DSAppend(dStr, "null", NULL);
} else if (Jsi_NumberIsInteger(num)) {
Jsi_NumberItoA10((Jsi_Wide)num, buf, sizeof(buf));
Jsi_DSAppend(dStr, buf, NULL);
} else if (Jsi_NumberIsWide(num)) {
snprintf(buf, sizeof(buf), "%" PRId64, (Jsi_Wide)num);
Jsi_DSAppend(dStr, buf, NULL);
} else if (Jsi_NumberIsNormal(num) || Jsi_NumberIsSubnormal(num)) {
Jsi_NumberDtoA(interp, num, buf, sizeof(buf), 0);
Jsi_DSAppend(dStr, buf, NULL);
} else if (Jsi_NumberIsNaN(num)) {
Jsi_DSAppend(dStr, "NaN", NULL);
} else {
int s = Jsi_NumberIsInfinity(num);
if (s > 0) Jsi_DSAppend(dStr, "+Infinity", NULL);
else if (s < 0) Jsi_DSAppend(dStr, "-Infinity", NULL);
else Jsi_LogBug("Ieee function problem: %d", fpclassify(num));
}
return JSI_OK;
case JSI_VT_STRING:
str = v->d.s.str;
outstr:
if (!quote) {
Jsi_DSAppend(dStr, str, NULL);
return JSI_OK;
}
Jsi_DSAppend(dStr,"\"", NULL);
while (*str) {
if ((*str == '\'' && (!isjson)) || *str == '\\'|| *str == '\"'|| (*str == '\n'
&& (!(owPtr->quote&JSI_OUTPUT_NEWLINES)))
|| *str == '\r' || *str == '\t' || *str == '\f' || *str == '\b' ) {
char pcp[2];
*pcp = *str;
pcp[1] = 0;
Jsi_DSAppendLen(dStr,"\\", 1);
switch (*str) {
case '\r': *pcp = 'r'; break;
case '\n': *pcp = 'n'; break;
case '\t': *pcp = 't'; break;
case '\f': *pcp = 'f'; break;
case '\b': *pcp = 'b'; break;
}
Jsi_DSAppendLen(dStr,pcp, 1);
} else if (isprint(*str) || !isjson)
Jsi_DSAppendLen(dStr,str, 1);
else {
char ubuf[10];
int l = Jsi_UtfEncode(str, ubuf);
Jsi_DSAppend(dStr,ubuf, NULL);
str += l-1;
}
str++;
}
Jsi_DSAppend(dStr,"\"", NULL);
Jsi_DSFree(&eStr);
return JSI_OK;
case JSI_VT_OBJECT: {
Jsi_Obj *o = v->d.obj;
switch(o->ot) {
case JSI_OT_BOOL:
Jsi_DSAppend(dStr, (o->d.val ? "true":"false"), NULL);
return JSI_OK;
case JSI_OT_NUMBER:
num = o->d.num;
goto outnum;
return JSI_OK;
case JSI_OT_STRING:
str = o->d.s.str;
goto outstr;
case JSI_OT_FUNCTION:
Jsi_FuncObjToString(interp, o->d.fobj->func, &eStr, 3 | ((owPtr->depth==0 && owPtr->quote)?8:0));
str = Jsi_DSValue(&eStr);
goto outstr;
case JSI_OT_REGEXP:
str = o->d.robj->pattern;
goto outstr;
case JSI_OT_USEROBJ:
jsi_UserObjToName(interp, o->d.uobj, &eStr);
str = Jsi_DSValue(&eStr);
goto outstr;
case JSI_OT_ITER:
Jsi_DSAppend(dStr, (isjson?"null":"*ITER*"), NULL);
return JSI_OK;
default:
break;
}
if (o->isarrlist)
{
Jsi_Value *nv;
int i, len = o->arrCnt;
if (!o->arr)
len = Jsi_ValueGetLength(interp, v);
Jsi_DSAppend(dStr,"[",len?" ":"", NULL);
for (i = 0; i < len; ++i) {
nv = Jsi_ValueArrayIndex(interp, v, i);
if (i) Jsi_DSAppend(dStr,", ", NULL);
owPtr->depth++;
if (nv) {
if (jsiValueGetString(interp, nv, dStr, owPtr) != JSI_OK) {
owPtr->depth--;
return JSI_ERROR;
}
}
else Jsi_DSAppend(dStr, "undefined", NULL);
owPtr->depth--;
}
Jsi_DSAppend(dStr,len?" ":"","]", NULL);
} else {
int len = Jsi_TreeSize(o->tree);
Jsi_DSAppend(dStr,"{",len?" ":"", NULL);
owPtr->depth++;
Jsi_TreeWalk(o->tree, _object_get_callback, owPtr, 0);
owPtr->depth--;
Jsi_DSAppend(dStr,len?" ":"","}", NULL);
}
return JSI_OK;
}
#ifndef __cplusplus
default:
Jsi_LogBug("Unexpected value type: %d", v->vt);
#endif
}
return JSI_OK;
}
|
CWE-120
| null | 520,316 |
144393418646217571675420412425390104936
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
int Jsi_Getc(Jsi_Interp *interp, Jsi_Channel chan) {
if (chan->fsPtr==0 || !chan->fsPtr->getcProc) return -1;
return chan->fsPtr->getcProc(chan);
}
|
CWE-120
| null | 520,317 |
18128821992941363023302576960219535799
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
jsi_HashArrayFind( Jsi_Hash *tablePtr, const void *key)
{
jsi_Hash hval = jsi_HashArray(key, tablePtr->keyType);
size_t hindex = hval & tablePtr->mask;
Jsi_HashEntry *hPtr = tablePtr->buckets[hindex];
for (; hPtr != NULL; hPtr = hPtr->nextPtr)
if (hPtr->hval == hval && !memcmp(hPtr->key.string, key, tablePtr->keyType))
return hPtr;
return NULL;
}
|
CWE-120
| null | 520,318 |
165582018294513102373351302334818513574
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
int Jsi_FunctionInvokeBool(Jsi_Interp *interp, Jsi_Value *func, Jsi_Value *arg)
{
if (interp->deleting)
return JSI_ERROR;
Jsi_Value *vpargs, *frPtr = Jsi_ValueNew1(interp);
Jsi_RC rc;
int bres = 0;
if (!arg) {
if (!interp->nullFuncArg) {
interp->nullFuncArg = Jsi_ValueMakeObject(interp, NULL, Jsi_ObjNewArray(interp, NULL, 0, 0));
Jsi_IncrRefCount(interp, interp->nullFuncArg);
}
vpargs = interp->nullFuncArg;
} else {
vpargs = Jsi_ValueMakeObject(interp, NULL, Jsi_ObjNewArray(interp, &arg, 1, 1));
}
Jsi_IncrRefCount(interp, vpargs);
rc = Jsi_FunctionInvoke(interp, func, vpargs, &frPtr, NULL);
Jsi_DecrRefCount(interp, vpargs);
if (rc == JSI_OK)
bres = Jsi_ValueIsTrue(interp, frPtr);
else {
bres = 2;
Jsi_LogError("function call failed");
}
Jsi_DecrRefCount(interp, frPtr);
if (Jsi_InterpGone(interp))
return JSI_ERROR;
return bres;
}
|
CWE-120
| null | 520,319 |
149996890656785475393202759509387327346
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
char* Jsi_NumberToString(Jsi_Interp *interp, Jsi_Number d, char *buf, int bsiz)
{
if (Jsi_NumberIsInteger(d)) {
Jsi_NumberItoA10((Jsi_Wide)d, buf, bsiz);
} else if (Jsi_NumberIsNormal(d)) {
Jsi_NumberDtoA(interp, d, buf, bsiz, 0);
} else if (Jsi_NumberIsNaN(d)) {
Jsi_Strcpy(buf, "NaN");
} else {
int s = Jsi_NumberIsInfinity(d);
if (s > 0) Jsi_Strcpy(buf, "Infinity");
else if (s < 0) Jsi_Strcpy(buf, "-Infinity");
else {
buf[0] = 0;
}
}
return buf;
}
|
CWE-120
| null | 520,320 |
269064424548985078302357477036156655463
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC SqliteConfCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
Jsi_Db *jdb, ojdb;
if (!(jdb = dbGetDbHandle(interp, _this, funcPtr))) return JSI_ERROR;
Jsi_Value *opts = Jsi_ValueArrayIndex(interp, args, 0);
if (jdb->noConfig && opts && !Jsi_ValueIsString(interp, opts))
return Jsi_LogError("Socket conf() is disabled for set");
ojdb = *jdb;
jdb->lastInsertId = sqlite3_last_insert_rowid(jdb->db);
jdb->changeCnt = sqlite3_changes(jdb->db);
jdb->changeCntAll = sqlite3_total_changes(jdb->db);
jdb->errorCode = sqlite3_errcode(jdb->db);
Jsi_RC rc = Jsi_OptionsConf(interp, SqlOptions, jdb, opts, ret, 0);
if (jdb->stmtCacheMax<0 || jdb->stmtCacheMax>MAX_PREPARED_STMTS) {
JSI_DBQUERY_PRINTF( "option stmtCacheMax value %d is not in range 0..%d", jdb->stmtCacheMax, MAX_PREPARED_STMTS);
jdb->stmtCacheMax = ojdb.stmtCacheMax;
rc = JSI_ERROR;
}
dbSetupCallbacks(jdb, &ojdb);
dbPrepStmtLimit(jdb);
return rc;
}
|
CWE-120
| null | 520,321 |
321642920158276980404883222045641368487
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
void Jsi_MutexDelete(Jsi_Interp *interp, Jsi_Mutex *mtx) { MutexDone(mtx); Jsi_Free(mtx);}
|
CWE-120
| null | 520,322 |
157270181685947834535995170386677029382
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC WebSocketSendCmd(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");
WSSIGASSERT(cmdPtr, OBJ);
jsi_wsPss *pss;
Jsi_HashEntry *hPtr;
Jsi_HashSearch cursor;
Jsi_Value *arg = Jsi_ValueArrayIndex(interp, args, 1);
char *str = Jsi_ValueString(interp, arg, NULL);
int id = -1, argc = Jsi_ValueGetLength(interp, args);
Jsi_DString eStr = {};
if (argc!=2)
return Jsi_LogError("wrong args");
Jsi_Number dnum;
Jsi_Value *darg = Jsi_ValueArrayIndex(interp, args, 0);
if (Jsi_ValueGetNumber(interp, darg, &dnum) != JSI_OK)
return Jsi_LogError("invalid id");
id = (int)dnum;
if (!str)
str = (char*)Jsi_ValueGetDString(interp, arg, &eStr, JSI_OUTPUT_JSON);
if (cmdPtr->echo)
Jsi_LogInfo("WS-SEND: %s\n", str);
for (hPtr = Jsi_HashSearchFirst(cmdPtr->pssTable, &cursor);
hPtr != NULL; hPtr = Jsi_HashSearchNext(&cursor)) {
pss = (jsi_wsPss*)Jsi_HashValueGet(hPtr);
WSSIGASSERT(pss, PWS);
if ((id<0 || pss->wid == id) && pss->state != PWS_DEAD) {
if (!pss->stack)
pss->stack = Jsi_StackNew();
char *msg = (char*)Jsi_Malloc(LWS_PRE + Jsi_Strlen(str) + 1);
Jsi_Strcpy(msg + LWS_PRE, str);
Jsi_StackPush(pss->stack, msg);
pss->stats.msgQLen++;
if (!cmdPtr->echo && pss->echo)
Jsi_LogInfo("WS-SEND: %s\n", str);
}
}
Jsi_DSFree(&eStr);
return JSI_OK;
}
|
CWE-120
| null | 520,323 |
254032483458313360158052185400210135379
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void fileObjErase(FileObj *fo)
{
if (fo->filename) {
Jsi_Close(fo->interp, fo->chan);
Jsi_Free(fo->filename);
Jsi_DecrRefCount(fo->interp, fo->fname);
Jsi_Free(fo->mode);
}
fo->filename = NULL;
}
|
CWE-120
| null | 520,324 |
171192825809641103048817010711310542864
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_OpCodes *code_reserved(jsi_Pstate *p, jsi_Pline *line, int type, const char *id)
{
jsi_ReservedInfo *ri = (jsi_ReservedInfo*)Jsi_Calloc(1, sizeof(*ri));
ri->type = type;
ri->label = id;
ri->topop = 0;
JSI_NEW_CODESLN(1,OP_RESERVED, ri);
}
|
CWE-120
| null | 520,325 |
170801363055914682758547189518177098912
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_RC jsi_StaticArgTypeCheck(Jsi_Interp *interp, int atyp, const char *p1, const char *p2, int index, Jsi_Func *func, jsi_Pline *line) {
Assert(index>0);
Jsi_RC rc;
if (interp->typeCheck.parse==0 && interp->typeCheck.all==0)
return JSI_OK;
int ai = index-1+func->callflags.bits.addargs;
if (func->argnames == NULL || ai>=func->argnames->count || ai<0)
return JSI_OK;
int typ = func->argnames->args[ai].type;
if (typ <= 0)
return JSI_OK;
if (index == 0 && func && func->type == FC_BUILDIN &&
interp->typeCheck.all==0) // Normally do not check return types for builtins.
return JSI_OK;
if ((typ&JSI_TT_ANY)) return JSI_OK;
if (index == 0 && atyp == JSI_VT_UNDEF) {
if (!(typ&JSI_TT_VOID))
goto done;
return JSI_OK;
}
/* if (index == 0 && (typ&JSI_TT_VOID)) {
if (atyp != JSI_VT_UNDEF && !(typ&JSI_TT_UNDEFINED))
goto done;
return JSI_OK;
}*/
if (atyp == JSI_VT_UNDEF)
return JSI_OK;
rc = JSI_OK;
if (typ&JSI_TT_UNDEFINED && atyp == JSI_TT_UNDEFINED) return rc;
if (typ&JSI_TT_NUMBER && atyp==JSI_TT_NUMBER) return rc;
if (typ&JSI_TT_STRING && atyp==JSI_TT_STRING) return rc;
if (typ&JSI_TT_BOOLEAN && atyp==JSI_TT_BOOLEAN) return rc;
if (typ&JSI_TT_ARRAY && atyp==JSI_TT_ARRAY) return rc;
if (typ&JSI_TT_FUNCTION && atyp==JSI_TT_FUNCTION) return rc;
if (typ&JSI_TT_REGEXP && atyp==JSI_TT_REGEXP) return rc;
if (typ&JSI_TT_USEROBJ && atyp==JSI_TT_USEROBJ) return rc;
if (typ&JSI_TT_ITEROBJ && atyp==JSI_TT_ITEROBJ) return rc;
if (typ&JSI_TT_OBJECT && atyp==JSI_TT_OBJECT) return rc;
if (typ&JSI_TT_NULL && atyp==JSI_TT_NULL) return rc;
done:
{
Jsi_DString dStr = {};
const char *exp = jsi_typeName(interp, typ, &dStr);
const char *vtyp = jsi_TypeName(interp, (Jsi_ttype)atyp);
char idxBuf[JSI_MAX_NUMBER_STRING*2];
idxBuf[0] = 0;
if (index>0)
snprintf(idxBuf, sizeof(idxBuf), " arg %d", index);
if (line)
interp->parseLine = line;
if (interp->typeCheck.error)
rc = JSI_ERROR;
jsi_TypeMismatch(interp);
Jsi_DString fStr = {};
rc = Jsi_LogType("type mismatch %s%s '%s': expected \"%s\" but got \"%s\"%s",
p1, idxBuf, p2, exp, vtyp, jsiFuncInfo(interp, &fStr, func, NULL));
Jsi_DSFree(&fStr);
Jsi_DSFree(&dStr);
}
return rc;
}
|
CWE-120
| null | 520,326 |
208018512584717070943704143433039660793
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
int Jsi_SetChannelOption(Jsi_Interp *interp, Jsi_Channel chan, const char *optionName,
const char *newValue) {return JSI_OK;}
|
CWE-120
| null | 520,327 |
330777518956904755390455313977262663542
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC InterpSourceCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
return InterpEvalCmd_(interp, args, _this, ret, funcPtr, 2);
}
|
CWE-120
| null | 520,328 |
85902888933889610594708993733857715170
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
const char *jsiFuncInfo(Jsi_Interp *interp, Jsi_DString *dStr, Jsi_Func* func, Jsi_Value *arg) {
if (!func) return "";
if (func->name)
Jsi_DSPrintf(dStr, ", in call to '%s'", func->name);
else
Jsi_DSPrintf(dStr, ", in call to function");
if (func->script) {
const char *cp = Jsi_Strrchr(func->script, '/');
if (cp)
cp++;
else
cp = func->script;
Jsi_DSPrintf(dStr, " declared at %s:%d.%d", cp, func->bodyline.first_line, func->bodyline.first_column);
}
if (arg) {
Jsi_DSAppend(dStr, " <", NULL);
Jsi_ValueGetDString(interp, arg, dStr, 0);
Jsi_DSAppend(dStr, ">.", NULL);
}
return Jsi_DSValue(dStr);
}
|
CWE-120
| null | 520,329 |
203054779309349218545253391160831906598
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC jsi_wsrecv_flush(jsi_wsCmdObj *cmdPtr, jsi_wsPss *pss)
{
int nlen = Jsi_DSLength(&pss->recvBuf);
if (nlen<=0)
return JSI_OK;
cmdPtr->recvBufCnt--;
const char *inPtr = Jsi_DSFreeDup(&pss->recvBuf);
Jsi_RC rc = jsi_wsrecv_callback(cmdPtr->interp, cmdPtr, pss, inPtr, nlen, 0);
if (rc != JSI_OK) {
pss->stats.recvErrCnt++;
pss->stats.recvErrLast = time(NULL);
}
return rc;
}
|
CWE-120
| null | 520,330 |
249329748523150464152940089125358521086
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_RC Jsi_EvalCmdJSON(Jsi_Interp *interp, const char *cmd, const char *jsonArgs, Jsi_DString *dStr, int flags)
{
if (Jsi_MutexLock(interp, interp->Mutex) != JSI_OK)
return JSI_ERROR;
Jsi_Value *nrPtr = Jsi_ValueNew1(interp);
Jsi_RC rc = Jsi_CommandInvokeJSON(interp, cmd, jsonArgs, &nrPtr);
Jsi_DSInit(dStr);
Jsi_ValueGetDString(interp, nrPtr, dStr, flags /*JSI_OUTPUT_JSON*/);
Jsi_DecrRefCount(interp, nrPtr);
Jsi_MutexUnlock(interp, interp->Mutex);
return rc;
}
|
CWE-120
| null | 520,331 |
199752189645398450660915597736627804787
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_OptionSpecsCached(Jsi_Interp *interp, const Jsi_OptionSpec *staticSpecs)
{
#ifdef NO_CACHED_SPECS
return (Jsi_OptionSpec*)staticSpecs;
#else
/* If we aren't master interp, need to cache due to init and modified flags if Jsi_OptionsChanged is called. */
if (interp->mainInterp == NULL) {
interp->mainInterp = interp;
}
if (interp == interp->mainInterp) {
return staticSpecs;
}
return jsi_GetCachedOptionSpecs(interp, staticSpecs);
#endif
}
|
CWE-120
| null | 520,332 |
5658848216531719854264153650203002549
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC StringToLowerCaseCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
int sLen, bLen;
const char *vstr;
ChkString(_this, funcPtr, vstr, &sLen, &bLen);
Jsi_DString dStr;
Jsi_DSInit(&dStr);
jsi_utf_tocase(vstr, 0, &dStr);
Jsi_ValueFromDS(interp, &dStr, ret);
return JSI_OK;
}
|
CWE-120
| null | 520,333 |
159191374008007909274684086308998518837
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_RC Jsi_GetDouble(Jsi_Interp* interp, const char *string, Jsi_Number *n)
{
char *endptr;
/* Callers can check for underflow via ERANGE */
errno = 0;
*n = strtod(string, &endptr);
return JsiCheckConversion(string, endptr);
}
|
CWE-120
| null | 520,334 |
165273546488134678157401884254519679321
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void jsi_DumpCustomSpec(Jsi_Interp *interp, Jsi_Obj *nobj, Jsi_OptionSpec* spec)
{
Jsi_OptionCustom* cspec = Jsi_OptionCustomBuiltin(spec->custom);
void *data = spec->data;
if (cspec->help) {
if (Jsi_Strchr(cspec->help, '\n'))
Jsi_LogError("%s .help contains newline: %s", cspec->name, cspec->help);
Jsi_ObjInsert(interp, nobj, "help", Jsi_ValueNewStringKey(interp, cspec->help),0);
}
if (cspec->info)
Jsi_ObjInsert(interp, nobj, "info", Jsi_ValueNewStringKey(interp, cspec->info),0);
Jsi_ObjInsert(interp, nobj, "name", Jsi_ValueNewStringKey(interp, cspec->name),0);
if (data && (spec->custom == Jsi_Opt_SwitchEnum || spec->custom == Jsi_Opt_SwitchBitset)) {
Jsi_Obj *sobj = Jsi_ObjNewType(interp, JSI_OT_ARRAY);
Jsi_Value *svalue = Jsi_ValueMakeObject(interp, NULL, sobj);
const char **lst = jsi_OptGetEnumList(spec);
int i = 0;
while (lst[i]) {
Jsi_ObjArrayAdd(interp, sobj, Jsi_ValueNewStringKey(interp, lst[i]));
i++;
}
Jsi_ObjInsert(interp, nobj, (spec->custom == Jsi_Opt_SwitchBitset?"bitSet":"enumList"), svalue, 0);
} else if (spec->custom == Jsi_Opt_SwitchSuboption) {
Jsi_OptionSpec* subSpec = (Jsi_OptionSpec*)data;
Jsi_Obj *sobj = Jsi_ObjNewType(interp, JSI_OT_ARRAY);
Jsi_Value *svalue = Jsi_ValueMakeObject(interp, NULL, sobj);
jsi_DumpOptionSpecs(interp, sobj, subSpec);
Jsi_ObjInsert(interp, nobj, "subSpec", svalue, 0);
}
}
|
CWE-120
| null | 520,335 |
204667387755826797194386749937498458586
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
const char *jsi_GetHomeDir(Jsi_Interp *interp) {
const char *str = NULL;
if (interp->homeDir)
return interp->homeDir;
#ifdef __WIN32
str = getenv("USERPROFILE"); /* TODO: windows home dir. */
#else
if ((str = getenv("HOME")) == NULL) {
struct passwd pwd, *pw;
char buf[JSI_BUFSIZ*3];
if (getpwuid_r(getuid(), &pwd, buf, sizeof(buf), &pw) == 0 && pw->pw_dir)
str = pw->pw_dir;
}
#endif
if (!str) {
Jsi_LogBug("no home dir");
str = "/";
}
#ifdef JSI_LITE_ONLY
return str;
#else
return (interp->homeDir = Jsi_KeyAdd(interp, str));
#endif
}
|
CWE-120
| null | 520,336 |
226383982391354509070262500061856699638
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_ScopeStrs *jsi_ScopeStrsDup(jsi_Pstate *ps, Jsi_ScopeStrs *ss)
{
Jsi_ScopeStrs *n = jsi_ScopeStrsNew();
int i;
if (!ss) return n;
*n = *ss;
if (!ss->args) return n;
n->args = (jsi_ArgValue*)Jsi_Calloc(n->count, sizeof(ss->args[0]));
n->_size = n->count;
memcpy(n->args, ss->args, (n->count * sizeof(ss->args[0])));
for (i = 0; i < ss->count; ++i) {
if (ss->args[i].defValue)
Jsi_IncrRefCount(ps->interp, ss->args[i].defValue);
}
return n;
}
|
CWE-120
| null | 520,337 |
48590936586874006461329429780040674095
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC interpObjFree(Jsi_Interp *interp, void *data)
{
InterpObj *fo = (InterpObj *)data;
SIGASSERT(fo,INTERPOBJ);
if (fo->deleting) return JSI_OK;
fo->deleting = 1;
interpObjErase(fo);
Jsi_Free(fo);
return JSI_OK;
}
|
CWE-120
| null | 520,338 |
40363073919335687383297282995337613661
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_RC Jsi_GetInt(Jsi_Interp* interp, const char *string, int *n, int base)
{
char *endptr;
if (base) {
*n = strtoul(string, &endptr, base);
}
else {
*n = (int)jsi_strtoul(string, &endptr);
}
return JsiCheckConversion(string, endptr);
}
|
CWE-120
| null | 520,339 |
225936388865283812676554796366611574690
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC jsi_ValueToParentFunc(Jsi_Interp *interp, Jsi_OptionSpec* spec, Jsi_Value *inValue, const char *inStr, void *record, Jsi_Wide flags)
{
if (inStr)
return JSI_ERROR;
Jsi_Value *val;
Jsi_Value **v = (Jsi_Value **)(((char*)record) + spec->offset);
const char *s, *subspec = (const char *)spec->data;
Jsi_Interp *pinterp = interp->parent;
if (!pinterp)
return Jsi_LogError("no parent interp");
if (!subspec)
return Jsi_LogError("custom parentfunc spec did not set data: %s", spec->name);
if (!inValue || Jsi_ValueIsNull(interp, inValue)) {
if (*v) Jsi_DecrRefCount(pinterp, *v);
*v = NULL;
return JSI_OK;
}
if (!(s=Jsi_ValueString(interp, inValue, NULL))) {
return Jsi_LogError("expected string or null");
}
val = Jsi_NameLookup(pinterp, s);
if (!val)
return Jsi_LogError("value not found in parent: %s", s);
if (!Jsi_ValueIsFunction(pinterp, val))
return Jsi_LogError("expected a func value");
if (spec->data && (interp->strict || pinterp->strict))
if (!jsi_FuncIsNoop(pinterp, val)
&& !jsi_FuncArgCheck(pinterp, val->d.obj->d.fobj->func, (char*)spec->data))
return Jsi_LogError("failed setting func pointer for %s", spec->name);
*v = val;
Jsi_IncrRefCount(pinterp, val);
return JSI_OK;
}
|
CWE-120
| null | 520,340 |
299575424467580517066858913900154996036
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC jsi_ValueToSubopt(Jsi_Interp *interp, Jsi_OptionSpec* spec, Jsi_Value *inValue, const char *inStr, void *record, Jsi_Wide flags)
{
if (inStr)
return JSI_ERROR;
char *s = ((char*)record) + spec->offset;
Jsi_OptionSpec *subspec = (Jsi_OptionSpec *)spec->data;
if (spec == subspec)
return Jsi_LogError("subspec was recursive");
if (!subspec)
return Jsi_LogError("custom suboption spec did not set data: %s", spec->name);
if (inValue && Jsi_ValueIsNull(interp, inValue) == 0 &&
(Jsi_ValueIsObjType(interp, inValue, JSI_OT_OBJECT)==0 || inValue->d.obj->isarrlist))
return Jsi_LogError("expected object");
return (Jsi_OptionsProcess(interp, subspec, s, inValue, flags)<0 ? JSI_ERROR : JSI_OK);
}
|
CWE-120
| null | 520,341 |
332995153233949008482268681498810490690
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_Value* Jsi_ValueMakeNumber(Jsi_Interp *interp, Jsi_Value **vPtr, Jsi_Number n) {
Jsi_Value *v = (vPtr?*vPtr:NULL);
if (!v)
v = Jsi_ValueNew(interp);
else
Jsi_ValueReset(interp, vPtr);
v->vt = JSI_VT_NUMBER;
v->d.num = n;
return v;
}
|
CWE-120
| null | 520,342 |
21731295809838510108675411923171984106
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void DbClose(sqlite3 *db) {
sqlite3_close(db);
}
|
CWE-120
| null | 520,343 |
282958824081823010167110227815523374228
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC InterpEvalCmd_(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr, int flags)
{
int isFile = flags&2;
int isUplevel = flags&1;
int lev = 0;
bool async = 0;
Jsi_RC rc = JSI_OK;
int isthrd;
Jsi_Interp *sinterp = interp;
Jsi_ValueMakeUndef(interp, ret);
InterpObj *udf = (InterpObj *)Jsi_UserObjGetData(interp, _this, funcPtr);
if (udf)
sinterp = udf->subinterp;
if (Jsi_InterpGone(interp) || Jsi_InterpGone(sinterp))
return Jsi_LogError("Sub-interp gone");
isthrd = (interp->threadId != sinterp->threadId);
jsi_Frame *f = sinterp->framePtr;
Jsi_Value *nw = Jsi_ValueArrayIndex(interp, args, 1);
if (!isUplevel) {
if (nw && Jsi_GetBoolFromValue(interp, nw, &async))
return JSI_ERROR;
} else {
if (isthrd)
return Jsi_LogError("can not use uplevel() with threaded interp");
Jsi_Number nlev = sinterp->framePtr->level;
if (nw && Jsi_GetNumberFromValue(interp, nw, &nlev)!=JSI_OK)
return Jsi_LogError("expected number");
lev = (int)nlev;
if (lev <= 0)
lev = f->level+lev;
if (lev <= 0 || lev > f->level)
return Jsi_LogError("level %d not between 1 and %d", (int)nlev, f->level);
}
char *cp = Jsi_ValueArrayIndexToStr(interp, args, 0, NULL);
if (cp==NULL || *cp == 0)
return JSI_OK;
if (async && isthrd) {
/* Post to thread event in sub-interps queue. TODO: could just use event like below... */
if (Jsi_MutexLock(interp, sinterp->QMutex) != JSI_OK)
return JSI_ERROR;
Jsi_DSAppend(&sinterp->interpEvalQ, Jsi_Strlen(Jsi_DSValue(&sinterp->interpEvalQ))?";":"", cp, NULL);
Jsi_MutexUnlock(interp, sinterp->QMutex);
return JSI_OK;
}
if (interp->subOpts.mutexUnlock) Jsi_MutexUnlock(interp, interp->Mutex);
if (!isthrd) {
int ostrict = sinterp->strict;
sinterp->strict = 0;
sinterp->level++;
if (interp->framePtr->tryDepth)
sinterp->framePtr->tryDepth++;
if (isFile) {
int sflags = 0;
if (!sinterp->includeCnt) {
sflags = JSI_EVAL_ARGV0|JSI_EVAL_AUTOINDEX;
sinterp->isMain = 1;
}
if (sinterp->debugOpts.debugCallback && !sinterp->includeCnt) // TODO: safe debugging can't use "source"
// TODO: we do this in debugger, even though it is illegal for interps to share objects.
sinterp->autoFiles = Jsi_ValueDup(sinterp, interp->autoFiles);
sinterp->includeCnt++;
rc = Jsi_EvalFile(sinterp, Jsi_ValueArrayIndex(interp, args, 0), sflags);
} else if (isUplevel == 0 || lev <= 1)
rc = (Jsi_EvalString(sinterp, cp, 0) == 0 ? JSI_OK : JSI_ERROR);
else {
rc = (jsi_evalStrFile(sinterp, NULL, cp, 0, lev) == 0 ? JSI_OK : JSI_ERROR);
}
sinterp->strict = ostrict;
if (interp->framePtr->tryDepth) {
sinterp->framePtr->tryDepth--;
if (rc != JSI_OK && interp != sinterp) {
Jsi_Strcpy(interp->errMsgBuf, sinterp->errMsgBuf);
interp->errLine = sinterp->errLine;
interp->errFile = sinterp->errFile;
sinterp->errMsgBuf[0] = 0;
}
}
sinterp->level--;
} else {
if (Jsi_MutexLock(interp, sinterp->QMutex) != JSI_OK)
return JSI_ERROR;
InterpStrEvent *se, *s = (InterpStrEvent *)Jsi_Calloc(1, sizeof(*s));
SIGINIT(s,INTERPSTREVENT);
s->isExec = 1;
s->tryDepth = interp->framePtr->tryDepth;
Jsi_DSInit(&s->data);
Jsi_DSAppend(&s->data, cp, NULL);
Jsi_DSInit(&s->func);
//s->mutex = Jsi_MutexNew(interp, -1, JSI_MUTEX_RECURSIVE);
//Jsi_MutexLock(s->mutex);
se = sinterp->interpStrEvents;
if (!se)
sinterp->interpStrEvents = s;
else {
while (se->next)
se = se->next;
se->next = s;
}
Jsi_MutexUnlock(interp, sinterp->QMutex);
while (s->isExec) /* Wait until done. TODO: timeout??? */
Jsi_Sleep(interp, 1);
rc = (s->rc == 0 ? JSI_OK : JSI_ERROR);
if (rc != JSI_OK)
Jsi_LogError("eval failed: %s", Jsi_DSValue(&s->data));
Jsi_DSFree(&s->func);
Jsi_DSFree(&s->data);
Jsi_Free(s);
}
if (interp->subOpts.mutexUnlock && Jsi_MutexLock(interp, interp->Mutex) != JSI_OK) {
return JSI_ERROR;
}
if (Jsi_InterpGone(sinterp))
{
/* TODO: perhaps exit() be able to delete. */
//Jsi_InterpDelete(sinterp);
return JSI_OK;
}
/*if (rc != JSI_OK && !async)
return rc;*/
if (sinterp->retValue->vt != JSI_VT_UNDEF) {
if (sinterp == interp)
Jsi_ValueCopy(interp, *ret, sinterp->retValue);
else
Jsi_CleanValue(sinterp, interp, sinterp->retValue, ret);
}
return rc;
}
|
CWE-120
| null | 520,344 |
38157864845962774992943689775199347026
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void delete_case5(Jsi_TreeEntry* n) {
Jsi_TreeEntry* s = sibling(n);
if (node_color(s) == _JSI_TREE_BLACK ) {
if (n == n->parent->left &&
node_color(s->right) == _JSI_TREE_BLACK &&
node_color(s->left) == _JSI_TREE_RED)
{
set_color(s, _JSI_TREE_RED);
set_color(s->left, _JSI_TREE_BLACK);
rotate_right(s);
}
else if (n == n->parent->right &&
node_color(s->right) == _JSI_TREE_RED &&
node_color(s->left) == _JSI_TREE_BLACK)
{
set_color(s, _JSI_TREE_RED);
set_color(s->right, _JSI_TREE_BLACK);
rotate_left(s);
}
}
delete_case6(n);
}
|
CWE-120
| null | 520,345 |
303113974066506967775250458521643162888
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
void Jsi_NumberDtoA(Jsi_Interp *interp, Jsi_Number value, char* buf, int bsiz, int prec)
{
int dp = interp->subOpts.dblPrec-1, dm = __DBL_DECIMAL_DIG__;
if (prec==0)
prec = (dp<=0?dm+dp:dp);
else if (prec<0)
prec = dm+prec;
if (prec<=0)
prec = dm-1;
if (Jsi_NumberIsNaN(value))
Jsi_Strcpy(buf,"NaN");
else
snprintf(buf, bsiz, "%.*" JSI_NUMGFMT, prec, value);
}
|
CWE-120
| null | 520,346 |
50197500180823330177473690798911095036
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
int Jsi_AddAutoFiles(Jsi_Interp *interp, const char *dir) {
Jsi_DString dStr = {};
Jsi_StatBuf stat;
int i, cnt = 0;
for (i=0; i<2; i++) {
Jsi_DSAppend(&dStr, dir, (i==0?"/lib":""),"/autoload.jsi", NULL);
Jsi_Value *v = Jsi_ValueNewStringKey(interp, Jsi_DSValue(&dStr));
if (Jsi_Stat(interp, v, &stat) != 0)
Jsi_ValueFree(interp, v);
else {
if (!interp->autoFiles) {
interp->autoFiles = Jsi_ValueNewArray(interp, 0, 0);
Jsi_IncrRefCount(interp, interp->autoFiles);
}
Jsi_ObjArrayAdd(interp, interp->autoFiles->d.obj, v);
cnt++;
interp->autoLoaded = 0;
}
Jsi_DSSetLength(&dStr, 0);
}
Jsi_DSFree(&dStr);
return cnt;
}
|
CWE-120
| null | 520,347 |
126508493392579672954363300494307843245
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC SqliteCollateCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
Jsi_Db *jdb;
Jsi_Value *func;
SqlCollate *pCollate;
char *zName;
if (!(jdb = dbGetDbHandle(interp, _this, funcPtr))) return JSI_ERROR;
zName = Jsi_ValueArrayIndexToStr(interp, args, 0, NULL);
func = Jsi_ValueArrayIndex(interp, args, 1);
pCollate = (SqlCollate*)Jsi_Calloc(1, sizeof(*pCollate));
if( pCollate==0 ) return JSI_ERROR;
pCollate->jdb = jdb;
pCollate->interp = interp;
pCollate->pNext = jdb->pCollate;
pCollate->zScript = func; /*(char*)&pCollate[1];*/
jdb->pCollate = pCollate;
if( sqlite3_create_collation(jdb->db, zName, SQLITE_UTF8, pCollate, dbSqlCollate) )
return Jsi_LogError("%s", (char *)sqlite3_errmsg(jdb->db));
return JSI_OK;
}
|
CWE-120
| null | 520,348 |
123498385740108650869459825834805365155
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_Value *Jsi_VarLookup(Jsi_Interp *interp, const char *varname)
{
Jsi_Value *v;
v = Jsi_ValueObjLookup(interp, interp->framePtr->incsc, (char*)varname, 0);
if (!v)
v = jsi_ScopeChainObjLookupUni(interp->framePtr->ingsc, (char*)varname);
return v;
}
|
CWE-120
| null | 520,349 |
338173214114663610745854450486722072262
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_RC jsi_InitTree(Jsi_Interp *interp, int release)
{
if (release) return JSI_OK;
/* TODO: maintain hash table of trees created per interp? */
return JSI_OK;
}
|
CWE-120
| null | 520,350 |
118667743191358040173630448754671724594
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_Value * jsi_FSListVolumesProc(Jsi_Interp *interp) {return 0;}
|
CWE-120
| null | 520,351 |
120160999140418817248664696339518055166
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC SqliteFilenameCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
#if (SQLITE_VERSION_NUMBER>3007009)
const char *zName = "main";
int argc = Jsi_ValueGetLength(interp, args);
Jsi_Db *jdb;
if (!(jdb = dbGetDbHandle(interp, _this, funcPtr))) return JSI_ERROR;
if (argc)
zName = Jsi_ValueArrayIndexToStr(interp, args, 0, NULL);
zName = sqlite3_db_filename(jdb->db, zName);
if (zName)
Jsi_ValueMakeStringDup(interp, ret, zName);
#endif
return JSI_OK;
}
|
CWE-120
| null | 520,352 |
8658960655113938501177673498346630772
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC dbTransPostCmd(
Jsi_Db *jdb, /* Sqlite3Db for $db */
Jsi_Interp *interp, /* Jsi interpreter */
Jsi_RC result /* Result of evaluating SCRIPT */
) {
static const char *azEnd[] = {
"RELEASE _jsi_transaction", /* rc==JSI_ERROR, nTransaction!=0 */
"COMMIT", /* rc!=JSI_ERROR, nTransaction==0 */
"ROLLBACK TO _jsi_transaction ; RELEASE _jsi_transaction",
"ROLLBACK" /* rc==JSI_ERROR, nTransaction==0 */
};
Jsi_RC rc = result;
const char *zEnd;
jdb->nTransaction--;
zEnd = azEnd[(rc==JSI_ERROR)*2 + (jdb->nTransaction==0)];
jdb->disableAuth++;
if( sqlite3_exec(jdb->db, zEnd, 0, 0, 0)) {
/* This is a tricky scenario to handle. The most likely cause of an
** error is that the exec() above was an attempt to commit the
** top-level transaction that returned SQLITE_BUSY. Or, less likely,
** that an IO-error has occured. In either case, throw a Jsi exception
** and try to rollback the transaction.
**
** But it could also be that the user executed one or more BEGIN,
** COMMIT, SAVEPOINT, RELEASE or ROLLBACK commands that are confusing
** this method's logic. Not clear how this would be best handled.
*/
if( rc!=JSI_ERROR ) {
Jsi_LogError("%s", sqlite3_errmsg(jdb->db));
rc = JSI_ERROR;
}
sqlite3_exec(jdb->db, "ROLLBACK", 0, 0, 0);
}
jdb->disableAuth--;
return rc;
}
|
CWE-120
| null | 520,353 |
126486647134540163081069512284907193928
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC dbEvalInit(
Jsi_Interp *interp,
DbEvalContext *p, /* Pointer to structure to initialize */
Jsi_Db *jdb, /* Database handle */
const char* zSql, /* Value containing SQL script */
Jsi_DString *dStr,
Jsi_Obj *pArray, /* Name of Jsi array to set (*) element of */
Jsi_Obj *pValVar /* Name element in array for list. */
) {
p->dSql = dStr;
p->zSql = Jsi_DSAppend(p->dSql, zSql?zSql:"", NULL);
p->jdb = jdb;
return JSI_OK;
}
|
CWE-120
| null | 520,354 |
162135227120449011732159918946506416027
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_DbQuery(Jsi_Db *jdb, Jsi_CDataDb *dPtr, const char *query)
{
if (!jsi_dbVfsPtr) {
printf( "Sqlite unsupported\n");
return -1;
}
return jsi_dbVfsPtr->dbcQuery(jdb, dPtr, query);
}
|
CWE-120
| null | 520,355 |
340119139131066299426647464257320220695
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_OpCodes *code_jtrue_np(int off) { JSI_NEW_CODES(0,OP_JTRUE_NP, off); }
|
CWE-120
| null | 520,356 |
113054441452291991887040189739795210319
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
const char* Jsi_KeyAdd(Jsi_Interp *interp, const char *str)
{
Jsi_MapEntry *hPtr;
bool isNew;
hPtr = Jsi_MapEntryNew(interp->strKeyTbl, str, &isNew);
assert(hPtr) ;
return (const char*)Jsi_MapKeyGet(hPtr, 0);
}
|
CWE-120
| null | 520,357 |
262955291178205471763969759860302828960
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static int codes_insert(Jsi_OpCodes *c, jsi_Eopcode code, void *extra, int doalloc)
{
if (c->code_size - c->code_len <= 0) {
c->code_size += 100;
c->codes = (jsi_OpCode *)Jsi_Realloc(c->codes, c->code_size * sizeof(jsi_OpCode));
}
c->codes[c->code_len].op = code;
c->codes[c->code_len].data = extra;
c->codes[c->code_len].alloc = doalloc;
c->code_len ++;
return 0;
}
|
CWE-120
| null | 520,358 |
277767665704154987817062854825290030128
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_DbQuery(Jsi_Db *jdb, Jsi_CDataDb *dbopts, const char *query)
{
int rc = jsi_DbQuery(jdb, dbopts, query);
#ifdef JSI_DBQUERY_ERRORCMD
if (rc<0)
rc = JSI_DBQUERY_ERRORCMD(jdb, specs, data, arrSize, query, dopts, rc);
#endif
return rc;
}
|
CWE-120
| null | 520,359 |
205876584629910398740324577451186414047
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_TreeEntry *Jsi_TreeEntryNew(Jsi_Tree *treePtr, const void *key, bool *isNew)
{
Jsi_TreeEntry* hPtr;
bool isn;
if (treePtr->flags.destroyed)
return NULL;
if (treePtr->opts.lockTreeProc && (*treePtr->opts.lockTreeProc)(treePtr, 1) != JSI_OK)
return NULL;
treePtr->flags.inserting=1;
if (treePtr->flags.internstr) {
Assert(treePtr->keyType == JSI_KEYS_STRINGKEY);
if (!treePtr->strHash)
treePtr->strHash = Jsi_HashNew(treePtr->opts.interp, JSI_KEYS_STRING, NULL);
key = Jsi_HashEntryNew(treePtr->strHash, key, NULL);
}
hPtr = treePtr->createProc(treePtr, key, &isn);
if (isNew)
*isNew = isn;
if (isn == 0 || treePtr->flags.nonredblack == 1 || !hPtr) {
treePtr->flags.inserting=0;
goto done;
}
treePtr->epoch++;
hPtr->f.bits.color = _JSI_TREE_RED;
if (treePtr->root == NULL) {
treePtr->root = hPtr;
} else {
Jsi_TreeEntry* n = treePtr->root;
while (1) {
int rc = treePtr->opts.compareTreeProc(treePtr, Jsi_TreeKeyGet(n) , key);
if (rc == 0) {
Assert(0);
} else if (rc < 0) {
if (n->left == NULL) {
n->left = hPtr;
break;
} else {
n = n->left;
}
} else {
if (n->right == NULL) {
n->right = hPtr;
break;
} else {
n = n->right;
}
}
}
hPtr->parent = n;
}
insert_case1(hPtr);
treePtr->flags.inserting = 0;
done:
if (treePtr->opts.lockTreeProc)
(*treePtr->opts.lockTreeProc)(treePtr, 0);
return hPtr;
}
|
CWE-120
| null | 520,360 |
270299185595693597055959300743686357610
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC jsi_wsFileAdd(Jsi_Interp *interp, jsi_wsCmdObj *cmdPtr, Jsi_Value *name) {
const char *sname = Jsi_ValueString(interp, name, NULL);
if (cmdPtr->onModify && sname) {
bool isNew = 0;
Jsi_HashEntry *hPtr = Jsi_HashEntryNew(cmdPtr->fileHash, sname, &isNew);
if (hPtr) {
jsi_wsFile* fPtr;
if (!isNew)
fPtr = Jsi_HashValueGet(hPtr);
else {
fPtr = (jsi_wsFile *)Jsi_Calloc(1, sizeof(*fPtr));
fPtr->fileVal = name;
fPtr->loadFirst = time(NULL);
Jsi_IncrRefCount(interp, name);
fPtr->flags = 0;
Jsi_HashValueSet(hPtr, fPtr);
}
fPtr->loadLast = time(NULL);
}
}
return JSI_OK;
}
|
CWE-120
| null | 520,361 |
130905635295550793131042562338730437903
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
void jsi_AddEventHandler(Jsi_Interp *interp)
{
Jsi_Event *ev;
while (!interp->EventHdlId) { /* Find an empty event slot. */
bool isNew;
uintptr_t id = ++interp->eventIdx;
Jsi_HashEntry *hPtr = Jsi_HashEntryNew(interp->eventTbl, (void*)id, &isNew);
if (!isNew)
continue;
ev = (Jsi_Event*)Jsi_Calloc(1, sizeof(*ev));
SIGINIT(ev,EVENT);
ev->id = id;
ev->handler = ThreadEvalCallback;
ev->hPtr = hPtr;
ev->evType = JSI_EVENT_ALWAYS;
Jsi_HashValueSet(hPtr, ev);
interp->EventHdlId = id;
}
}
|
CWE-120
| null | 520,362 |
310983244921653776000180050409706226501
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_HashNew(Jsi_Interp *interp, unsigned int keyType, Jsi_HashDeleteProc freeProc)
{
Jsi_Hash *tablePtr = (Jsi_Hash*)Jsi_Calloc(1,sizeof(*tablePtr));
SIGINIT(tablePtr, HASH);
tablePtr->opts.mapType = (Jsi_Map_Type)JSI_MAP_HASH;
tablePtr->typ = JSI_MAP_HASH;
tablePtr->opts.interp = interp;
tablePtr->buckets = tablePtr->staticBuckets;
#if !(JSI_SMALL_HASH_TABLE && !(JSI_SMALL_HASH_TABLE & (JSI_SMALL_HASH_TABLE - 1)))
#error "small hash must be a power of two"
#endif
tablePtr->numBuckets = JSI_SMALL_HASH_TABLE;
tablePtr->rebuildSize = JSI_SMALL_HASH_TABLE * REBUILD_MULTIPLIER;
tablePtr->downShift = DOWNSHIFT_START;
tablePtr->opts.freeHashProc = freeProc;
tablePtr->mask = (jsi_Hash)(tablePtr->numBuckets - 1);
tablePtr->opts.keyType = (Jsi_Key_Type)keyType;
tablePtr->keyType = (Jsi_Key_Type)keyType;
switch (keyType) {
case JSI_KEYS_STRING: /* NUL terminated string keys. */
tablePtr->findProc = HashStringFind;
tablePtr->createProc = HashStringCreate;
break;
case JSI_KEYS_STRINGKEY: /* Lookup from another String hash, eg. Jsi_KeyAdd() */
case JSI_KEYS_ONEWORD: /* A pointer. */
tablePtr->findProc = HashOneWordFind;
tablePtr->createProc = HashOneWordCreate;
break;
default: /* Structs. */
if (keyType < JSI_KEYS_STRUCT_MINSIZE) {
Jsi_LogError("Jsi_HashNew: Key size can't be %d, must be >= %d", keyType, JSI_KEYS_STRUCT_MINSIZE);
Jsi_Free(tablePtr);
return NULL;
}
tablePtr->findProc = jsi_HashArrayFind;
tablePtr->createProc = jsi_HashArrayCreate;
break;
}
return tablePtr;
}
|
CWE-120
| null | 520,363 |
201576285232737003371178212536889459081
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_RC Jsi_initSqlite(Jsi_Interp *interp, int release)
{
if (!release) Jsi_InterpSetData(interp, JSI_SQLITE_DB_VFS, &jsi_dbVfsPtr, NULL);
return JSI_OK;
}
|
CWE-120
| null | 520,364 |
65777949194774710892206609947637286663
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void jsi_ValueCopyMove(Jsi_Interp *interp, Jsi_Value *to, Jsi_Value *from, int isCopy ) {
if (!from) {
Jsi_ValueMakeUndef(interp, &to);
return;
}
VALCHK(from);
if( to == from) return;
int ocnt = to->refCnt;
Jsi_Value *ovt = NULL;
assert(ocnt>0);
int toVt = to->vt;
if (toVt == JSI_VT_VARIABLE) {
ovt = to->d.lval;
Jsi_IncrRefCount(interp, ovt);
}
Jsi_ValueMakeUndef(interp, &to);
#ifdef JSI_MEM_DEBUG
memcpy(to, from, sizeof(*to)-sizeof(to->VD));
to->VD.label3 = from->VD.func;
#else
*to = *from;
#endif
if (isCopy) {
if (to->refCnt) {
switch (to->vt) {
case JSI_VT_STRING:
if (!to->f.bits.isstrkey) {
to->d.s.str = Jsi_StrdupLen(to->d.s.str, to->d.s.len);
}
break;
case JSI_VT_OBJECT:
Jsi_ObjIncrRefCount(interp,to->d.obj);
break;
case JSI_VT_VARIABLE:
Jsi_IncrRefCount(interp,to->d.lval);
break;
default:
break;
}
}
to->refCnt = ocnt;
if (ovt)
Jsi_DecrRefCount(interp, ovt);
} else {
to->refCnt = ocnt;
if (ovt)
Jsi_DecrRefCount(interp, ovt);
ocnt = from->refCnt;
#ifdef JSI_MEM_DEBUG
memset(from, 0, sizeof(*to)-sizeof(to->VD));
#else
memset(from, 0, sizeof(*to));
#endif
SIGINIT(from, VALUE);
from->refCnt = ocnt;
}
}
|
CWE-120
| null | 520,365 |
42766002787788639316911633927445892943
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static int jsi_wsHttp(Jsi_Interp *interp, jsi_wsCmdObj *cmdPtr, struct lws *wsi, void *user,
struct lws_context *context, const char* inPtr, Jsi_DString *tStr, jsi_wsPss *pss)
{
const char *ext = NULL;
unsigned char buffer[JSI_BUFSIZ];
const char *mime = NULL;
time_t now = time(NULL);
char buf[JSI_BUFSIZ];
int rc = 0;
buf[0] = 0;
uchar *p = buffer, *end = &buffer[sizeof(buffer)-1];
int n;
Jsi_Value* fname = NULL;
bool isJsiWeb = 0, isSSI = 0;
cmdPtr->stats.httpLast = now;
/* if a legal POST URL, let it continue and accept data */
if (lws_hdr_total_length(wsi, WSI_TOKEN_POST_URI))
return 0;
if (!pss)
pss = jsi_wsgetPss(cmdPtr, wsi, user, 1, 1);
int uplen=(cmdPtr->urlPrefix?Jsi_Strlen(cmdPtr->urlPrefix):0);
if (inPtr && cmdPtr->urlPrefix && !Jsi_Strncmp(inPtr, cmdPtr->urlPrefix, uplen))
inPtr += uplen;
if (cmdPtr->redirDisable) {// Try to defray redirect loops.
if (difftime(now, cmdPtr->stats.redirLast)>=600)
cmdPtr->redirDisable = 0;
else
cmdPtr->redirDisable--;
}
if ((cmdPtr->urlRedirect && (inPtr == 0 || *inPtr == 0 || !Jsi_Strcmp(inPtr, "/")) && !cmdPtr->redirDisable)
&& (inPtr = cmdPtr->urlRedirect) && inPtr[0]) {
cmdPtr->stats.redirCnt++;
// TODO: system time change can disrupt the following.
if (cmdPtr->redirMax>0 && !cmdPtr->redirDisable && cmdPtr->redirMax>0 && cmdPtr->stats.redirLast
&& difftime(now, cmdPtr->stats.redirLast)<600 && ++cmdPtr->redirAllCnt>cmdPtr->redirMax)
cmdPtr->redirDisable = 100;
cmdPtr->stats.redirLast = now;
rc = lws_http_redirect(wsi, 301, (uchar*)inPtr, Jsi_Strlen(inPtr), &p, end);
return (rc == 100 ? 0 : 1);
}
if (!inPtr || !*inPtr)
inPtr = "/";
if (cmdPtr->useridPass || cmdPtr->onAuth) {
int ok = 0;
int alen;
const char *auth = jsi_wsHeader(pss, "authorization", &alen);
if (auth && !Jsi_Strncasecmp(auth, "basic ", 6) && !cmdPtr->deleted) {
auth += 6;
Jsi_DString eStr = {}, bStr = {};
Jsi_DSAppendLen(&eStr, auth, alen - 6);
Jsi_Base64(Jsi_DSValue(&eStr), -1, &bStr, 1);
const char *bp = Jsi_DSValue(&bStr);
if (bp && bp[0]) {
if (!cmdPtr->onAuth)
ok = (!Jsi_Strcmp(cmdPtr->useridPass, bp));
else {
/* Pass 4 args: ws, id, url and userid:pass . */
Jsi_Obj *oarg1;
Jsi_Value *vpargs, *vargs[10];
int n = 0;
vargs[n++] = Jsi_ValueNewObj(interp, cmdPtr->fobj);
vargs[n++] = Jsi_ValueNewNumber(interp, (Jsi_Number)(pss->wid));
vargs[n++] = Jsi_ValueNewStringDup(interp, inPtr);
vargs[n++] = Jsi_ValueNewStringDup(interp, bp);
vpargs = Jsi_ValueMakeObject(interp, NULL, oarg1 = Jsi_ObjNewArray(interp, vargs, n, 0));
Jsi_IncrRefCount(interp, vpargs);
Jsi_Value *ret = Jsi_ValueNew1(interp);
bool rb = 0;
rc = Jsi_FunctionInvoke(interp, cmdPtr->onAuth, vpargs, &ret, NULL);
if (rc == JSI_OK)
rb = !Jsi_ValueIsFalse(interp, ret);
Jsi_DecrRefCount(interp, vpargs);
Jsi_DecrRefCount(interp, ret);
if (rc != JSI_OK) {
Jsi_LogError("websock bad rcv eval");
return -1;
}
ok = rb;
}
}
Jsi_DSFree(&eStr);
Jsi_DSFree(&bStr);
}
if (!ok) {
const char *realm = (cmdPtr->realm?cmdPtr->realm:"jsish");
int n = snprintf(buf, sizeof(buf), "Basic realm=\"%s\"", realm);
if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_WWW_AUTHENTICATE,
(unsigned char *)buf, n, &p, end))
return -1;
if (jsi_wsServeString(pss, wsi, "Password is required to access this page", 401, (char*)buffer, NULL)<0)
return -1;
return lws_http_transaction_completed(wsi);
}
}
if (cmdPtr->onGet || pss->onGet) {
Jsi_RC jrc;
int rrv = 1;
if (cmdPtr->getRegexp) {
rrv = 0;
jrc = Jsi_RegExpMatch(interp, cmdPtr->getRegexp, inPtr, &rrv, NULL);
if (jrc != JSI_OK)
return -1; // Error in regexp.
}
if (rrv) {
jrc = jsi_wsGetCmd(interp, cmdPtr, pss, wsi, inPtr, pss->onGet?pss->onGet:cmdPtr->onGet, tStr);
switch (jrc) {
case JSI_ERROR: return -1;
case JSI_OK: return 0;
case JSI_SIGNAL:
return jsi_ws_http_redirect(wsi, 302, tStr, &p, end);
case JSI_CONTINUE:
inPtr = Jsi_DSValue(tStr); break;
case JSI_BREAK: break;
default: break;
}
}
}
ext = Jsi_Strrchr(inPtr, '.');
Jsi_Value *rdir = (pss->rootdir?pss->rootdir:cmdPtr->rootdir);
cmdPtr->curRoot = (rdir?Jsi_ValueString(cmdPtr->interp, rdir, NULL):"./");
Jsi_DString sStr;
Jsi_DSInit(&sStr);
jsi_wsPathAlias(interp, cmdPtr, &inPtr, &sStr);
snprintf(buf, sizeof(buf), "%s/%s", cmdPtr->curRoot, inPtr);
Jsi_DSFree(&sStr);
if (cmdPtr->debug>1)
fprintf(stderr, "FILE: %s in %s | %s\n", buf, cmdPtr->curRoot, Jsi_ValueString(interp, cmdPtr->rootdir, NULL));
char extBuf[JSI_BUFSIZ], *cpde = Jsi_Strrchr(buf, '/');
isJsiWeb = (cpde && cmdPtr->jsiFnPattern && Jsi_GlobMatch(cmdPtr->jsiFnPattern, cpde+1, 0));
bool isgzip = 0;
if (!ext || !ext[1])
mime = "text/html";
else {
const char *eext = ext+1;
uint elen = Jsi_Strlen(ext);
if (elen>3 && elen<(sizeof(extBuf)-10) && !Jsi_Strcmp(ext+elen-3,".gz")) {
Jsi_Strcpy(extBuf, ext);
extBuf[elen-3] = 0;
char *ext2 = Jsi_Strrchr(extBuf, '.');
if (ext2) {
isgzip = 1;
ext = ext2;
}
}
Jsi_HashEntry *hPtr;
if (cmdPtr->mimeTypes) {
/* Lookup mime type in mimeTypes object. */
Jsi_Value *mVal = Jsi_ValueObjLookup(interp, cmdPtr->mimeTypes, ext+1, 1);
if (mVal)
mime = Jsi_ValueString(interp, mVal, NULL);
}
if (!mime) {
static const char* mtypes[] = {
"html", "text/html", "js", "application/x-javascript",
"css", "text/css", "png", "image/png", "ico", "image/icon",
"gif", "image/gif", "jpeg", "image/jpeg",
"jpg", "image/jpeg", "svg", "image/svg+xml",
"json", "application/json", "txt", "text/plain",
"jsi", "application/x-javascript", "cssi", "text/css",
"shtml", "text/html", "scss", "text/css",
"sjs", "application/x-javascript",
0, 0
};
mime = "text/html";
int i;
for (i=0; mtypes[i]; i+=2)
if (tolower(*eext) == mtypes[i][0] && !Jsi_Strncasecmp(eext, mtypes[i], -1)) {
mime = mtypes[i+1];
break;
}
}
isSSI = jsi_wsIsSSIExt(interp, cmdPtr, pss, eext);
if ((hPtr = Jsi_HashEntryFind(cmdPtr->handlers, ext)) && !cmdPtr->deleted) {
/* Use interprete html eg. using jsi_wpp preprocessor */
Jsi_DString jStr = {};
Jsi_Value *vrc = NULL;
int hrc = 0, strLen, evrc, isalloc=0;
char *vStr, *hstr = NULL;
jsi_wsHander *hdlPtr = (jsi_wsHander*)Jsi_HashValueGet(hPtr);
Jsi_Value *hv = hdlPtr->val;
if (Jsi_Strchr(buf, '\'') || Jsi_Strchr(buf, '\"')) {
jsi_wsServeString(pss, wsi, "Can not handle quotes in url", 404, NULL, NULL);
return -1;
}
cmdPtr->handlersPkg=1;
// Attempt to load package and get function.
if ((hdlPtr->flags&1) && cmdPtr->handlersPkg && Jsi_ValueIsString(interp, hv)
&& ((hstr = Jsi_ValueString(interp, hv, NULL)))) {
vrc = Jsi_NameLookup(interp, hstr);
if (!vrc) {
Jsi_Number pver = Jsi_PkgRequire(interp, hstr, 0);
if (pver >= 0)
vrc = Jsi_NameLookup(interp, hstr);
}
if (!vrc || !Jsi_ValueIsFunction(interp, vrc)) {
if (vrc)
Jsi_DecrRefCount(interp, vrc);
Jsi_LogError("Failed to autoload handle: %s", hstr);
jsi_wsServeString(pss, wsi, "Failed to autoload handler", 404, NULL, NULL);
return -1;
}
if (hdlPtr->val)
Jsi_DecrRefCount(interp, hdlPtr->val);
hdlPtr->val = vrc;
Jsi_IncrRefCount(interp, vrc);
hv = vrc;
}
if ((hdlPtr->flags&2) && !hdlPtr->triedLoad && !hdlPtr->objVar && Jsi_ValueIsFunction(interp, hv)) {
// Run command and from returned object get the parse function.
hdlPtr->triedLoad = 1;
Jsi_DSAppend(&jStr, "[null]", NULL);
Jsi_DSAppend(&jStr, "]", NULL);
vrc = Jsi_ValueNew1(interp);
evrc = Jsi_FunctionInvokeJSON(interp, hv, Jsi_DSValue(&jStr), &vrc);
if (Jsi_InterpGone(interp))
return -1;
if (evrc != JSI_OK || !vrc || !Jsi_ValueIsObjType(interp, vrc, JSI_OT_OBJECT)) {
Jsi_LogError("Failed to load obj: %s", hstr);
jsi_wsServeString(pss, wsi, "Failed to load obj", 404, NULL, NULL);
return -1;
}
Jsi_Value *fvrc = Jsi_ValueObjLookup(interp, vrc, "parse", 0);
if (!fvrc || !Jsi_ValueIsFunction(interp, fvrc)) {
Jsi_LogError("Failed to find parse: %s", hstr);
jsi_wsServeString(pss, wsi, "Failed to find parse", 404, NULL, NULL);
return -1;
}
hdlPtr->objVar = fvrc;
Jsi_IncrRefCount(interp, fvrc);
hv = vrc;
}
if (hdlPtr->objVar) { // Call the obj.parse function.
Jsi_DSAppend(&jStr, "[\"", buf, "\"]", NULL); // TODO: JSON encode.
vrc = Jsi_ValueNew1(interp);
evrc = Jsi_FunctionInvokeJSON(interp, hdlPtr->objVar, Jsi_DSValue(&jStr), &vrc);
isalloc = 1;
}
else if (Jsi_ValueIsFunction(interp, hv)) {
//printf("CNCNN: %s\n", Jsi_DSValue(&cmdPtr->cName));
Jsi_DSAppend(&jStr, "[\"", buf, "\", {wsName:\"", Jsi_DSValue(&cmdPtr->cName), "\"", "}]", NULL); // TODO: JSON encode.
vrc = Jsi_ValueNew1(interp);
evrc = Jsi_FunctionInvokeJSON(interp, hv, Jsi_DSValue(&jStr), &vrc);
isalloc = 1;
} else {
// One shot invoke of string command.
hstr = Jsi_ValueString(interp, hv, NULL);
Jsi_DSAppend(&jStr, hstr, "('", buf, "');", NULL);
evrc = Jsi_EvalString(interp, Jsi_DSValue(&jStr), JSI_EVAL_RETURN);
if (evrc == JSI_OK)
vrc = Jsi_InterpResult(interp);
}
// Take result from vrc and return it.
if (evrc != JSI_OK) {
Jsi_LogError("failure in websocket handler");
} else if ((!vrc) ||
(!(vStr = Jsi_ValueString(interp, vrc, &strLen)))) {
Jsi_LogError("failed to get result");
} else {
hrc = jsi_wsServeString(pss, wsi, vStr, 0, NULL, mime);
}
Jsi_DSFree(&jStr);
if (isalloc)
Jsi_DecrRefCount(interp, vrc);
if (hrc<=0)
return -1;
return 1;
}
}
if (!buf[0]) {
if (cmdPtr->debug)
fprintf(stderr, "empty file: %s\n", inPtr);
return -1;
}
fname = Jsi_ValueNewStringDup(interp, buf);
Jsi_IncrRefCount(interp, fname);
Jsi_DString hStr = {};
Jsi_StatBuf jsb;
bool native = Jsi_FSNative(interp, fname);
if ((native && Jsi_InterpSafe(interp) && Jsi_InterpAccess(interp, fname, JSI_INTACCESS_READ) != JSI_OK) ||
(Jsi_Stat(interp, fname, &jsb) || jsb.st_size<=0)) {
nofile:
if (cmdPtr->onUnknown || pss->onUnknown) {
Jsi_Value *uk = (pss->onUnknown?pss->onUnknown:cmdPtr->onUnknown);
Jsi_RC jrc = jsi_wsGetCmd(interp, cmdPtr, pss, wsi, inPtr, uk, NULL);
if (jrc == JSI_ERROR)
goto bail;
if (jrc == JSI_OK)
goto done;
}
if (0 && Jsi_Strstr(buf, "favicon.ico"))
rc = jsi_wsServeString(pss, wsi, "data:;base64,iVBORw0KGgo=", 200, NULL, "image/icon");
else {
const char *cp = Jsi_Strrchr(buf,'/');
if (cp && cp[1]) {
char statPath[PATH_MAX];
snprintf(statPath, sizeof(statPath), "/zvfs/lib/web%s", cp);
Jsi_DecrRefCount(interp, fname);
fname = Jsi_ValueNewStringDup(interp, statPath);
Jsi_IncrRefCount(interp, fname);
if (!Jsi_Stat(interp, fname, &jsb) && jsb.st_size>0) {
native = 0;
goto serve;
}
}
if (cmdPtr->noWarn==0 && !Jsi_Strstr(buf, "favicon.ico"))
fprintf(stderr, "failed open file for read: %s\n", buf);
rc = jsi_wsServeString(pss, wsi, "<b style='color:red'>ERROR: can not serve file!</b>", 404, NULL, NULL);
}
Jsi_DecrRefCount(interp, fname);
goto done;
}
if (!ext || isSSI)
goto serve;
if (S_ISDIR(jsb.st_mode)) {
if (cmdPtr->noWarn==0)
fprintf(stderr, "can not serve directory: %s\n", buf);
rc = jsi_wsServeString(pss, wsi, "<b style='color:red'>ERROR: can not serve directory!</b>", 404, NULL, NULL);
Jsi_DecrRefCount(interp, fname);
goto done;
}
serve:
n = 0;
// TODO: add automatic cookie mgmt?
/*
if (!strcmp((const char *)in, "/") &&
!lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_COOKIE)) {
gettimeofday(&tv, NULL);
n = sprintf(b64, "test=LWS_%u_%u_COOKIE;Max-Age=360000",
(unsigned int)tv.tv_sec,
(unsigned int)tv.tv_usec);
if (lws_add_http_header_by_name(wsi,
(unsigned char *)"set-cookie:",
(unsigned char *)b64, n, &p,
(unsigned char *)buffer + sizeof(buffer)))
return 1;
}*/
static const char stsStr[] = "max-age=15768000 ; includeSubDomains";
if (lws_is_ssl(wsi) && lws_add_http_header_by_name(wsi,
(uchar *) "Strict-Transport-Security:",
(uchar *) stsStr,
sizeof(stsStr)-1, &p, (uchar *)buffer + sizeof(buffer)))
goto bail;
n = p - buffer;
if (n>0)
Jsi_DSAppendLen(&hStr, (char*)buffer, n);
p = buffer;
if (isgzip) {
if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_ENCODING,
(unsigned char *)"gzip", n, &p, end))
goto bail;
}
if (cmdPtr->headers && !jsi_wsAddHeader(interp, cmdPtr, wsi, cmdPtr->headers, &hStr))
goto bail;
if (pss->headers && !jsi_wsAddHeader(interp, cmdPtr, wsi, pss->headers, &hStr))
goto bail;
n = Jsi_DSLength(&hStr);
if (native && !isSSI && !isJsiWeb) {
if (!jsi_wsAddStdHeader(interp, cmdPtr, wsi, &hStr)) {
Jsi_DecrRefCount(interp, fname);
goto bail;
}
int hrc = lws_serve_http_file(wsi, buf, mime, Jsi_DSValue(&hStr), Jsi_DSLength(&hStr));
if (hrc >= 0 && cmdPtr->onModify)
jsi_wsFileAdd(interp, cmdPtr, fname);
Jsi_DecrRefCount(interp, fname);
if (hrc<0) {
if (cmdPtr->noWarn==0)
fprintf(stderr, "can not serve file (%d): %s\n", hrc, buf);
goto bail;
} else if (hrc > 0 && lws_http_transaction_completed(wsi))
goto bail;
} else {
// Need to read data for non-native files.
Jsi_DString dStr = {}, fStr = {};
if (isSSI)
rc = jsi_wsEvalSSI(interp, cmdPtr, fname, &fStr, 1, pss);
else {
rc = jsi_wsFileRead(interp, fname, &fStr, cmdPtr, pss);
if (isJsiWeb)
Jsi_DSAppend(&fStr, "\nwindow.jsiWebSocket=true;", NULL);
}
if (rc != JSI_OK) {
Jsi_DSFree(&fStr);
goto nofile;
}
int hrc = jsi_wsServeHeader(pss, wsi, (int)Jsi_DSLength(&fStr), 200, Jsi_DSValue(&hStr), mime, &dStr);
if (hrc>=0) {
Jsi_DSAppendLen(&dStr, Jsi_DSValue(&fStr), Jsi_DSLength(&fStr));
char *strVal = Jsi_DSValue(&dStr);
int strLen = Jsi_DSLength(&dStr);
hrc = jsi_wswrite(pss, wsi, (unsigned char*)strVal, strLen, LWS_WRITE_HTTP);
}
Jsi_DecrRefCount(interp, fname);
Jsi_DSFree(&dStr);
Jsi_DSFree(&fStr);
if (hrc<0) {
if (cmdPtr->noWarn==0)
fprintf(stderr, "can not serve data (%d): %s\n", hrc, buf);
goto bail;
} else if (hrc > 0 && lws_http_transaction_completed(wsi))
goto bail;
}
done:
Jsi_DSFree(&hStr);
return rc;
bail:
rc = 1;
goto done;
}
|
CWE-120
| null | 520,366 |
260012632305379437622112185326569917875
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
void jsi_ToHexStr(const uchar *indata, int dlen, char *out) {
static char hex[] = "0123456789abcdef";
int i, n=0;
for (i=0; i<dlen; i++) {
int c = indata[i];
out[n++] = hex[(c>>4)&0xf];
out[n++] = hex[c&0xf];
}
out[n] = 0;
}
|
CWE-120
| null | 520,367 |
330490174999729090042973701517151917423
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC mdbEvalStep(MyDbEvalContext *p) {
Jsi_RC rc = JSI_OK;
if( p->prep==0)
rc = mdbEvalPrep(p);
if (rc == JSI_BREAK)
return JSI_BREAK;
if (rc == JSI_OK)
rc = mdbEvalStepSub(p, 1, NULL);
return rc;
}
|
CWE-120
| null | 520,368 |
109807650935635029574042830257217390914
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_OpCodes *code_push_vstring(jsi_Pstate *p, jsi_Pline *line, Jsi_String *s) {
JSI_NEW_CODESLN(0,OP_PUSHVSTR, s);
}
|
CWE-120
| null | 520,369 |
178050715869487236314663250734447965297
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_Value* Jsi_ValueNewString(Jsi_Interp *interp, const char *s, int len) {
assert(s);
Jsi_Value *v = Jsi_ValueNew(interp);
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<0?Jsi_Strlen(s):(uint)len);
return v;
}
|
CWE-120
| null | 520,370 |
253351359762816717223426611214849106242
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC NumberIsFiniteCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr) {
return jsi_NumberIsFiniteCmd(interp, args, _this, ret, funcPtr, 1);
}
|
CWE-120
| null | 520,371 |
257965292224013978435265019856900980393
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC JSONStringifyCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
bool strict = 1;
Jsi_Value *jsv = Jsi_ValueArrayIndex(interp, args, 1);
if (jsv && Jsi_ValueGetBoolean(interp, jsv, &strict) != JSI_OK)
return Jsi_LogError("Expected boolean");
int quote = JSI_OUTPUT_JSON;
if (strict) quote|=JSI_JSON_STRICT;
Jsi_DString dStr = {};
Jsi_Value *arg = Jsi_ValueArrayIndex(interp, args, 0);
Jsi_ValueGetDString(interp, arg, &dStr, quote);
Jsi_ValueFromDS(interp, &dStr, ret);
return JSI_OK;
}
|
CWE-120
| null | 520,372 |
64021846404997471871833647133238985641
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void dbEvalSetColumnJSON(DbEvalContext *p, int iCol, Jsi_DString *dStr) {
Jsi_Interp *interp = p->jdb->interp;
char nbuf[JSI_MAX_NUMBER_STRING];
sqlite3_stmt *pStmt = p->pPreStmt->pStmt;
switch( sqlite3_column_type(pStmt, iCol) ) {
case SQLITE_BLOB: {
int bytes = sqlite3_column_bytes(pStmt, iCol);
const char *zBlob = (char*)sqlite3_column_blob(pStmt, iCol);
if( !zBlob ) {
Jsi_DSAppend(dStr, "null", NULL);
return;
}
Jsi_JSONQuote(interp, zBlob, bytes, dStr);
return;
}
case SQLITE_INTEGER: {
sqlite_int64 v = sqlite3_column_int64(pStmt, iCol);
if (v==0 || v==1) {
const char *dectyp = sqlite3_column_decltype(pStmt, iCol);
if (dectyp && !Jsi_Strncasecmp(dectyp,"bool", 4)) {
Jsi_DSAppend(dStr, (v?"true":"false"), NULL);
return;
}
}
#ifdef __WIN32
snprintf(nbuf, sizeof(nbuf), "%" PRId64, (Jsi_Wide)v);
#else
snprintf(nbuf, sizeof(nbuf), "%lld", v);
#endif
Jsi_DSAppend(dStr, nbuf, NULL);
return;
}
case SQLITE_FLOAT: {
Jsi_NumberToString(interp, sqlite3_column_double(pStmt, iCol), nbuf, sizeof(nbuf));
Jsi_DSAppend(dStr, nbuf, NULL);
return;
}
case SQLITE_NULL: {
Jsi_DSAppend(dStr, "null", NULL);
return;
}
}
const char *str = (char*)sqlite3_column_text(pStmt, iCol );
if (!str)
str = p->jdb->optPtr->nullvalue;
Jsi_JSONQuote(interp, str?str:"", -1, dStr);
}
|
CWE-120
| null | 520,373 |
312970571117139483455109363605632034737
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
void Jsi_MutexDelete(Jsi_Interp *interp, Jsi_Mutex *mtx) { }
|
CWE-120
| null | 520,374 |
196814076429482240116787037521811265918
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_OptionsConf(Jsi_Interp *interp, Jsi_OptionSpec *specs, void *rec, Jsi_Value *val, Jsi_Value **ret, Jsi_Wide flags)
{
flags |= JSI_OPTS_IS_UPDATE;
if (!Jsi_OptionsValid(interp, specs))
return Jsi_LogError("invalid options");
if (!val)
return Jsi_OptionsDump(interp, specs, rec, ret, flags);
if (val->vt == JSI_VT_NULL)
return Jsi_OptionsDump(interp, specs, rec, ret, flags|JSI_OPTS_VERBOSE);
if (Jsi_ValueIsString(interp, val)) {
const char *cp = Jsi_ValueString(interp, val, NULL);
if (cp && *cp)
return Jsi_OptionsGet(interp, specs, rec, cp, ret, flags);
Jsi_Obj *sobj = Jsi_ObjNewType(interp, JSI_OT_ARRAY);
Jsi_Value *svalue = Jsi_ValueMakeObject(interp, NULL, sobj);
jsi_DumpOptionSpecs(interp, sobj, specs);
Jsi_ValueReplace(interp, ret, svalue);
return JSI_OK;
}
if (val->vt != JSI_VT_OBJECT)
return Jsi_LogError("expected string, object, or null");
if (Jsi_OptionsProcess(interp, specs, rec, val, JSI_OPTS_IS_UPDATE|flags) < 0)
return JSI_ERROR;
return JSI_OK;
}
|
CWE-120
| null | 520,375 |
311778908499102777674648369166855430516
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
void *Jsi_TreeKeyGet(Jsi_TreeEntry *hPtr)
{
Jsi_Tree *t = hPtr->treePtr;
return (t->keyType == JSI_KEYS_ONEWORD || t->keyType == JSI_KEYS_STRINGKEY ? hPtr->key.oneWordValue : hPtr->key.string);
}
|
CWE-120
| null | 520,376 |
66572538717013700949924242389193516139
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
bool Jsi_MapUnset(Jsi_Map *mapPtr, const void *key){
SIGASSERT(mapPtr, MAP);
switch (mapPtr->typ) {
case JSI_MAP_HASH: return Jsi_HashUnset(mapPtr->v.hash, (void*)key);
case JSI_MAP_TREE: return Jsi_TreeUnset(mapPtr->v.tree, (void*)key);
case JSI_MAP_LIST: {
/*Jsi_ListEntry* lptr = (key == NULL? Jsi_ListGetFront(mapPtr->v.list) : Jsi_ListGetBack(mapPtr->v.list));
if (lptr)
return Jsi_ListUnset(lptr);*/
break;
}
case JSI_MAP_NONE: break;
}
return false;
}
|
CWE-120
| null | 520,377 |
4425944704665728749749191677858093076
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
jsi_wsGetHeaders(jsi_wsPss *pss, struct lws *wsi, Jsi_DString* dStr, int lens[], int hmax)
{
int n = 0, i = 0, nlen;
char buf[JSI_BUFSIZ];
const char *cp;
while ((cp = (char*)lws_token_to_string((enum lws_token_indexes)n))) {
int len = lws_hdr_copy(wsi, buf, sizeof(buf), ( enum lws_token_indexes)n);
n++;
if (i>=(n*2+2)) break;
if (len<=0) continue;
buf[sizeof(buf)-1] = 0;
if (!buf[0]) continue;
nlen = Jsi_Strlen(cp);
if (nlen>0 && cp[nlen-1]==' ') nlen--;
if (nlen>0 && cp[nlen-1]==':') nlen--;
Jsi_DSAppendLen(dStr, cp, nlen);
Jsi_DSAppend(dStr, "=", buf, "\n", NULL);
if (lens) {
lens[i++] = nlen;
lens[i++] = Jsi_Strlen(buf);
}
}
//printf("HEE: %d = %s\n", pss->wid, Jsi_DSValue(dStr) );
return i;
}
|
CWE-120
| null | 520,378 |
338640284277112863418906541085319095274
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC StringReplaceCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
/* Now handles perl regex flag extensions.*/
const char *source_str;
int source_len, bLen;
const char *replace_str = NULL;
int replace_len;
int regexec_flags = 0;
Jsi_Value *seq, *strVal;
Jsi_DString dStr = {};
regex_t *regex;
Jsi_Regex *re;
const char *p;
int maxArgs = 1;
int offset = 0, n, j, isglob = 0, num_matches = 0;
/* Is a generic String.replace if _this->d.obj is a function */
ChkString(_this, funcPtr, source_str, &source_len, &bLen);
source_len = bLen;
if (!skip)
strVal = _this;
else
strVal = Jsi_ValueArrayIndex(interp, args, 0);
seq = Jsi_ValueArrayIndex(interp, args, skip);
Jsi_Value *repVal = Jsi_ValueArrayIndex(interp, args, 1+skip);
if (!Jsi_ValueIsFunction(interp, repVal))
replace_str = Jsi_ValueToString(interp, repVal, &replace_len);
else
maxArgs = repVal->d.obj->d.fobj->func->argnames->argCnt;
Jsi_DSInit(&dStr);
if (Jsi_ValueIsString(interp, seq)) {
const char *ce, *cp = Jsi_ValueString(interp, seq, NULL);
if (!(ce = Jsi_Strstr(source_str, cp)))
Jsi_ValueMakeStringDup(interp, ret, source_str);
else {
int slen;
slen = (ce-source_str);
if (slen)
Jsi_DSAppendLen(&dStr, source_str, slen);
if (replace_str)
Jsi_DSAppendLen(&dStr, replace_str, replace_len);
else {
Jsi_Value *inStr = Jsi_ValueNewStringDup(interp, source_str);
Jsi_IncrRefCount(interp, inStr);
Jsi_RC rc = Jsi_FunctionInvokeString(interp, repVal, inStr, &dStr);
if (Jsi_InterpGone(interp))
return JSI_ERROR;
if (rc != JSI_OK) {
Jsi_DSFree(&dStr);
Jsi_DecrRefCount(interp, inStr);
return JSI_ERROR;
}
Jsi_DecrRefCount(interp, inStr);
}
Jsi_DSAppend(&dStr, ce+Jsi_Strlen(cp), NULL);
Jsi_ValueFromDS(interp, &dStr, ret);
}
return JSI_OK;
}
if (seq == NULL || seq->vt != JSI_VT_OBJECT || seq->d.obj->ot != JSI_OT_REGEXP) {
Jsi_ValueMakeNull(interp, ret);
return JSI_OK;
}
re = seq->d.obj->d.robj;
regex = &re->reg;
isglob = (re->eflags & JSI_REG_GLOB);
regmatch_t pmatch[MAX_SUBREGEX] = {};
/* If an offset has been specified, adjust for that now.
* If it points past the end of the string, point to the terminating null
*/
int eoffset=0;
if (offset) {
if (offset < 0) {
offset += source_len + 1;
}
if (offset > source_len) {
offset = source_len;
}
else if (offset < 0) {
offset = 0;
}
}
Jsi_DSAppendLen(&dStr, source_str, offset);
n = source_len - offset;
p = source_str + offset;
Jsi_RC rc = JSI_OK;
do {
if (num_matches > 10000000) {
Jsi_LogBug("regexp infinite loop");
rc = JSI_ERROR;
break;
}
int match = regexec(regex, p, MAX_SUBREGEX, pmatch, regexec_flags);
if (match >= REG_BADPAT) {
char buf[JSI_MAX_NUMBER_STRING];
regerror(match, regex, buf, sizeof(buf));
Jsi_LogError("error while matching pattern: %s", buf);
Jsi_DSFree(&dStr);
return JSI_ERROR;
}
if (match == REG_NOMATCH) {
break;
}
num_matches++;
Jsi_DSAppendLen(&dStr, p, pmatch[0].rm_so);
if (replace_str && !Jsi_Strchr(replace_str, '$'))
Jsi_DSAppend(&dStr, replace_str, NULL);
else if (replace_str) {
for (j = 0; j < replace_len; j++) {
int idx;
int c = replace_str[j];
if (c == '$' && j < replace_len) {
c = replace_str[++j];
if ((c >= '0') && (c <= '9')) {
idx = c - '0';
} else if (c == '&') {
idx = 0;
} else if (c == '$') {
Jsi_DSAppendLen(&dStr, replace_str + j, 1);
continue;
}
else if (c == '\'') {
Jsi_DSAppendLen(&dStr, p + pmatch[0].rm_eo, pmatch[0].rm_eo-Jsi_Strlen(p));
continue;
}
else if (c == '`') {
Jsi_DSAppendLen(&dStr, p, pmatch[0].rm_so);
continue;
}
else {
Jsi_DSAppendLen(&dStr, replace_str + j - 1, 2);
continue;
}
} else {
Jsi_DSAppendLen(&dStr, replace_str + j, 1);
continue;
}
if ((idx < MAX_SUBREGEX) && pmatch[idx].rm_so != -1 && pmatch[idx].rm_eo != -1) {
Jsi_DSAppendLen(&dStr, p + pmatch[idx].rm_so,
pmatch[idx].rm_eo - pmatch[idx].rm_so);
}
}
} else {
Jsi_DString sStr;
Jsi_DSInit(&sStr);
if (pmatch[0].rm_so <= 0 && pmatch[0].rm_eo <= 0)
break;
int olen = -1;
char *ostr = jsi_SubstrDup(p, -1, pmatch[0].rm_so, pmatch[0].rm_eo - pmatch[0].rm_so, &olen);
Jsi_Value *inStr = Jsi_ValueMakeBlob(interp, NULL, (uchar*)ostr, olen);
Jsi_DSFree(&sStr);
Jsi_IncrRefCount(interp, inStr);
if (maxArgs==1) {
Jsi_RC rc = Jsi_FunctionInvokeString(interp, repVal, inStr, &dStr);
if (Jsi_InterpGone(interp))
return JSI_ERROR;
if (rc != JSI_OK) {
Jsi_DSFree(&dStr);
Jsi_DecrRefCount(interp, inStr);
return JSI_ERROR;
}
} else {
Jsi_Value *vpargs, *items[MAX_SUBREGEX] = {}, *ret;
int i;
items[0] = inStr;
for (i=1; i<=(int)re->reg.re_nsub && i<(MAX_SUBREGEX-3); i++) {
if (pmatch[i].rm_so<0)
items[i] = interp->NullValue;
else {
ostr = jsi_SubstrDup(p, -1, pmatch[i].rm_so, pmatch[i].rm_eo - pmatch[i].rm_so, &olen);
items[i] = Jsi_ValueMakeBlob(interp, NULL, (uchar*)ostr, olen);
}
}
items[i++] = Jsi_ValueMakeNumber(interp, NULL, eoffset+pmatch[0].rm_so);
items[i++] = strVal;
vpargs = Jsi_ValueMakeObject(interp, NULL, Jsi_ObjNewArray(interp, items, i, 0));
Jsi_IncrRefCount(interp, vpargs);
ret = Jsi_ValueNew1(interp);
rc = Jsi_FunctionInvoke(interp, repVal, vpargs, &ret, NULL);
if (Jsi_InterpGone(interp))
return JSI_ERROR;
Jsi_DecrRefCount(interp, vpargs);
if (rc == JSI_OK)
Jsi_DSAppend(&dStr, Jsi_ValueToString(interp, ret, NULL), NULL);
Jsi_DecrRefCount(interp, ret);
if (rc != JSI_OK) {
Jsi_DSFree(&dStr);
Jsi_DecrRefCount(interp, inStr);
return JSI_ERROR;
}
}
Jsi_DecrRefCount(interp, inStr);
}
eoffset += pmatch[0].rm_eo;
p += pmatch[0].rm_eo;
n -= pmatch[0].rm_eo;
/* If -all is not specified, or there is no source left, we are done */
if (!isglob || n == 0 || pmatch[0].rm_eo == 0) {
break;
}
/* An anchored pattern without -line must be done */
if ((re->eflags & JSI_REG_NEWLINE) == 0 && re->pattern[0] == '^') {
break;
}
/* If the pattern is empty, need to step forwards */
if (re->pattern[0] == '\0' && n) {
/* Need to copy the char we are moving over */
Jsi_DSAppendLen(&dStr, p, 1);
p++;
n--;
}
regexec_flags |= REG_NOTBOL;
} while (n);
/*
* Copy the portion of the string after the last match to the
* result variable.
*/
Jsi_DSAppend(&dStr, p, NULL);
Jsi_ValueFromDS(interp, &dStr, ret);
return rc;
}
|
CWE-120
| null | 520,379 |
75998632061432095449336309107337672522
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC jsi_PushVar(jsi_Pstate *ps, jsi_OpCode *ip, jsi_ScopeChain *scope, Jsi_Value *currentScope, int context_id) {
Jsi_Interp *interp = ps->interp;
jsi_FastVar *fvar = (typeof(fvar))ip->data;
SIGASSERT(fvar,FASTVAR);
Jsi_Value **dvPtr = &_jsi_STACKIDX(interp->framePtr->Sp), *dv = *dvPtr, *v = NULL;
if (fvar->context_id == context_id && fvar->ps == ps) {
v = fvar->lval;
} else {
char *varname = fvar->varname;
v = Jsi_ValueObjLookup(interp, currentScope, varname, 1);
if (v) {
fvar->local = 1;
if (v->vt == JSI_VT_UNDEF) {
v->d.lookupFail = varname;
v->f.bits.lookupfailed = 1;
}
} else {
v = jsi_ScopeChainObjLookupUni(scope, varname);
if (v)
fvar->local = 1;
else {
/* add to global scope. TODO: do not define if a right_val??? */
Jsi_Value *global_scope = scope->chains_cnt > 0 ? scope->chains[0]:currentScope;
Jsi_Value key = VALINIT, *kPtr = &key; // Note: a string key so no reset needed.
Jsi_ValueMakeStringKey(interp, &kPtr, varname);
v = jsi_ValueObjKeyAssign(interp, global_scope, &key, NULL, JSI_OM_DONTENUM);
if (v->vt == JSI_VT_UNDEF) {
v->d.lookupFail = varname;
v->f.bits.lookupfailed = 1;
}
jsi_ValueDebugLabel(v, "var", varname);
bool isNew;
Jsi_HashEntry *hPtr = Jsi_HashEntryNew(interp->varTbl, varname, &isNew);
if (hPtr && isNew)
Jsi_HashValueSet(hPtr, 0);
}
}
Jsi_IncrRefCount(interp, v);
}
if (dv != v && (dv->vt != JSI_VT_VARIABLE || dv->d.lval != v)) {
Jsi_ValueReset(interp, dvPtr);
dv->vt = JSI_VT_VARIABLE;
SIGASSERT(v, VALUE);
dv->d.lval = v;
dv->f.bits.local = (fvar->local);
}
SIGASSERT(v, VALUE);
jsiPush(interp,1);
return JSI_OK;
}
|
CWE-120
| null | 520,380 |
337521441916272580160699306083606725857
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_Value *Jsi_ValueArrayIndex(Jsi_Interp *interp, Jsi_Value *args, int index)
{
Jsi_Obj *obj = args->d.obj;
Jsi_Value *v;
assert(args->vt == JSI_VT_OBJECT);
if (obj->isarrlist && obj->arr)
return ((index < 0 || (uint)index >= obj->arrCnt) ? NULL : obj->arr[index]);
char unibuf[JSI_MAX_NUMBER_STRING];
Jsi_NumberItoA10(index, unibuf, sizeof(unibuf));
v = Jsi_TreeObjGetValue(args->d.obj, unibuf, 0);
return v;
}
|
CWE-120
| null | 520,381 |
262075391548479636499037344373916456637
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static int tree_levelorder(Jsi_Tree *treePtr, Jsi_TreeEntry *hPtr, Jsi_TreeWalkProc *callback,
void *data, int curlev, int level, int *cnt) {
uint epoch = treePtr->epoch;
if (hPtr == NULL) return JSI_OK;
if (curlev > level) return JSI_OK;
if (curlev == level) {
if (callback(treePtr, hPtr, data) != JSI_OK || epoch != treePtr->epoch)
return JSI_ERROR;
(*cnt)++;
}
if (hPtr->right != NULL) {
if (tree_levelorder(treePtr, hPtr->right, callback, data, curlev+1, level, cnt) != JSI_OK || epoch != treePtr->epoch)
return JSI_ERROR;
}
if (hPtr->left != NULL) {
if (tree_levelorder(treePtr, hPtr->left, callback, data, curlev+1, level, cnt) != JSI_OK || epoch != treePtr->epoch)
return JSI_ERROR;
}
return JSI_OK;
}
|
CWE-120
| null | 520,382 |
218492912305500743032570164435468249055
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_OpCodes *code_typeof(jsi_Pstate *p, jsi_Pline *line, int e) { JSI_NEW_CODESLN(0,OP_TYPEOF, e); }
|
CWE-120
| null | 520,383 |
249556190011831375538140140307575545482
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
uint Jsi_HashSize(Jsi_Hash *hashPtr) { return hashPtr->numEntries; }
|
CWE-120
| null | 520,384 |
316212918488021744468383046120090123503
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC dbBindOptionStmt(Jsi_Db *jdb, sqlite3_stmt *pStmt, OptionBind *obPtr,
int dataIdx, int bindMax, Jsi_CDataDb *dbopts)
{
Jsi_Interp *interp = jdb->interp;
int j, k, cnt = 0, idx, sidx = -1, rc = 0;
Jsi_StructSpec *specPtr, *specs;
void *rec;
Jsi_DString *eStr;
const char *bName;
int lastBind = sqlite3_bind_parameter_count(pStmt);
if (lastBind<=0)
return JSI_OK;
int structSize = 0;
Jsi_Wide flags = 0;
sqlite3_destructor_type statFlags = ((dbopts->noStatic)?SQLITE_TRANSIENT:SQLITE_STATIC);
specPtr = dbopts[0].sf;
structSize = specPtr[obPtr->optLen].size;
for (j=1; j<=lastBind; j++) {
bName = sqlite3_bind_parameter_name(pStmt, j);
if (bName==NULL || bName[0]==0 || bName[1]==0)
continue;
idx = j;
if (dbopts[0].prefix==0)
k = 0;
else {
for (k=0; dbopts[k].sf; k++) {
if (bName[0] == dbopts[k].prefix)
break;
}
if (bindMax>0 && k>=bindMax)
continue;
if (!dbopts[k].sf) {
Jsi_LogError("bad bind: %s", bName);
continue;
}
}
specs = dbopts[k].sf;
rec = dbopts[k].data;
if (k==0) {
if (dbopts->isMap) {
Jsi_Map *map = *(typeof(map)*)rec;
rec = Jsi_MapEntryFind(map, (void*)(intptr_t)dataIdx);
if (!rec) return JSI_ERROR;
} else if (dbopts->isPtrs)
rec = ((void**)rec)[dataIdx];
else
rec = ((uchar*)rec)+ (dataIdx * structSize);
}
if (bName[0] == '?')
sidx = atoi(bName+1);
for (specPtr = specs, cnt=1; specPtr->id>=JSI_OPTION_BOOL && specPtr->id < JSI_OPTION_END; specPtr++, cnt++) {
if (specPtr->flags&JSI_OPT_DB_IGNORE)
continue;
if (bName[0] == '?') {
if (cnt == sidx)
break;
} else {
const char *sName = specPtr->name;
if (bName[1] == sName[0] && !Jsi_Strcmp(bName+1, sName))
break;
}
}
if (specPtr->id<JSI_OPTION_BOOL || specPtr->id>=JSI_OPTION_END)
return Jsi_LogError("unknown bind: %s", bName);
char *ptr = (char *)rec + specPtr->offset;
switch (specPtr->id) {
case JSI_OPTION_BOOL:
rc = sqlite3_bind_int(pStmt, idx, *(int*)ptr);
break;
case JSI_OPTION_INT: rc = sqlite3_bind_int64(pStmt, idx, *(int*)ptr); break;
case JSI_OPTION_UINT:rc = sqlite3_bind_int64(pStmt, idx, *(uint*)ptr); break;
case JSI_OPTION_INT8: rc = sqlite3_bind_int64(pStmt, idx, *(int8_t*)ptr); break;
case JSI_OPTION_UINT8:rc = sqlite3_bind_int64(pStmt, idx, *(uint8_t*)ptr); break;
case JSI_OPTION_INT16: rc = sqlite3_bind_int64(pStmt, idx, *(int16_t*)ptr); break;
case JSI_OPTION_UINT16:rc = sqlite3_bind_int64(pStmt, idx, *(uint16_t*)ptr); break;
case JSI_OPTION_INT32: rc = sqlite3_bind_int64(pStmt, idx, *(int32_t*)ptr); break;
case JSI_OPTION_UINT32:rc = sqlite3_bind_int64(pStmt, idx, *(uint32_t*)ptr); break;
case JSI_OPTION_TIME_W:
case JSI_OPTION_INT64: rc = sqlite3_bind_int64(pStmt, idx, *(int64_t*)ptr); break;
case JSI_OPTION_UINT64:rc = sqlite3_bind_int64(pStmt, idx, *(uint64_t*)ptr); break;
case JSI_OPTION_USHORT:rc = sqlite3_bind_int64(pStmt, idx, *(ushort*)ptr); break;
case JSI_OPTION_SHORT:rc = sqlite3_bind_int64(pStmt, idx, *(short*)ptr); break;
case JSI_OPTION_LONG:rc = sqlite3_bind_int64(pStmt, idx, *(long*)ptr); break;
case JSI_OPTION_ULONG:rc = sqlite3_bind_int64(pStmt, idx, *(ulong*)ptr); break;
case JSI_OPTION_INTPTR_T:rc = sqlite3_bind_int64(pStmt, idx, *(intptr_t*)ptr); break;
case JSI_OPTION_UINTPTR_T:rc = sqlite3_bind_int64(pStmt, idx, *(uintptr_t*)ptr); break;
case JSI_OPTION_SIZE_T:rc = sqlite3_bind_int64(pStmt, idx, *(size_t*)ptr); break;
case JSI_OPTION_SSIZE_T:rc = sqlite3_bind_int64(pStmt, idx, *(ssize_t*)ptr); break;
case JSI_OPTION_LDOUBLE:rc = sqlite3_bind_int64(pStmt, idx, *(ldouble*)ptr); break;
case JSI_OPTION_FLOAT:rc = sqlite3_bind_int64(pStmt, idx, *(float*)ptr); break;
case JSI_OPTION_TIME_T:
rc = sqlite3_bind_int64(pStmt, idx, (Jsi_Wide)*(time_t*)ptr);
break;
case JSI_OPTION_NUMBER:
rc = sqlite3_bind_double(pStmt, idx, (double)*(Jsi_Number*)ptr);
break;
case JSI_OPTION_TIME_D:
case JSI_OPTION_DOUBLE:
rc = sqlite3_bind_double(pStmt, idx, (double)*(Jsi_Number*)ptr);
break;
case JSI_OPTION_CUSTOM: {
Jsi_OptionCustom* cust = Jsi_OptionCustomBuiltin(specPtr->custom);
if (cust && cust->formatProc) {
Jsi_DString dStr;
Jsi_DSInit(&dStr);
if ((*cust->formatProc)(interp, (Jsi_OptionSpec*)specPtr, NULL, &dStr, rec, flags) != JSI_OK) {
Jsi_DSFree(&dStr);
return JSI_ERROR;
}
rc = sqlite3_bind_text(pStmt, idx, Jsi_DSValue(&dStr), -1, SQLITE_TRANSIENT );
Jsi_DSFree(&dStr);
} else
return Jsi_LogError("missing or invalid custom for \"%s\"", specPtr->name);
break;
}
case JSI_OPTION_DSTRING:
eStr = (Jsi_DString*)ptr;
if (jdb->optPtr->nullvalue && !Jsi_Strcmp(jdb->optPtr->nullvalue, Jsi_DSValue(eStr)))
rc = sqlite3_bind_text(pStmt, idx, NULL, -1, statFlags );
else
rc = sqlite3_bind_text(pStmt, idx, Jsi_DSValue(eStr), -1, statFlags );
break;
case JSI_OPTION_STRBUF:
if (jdb->optPtr->nullvalue && ptr && !Jsi_Strcmp(jdb->optPtr->nullvalue, (char*)ptr))
rc = sqlite3_bind_text(pStmt, idx, NULL, -1, statFlags );
else
rc = sqlite3_bind_text(pStmt, idx, (char*)ptr, -1, statFlags );
break;
case JSI_OPTION_STRKEY:
rc = sqlite3_bind_text(pStmt, idx, *(char**)ptr, -1, SQLITE_STATIC );
break;
#ifndef JSI_LITE_ONLY
case JSI_OPTION_STRING:
rc = sqlite3_bind_text(pStmt, idx, Jsi_ValueString(interp, *((Jsi_Value **)ptr), NULL), -1, statFlags );
break;
#else
case JSI_OPTION_STRING:
#endif
case JSI_OPTION_VALUE: /* Unsupported. */
case JSI_OPTION_VAR:
case JSI_OPTION_OBJ:
case JSI_OPTION_ARRAY:
case JSI_OPTION_REGEXP:
case JSI_OPTION_FUNC:
#ifdef __cplusplus
case JSI_OPTION_END:
case JSI_OPTION_USEROBJ:
#else
default:
#endif
Jsi_LogError("unsupported jdb option type \"%s\" for \"%s\"", jsi_DbOptionTypeStr(specPtr->id, 0), specPtr->name);
return JSI_ERROR;
}
if (rc != SQLITE_OK)
Jsi_LogError("bind failure: %s", sqlite3_errmsg(jdb->db));
}
cnt++;
return JSI_OK;
}
|
CWE-120
| null | 520,385 |
184657550112595919482281991001570133887
| null | null |
other
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.