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 |
Jsi_Value* Jsi_ValueMakeDStringObject(Jsi_Interp *interp, Jsi_Value **vPtr, Jsi_DString *dsPtr) {
Jsi_Value *v = (vPtr?*vPtr:NULL);
Jsi_Obj *obj;
if (!v)
v = Jsi_ValueNew(interp);
else {
assert(v->vt <= JSI_VT__MAX);
if (v->vt == JSI_VT_OBJECT && v->d.obj->ot == JSI_OT_STRING
&& v->d.obj->refcnt == 1
) {
Jsi_ObjFromDS(dsPtr, v->d.obj);
return v;
}
Jsi_ValueReset(interp, &v);
}
obj = Jsi_ObjNewType(interp, JSI_OT_STRING);
Jsi_ObjFromDS(dsPtr, obj);
Jsi_ValueMakeObject(interp, &v, obj);
return v;
}
|
CWE-120
| null | 519,886 |
9427248896220350865990441314267135822
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_OpCodes *code_instanceof() { JSI_NEW_CODES(0,OP_INSTANCEOF, 0); }
|
CWE-120
| null | 519,887 |
281093062586642700824001777776941496496
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_OpCodes *code_push_regex(jsi_Pstate *p, jsi_Pline *line, Jsi_Regex *reg) { JSI_NEW_CODESLN(0,OP_PUSHREG, reg); }
|
CWE-120
| null | 519,888 |
185058131665725459271615645650812060756
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_OpCodes *code_push_undef() { JSI_NEW_CODES(0,OP_PUSHUND, 0); }
|
CWE-120
| null | 519,889 |
210102700284483463688023407068067828648
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_Func *jsi_FuncMake(jsi_Pstate *pstate, Jsi_ScopeStrs *args, Jsi_OpCodes *ops, jsi_Pline* line, const char *name, int isArrow)
{
Jsi_Interp *interp = pstate->interp;
Jsi_ScopeStrs *localvar = jsi_ScopeGetVarlist(pstate);
Jsi_Func *f = jsi_FuncNew(interp);
jsi_Lexer *l = pstate->lexer;
if (isArrow)
f->isArrow = isArrow;
f->type = FC_NORMAL;
f->opcodes = ops;
f->argnames = args;
f->localnames = localvar;
f->script = interp->curFile;
f->bodyline = *line;
f->retType = (Jsi_otype)args->retType;
if (!pstate->eval_flag) {
f->scriptFile = f->script;
}
if (l->ltype == LT_STRING)
f->bodyStr = l->d.str;
f->endPos = l->cur;
f->startPos = -1; // Have to get these from newline count.
if (f->retType & JSI_TT_UNDEFINED)
Jsi_LogWarn("illegal use of 'undefined' in a return type: %s", name?name:"");
//f->strict = (jsi_GetDirective(interp, ops, "use strict") != NULL);
pstate->argType = 0;
if (localvar && args && (interp->strict)) {
int i, j;
for (i=0; i<args->count; i++) {
for (j=0; j<args->count; j++) {
if (i != j && !Jsi_Strcmp(args->args[i].name, args->args[j].name)) {
if (line)
interp->parseLine = line;
Jsi_LogWarn("function %s(): duplicate parameter name '%s'", name?name:"", args->args[i].name);
if (line)
interp->parseLine = NULL;
jsi_TypeMismatch(interp);
if (interp->typeCheck.error)
pstate->err_count++;
}
}
for (j=0; j<localvar->count; j++) {
if (!Jsi_Strcmp(localvar->args[j].name, args->args[i].name)) {
if (line)
interp->parseLine = line;
Jsi_LogWarn("function %s(): parameter name conflicts with 'var %s'", name?name:"", localvar->args[j].name);
if (line)
interp->parseLine = NULL;
jsi_TypeMismatch(interp);
if (interp->typeCheck.error)
pstate->err_count++;
}
}
}
}
if (name) {
f->name = Jsi_KeyAdd(interp, name);
if ((interp->typeCheck.run|interp->typeCheck.parse|interp->typeCheck.all|interp->typeCheck.funcsig)) {
if (f->retType && !(f->retType&JSI_TT_VOID) && ops && ops->code_len && ops->codes[ops->code_len-1].op != OP_RET) {
if (line)
interp->parseLine = line;
Jsi_LogWarn("missing return at end of function '%s'", name);
if (line)
interp->parseLine = NULL;
//if (interp->typeCheck.error)
// pstate->err_count++;
}
if (interp->staticFuncsTbl) {
Jsi_Func *fo = (Jsi_Func*)Jsi_HashGet(interp->staticFuncsTbl, (void*)name, 0);
// Forward declaration signature compare (indicated by an empty body).
if (interp->typeCheck.funcsig && fo && fo->opcodes && fo->opcodes->code_len == 1 && fo->opcodes->codes->op == OP_NOP) {
if (!jsi_FuncSigsMatch(pstate, f, fo)) {
if (line)
interp->parseLine = line;
Jsi_LogWarn("possible signature mismatch for function '%s' at %.120s:%d", name, fo->script, fo->bodyline.first_line);
if (line)
interp->parseLine = NULL;
jsi_TypeMismatch(interp);
}
//printf("OLD: %s\n", name);
}
Jsi_HashSet(interp->staticFuncsTbl, name, f);
}
}
}
return f;
}
|
CWE-120
| null | 519,890 |
249623079489065740396954226065962832868
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_RC Jsi_InitMySql(Jsi_Interp *interp, int release)
{
if (release) {
if (!--mydbObjCmd.init)
mysql_library_end();
return Jsi_DoneMySql(interp);
}
Jsi_Hash* dbSys;
#if JSI_USE_STUBS
if (Jsi_StubsInit(interp, 0) != JSI_OK)
return JSI_ERROR;
#endif
#ifndef JSI_OMIT_THREADS
if (mydbObjCmd.init == 0 && mysql_library_init(0, NULL, NULL))
return Jsi_LogError("failed to initialize MySQL library\n");
#else
return Jsi_LogError("Threads required for mysql");
#endif
Jsi_Value *info = Jsi_ValueNew1(interp);
Jsi_JSONParseFmt(interp, &info, "{pkgVer:%d}", MYSQL_VERSION_ID);
Jsi_PkgOpts dbPkgOpts = { mydb_ObjCmd_Specs, &mydbObjCmd, mysqlCmds, info};
Jsi_RC rc = Jsi_PkgProvideEx(interp, "MySql", 1.1, Jsi_InitMySql, &dbPkgOpts);
Jsi_DecrRefCount(interp, info);
if (rc != JSI_OK)
rc = JSI_ERROR;
else if (!(dbSys = Jsi_UserObjRegister(interp, &mysqlobject)))
rc = Jsi_LogError("Failed to init mysql extension");
else if (!Jsi_CommandCreateSpecs(interp, mysqlobject.name, mysqlCmds, dbSys, JSI_CMDSPEC_ISOBJ))
rc = JSI_ERROR;
if (rc == JSI_OK)
mydbObjCmd.init++;
else
mysql_library_end();
return rc;
}
|
CWE-120
| null | 519,891 |
194451703270648391427564618489738038538
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC StringCharAtCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
int pos = 0, len, bLen;
const char *vstr;
ChkString(_this, funcPtr, vstr, &len, &bLen);
Jsi_Value *vpos = Jsi_ValueArrayIndex(interp, args, 0);
if (Jsi_GetIntFromValue(interp, vpos, &pos)) {
return JSI_ERROR;
}
if (pos<0 || pos >=len)
Jsi_ValueMakeStringDup(interp, ret, "");
else {
Jsi_DString dStr;
Jsi_DSInit(&dStr);
Jsi_UtfSubstr(vstr, pos, 1, &dStr);
Jsi_ValueFromDS(interp, &dStr, ret);
}
return JSI_OK;
}
|
CWE-120
| null | 519,892 |
81574336617421971061503084645446523735
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
const char *jsi_GetCurFile(Jsi_Interp *interp)
{
const char *curFile = NULL;
if (!interp)
return NULL;
if (interp->inParse)
curFile = interp->curFile;
else
curFile = (interp->curIp && interp->curIp->fname? interp->curIp->fname:interp->curFile);
if (!curFile) curFile = interp->framePtr->fileName;
if (!curFile) curFile = "";
return curFile;
}
|
CWE-120
| null | 519,893 |
286673449277535871621788570158054951475
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC NumberToExponentialCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
char buf[JSI_MAX_NUMBER_STRING+1];
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 = 0;
Jsi_GetDoubleFromValue(interp, v, &num);
snprintf(buf, sizeof(buf), "%.*" JSI_NUMEFMT, prec, num);
#ifdef __WIN32
char *e = strrchr(buf, 'e');
if (e && (e[1]=='+' || e[1]=='-')) {
e++;
int eNum = atoi(e);
if (e[0]=='-')
eNum = -eNum;
e++;
snprintf(e, (e-buf), "%02d", eNum);
}
#endif
Jsi_ValueMakeStringDup(interp, ret, buf);
return JSI_OK;
}
|
CWE-120
| null | 519,894 |
110022956548831062771250912496387046877
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC SqliteQueryCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
Jsi_RC rc = JSI_OK;
Jsi_Db *jdb;
if (!(jdb = dbGetDbHandle(interp, _this, funcPtr))) return JSI_ERROR;
Jsi_Value *vSql = Jsi_ValueArrayIndex(interp, args, 0);
Jsi_DString eStr = {};
#ifdef JSI_DB_DSTRING_SIZE
JSI_DSTRING_VAR(dStr, JSI_DB_DSTRING_SIZE);
#else
Jsi_DString ddStr, *dStr = &ddStr;
Jsi_DSInit(dStr);
#endif
const char *zSql = Jsi_ValueGetDString(interp, vSql, &eStr, 0);
Jsi_Value *arg = Jsi_ValueArrayIndex(interp, args, 1);
int cnt = 0;
char **apColName = NULL;
int *apColType = NULL, isopts = 0;
DbEvalContext sEval = {};
QueryOpts opts, *oEopt = jdb->optPtr;
opts = jdb->queryOpts;
opts.callback = NULL;
opts.width = NULL;
Jsi_Value *callback = NULL, *width = NULL;
if (arg) {
if (Jsi_ValueIsFunction(interp,arg))
callback = opts.callback = arg;
else if (Jsi_ValueIsString(interp, arg))
opts.objName = Jsi_ValueString(interp, arg, NULL);
else if (Jsi_ValueIsObjType(interp, arg, JSI_OT_ARRAY))
opts.values = arg;
else if (Jsi_ValueIsObjType(interp, arg, JSI_OT_OBJECT))
isopts = 1;
else {
rc = Jsi_LogError("arg 2: expected function, string, array or options");
goto bail;
}
}
if (isopts) {
if (Jsi_OptionsProcess(interp, ExecFmtOptions, &opts, arg, 0) < 0) {
rc = JSI_ERROR;
goto bail;
}
callback = (opts.callback ? opts.callback : jdb->queryOpts.callback);
width = (opts.width ? opts.width : jdb->queryOpts.width);
}
if (opts.retChanged) {
if (opts.callback) {
rc = Jsi_LogError("can not use retChanged with callback");
goto bail;
}
opts.mode = _JSI_EF_NONE;
opts.headers = 0;
}
if (opts.cdata) {
Jsi_CDataDb* copts = Jsi_CDataLookup(interp, opts.cdata);
if (!copts)
rc = Jsi_LogError("unknown cdata name: %s", opts.cdata);
else {
int n = Jsi_DbQuery(jdb, copts, zSql);
Jsi_ValueMakeNumber(interp, ret, (Jsi_Number)n);
}
goto bail;
}
if (opts.objName) {
if (Jsi_SqlObjBinds(interp, &eStr, opts.objName, !(opts.objOpts&OBJMODE_NOTYPES),
!(opts.objOpts&OBJMODE_NODEFAULTS), (opts.objOpts&OBJMODE_NULLDEFAULTS)!=0) != JSI_OK)
goto bail;
zSql = Jsi_DSValue(&eStr);
}
if ((jdb->echo || opts.echo) && zSql)
Jsi_LogInfo("SQL-ECHO: %s\n", zSql);
if ((opts.objOpts&OBJMODE_SQLONLY)) {
if (opts.objName)
Jsi_ValueMakeStringDup(interp, ret, zSql);
else
rc = Jsi_LogError("'objOpts.sqlOnly' can only be used with 'objName'");
goto bail;
}
if (!opts.separator) {
switch (opts.mode) {
case _JSI_EF_LIST: opts.separator = "|"; break;
case _JSI_EF_COLUMN: opts.separator = " "; break;
case _JSI_EF_TABS: opts.separator = "\t"; break;
default: opts.separator = ",";
}
}
Jsi_DString sStr;
Jsi_DSInit(&sStr);
sEval.nocache = opts.nocache;
if ((rc = dbEvalInit(interp, &sEval, jdb, zSql, &sStr, 0, 0)) != JSI_OK)
goto bail;
sEval.ret = *ret;
jdb->optPtr = &opts;
if (callback) {
sEval.tocall = callback;
if (opts.mode != _JSI_EF_ROWS) {
Jsi_LogError("'mode' must be 'rows' with 'callback'");
rc = JSI_ERROR;
goto bail;
}
rc = dbEvalCallCmd(&sEval, interp, JSI_OK);
goto bail;
} else
switch (opts.mode) {
case _JSI_EF_NONE:
while(JSI_OK==(rc = dbEvalStep(&sEval)) ) {
cnt++;
if (opts.limit && cnt>=opts.limit) break;
}
if (opts.retChanged)
Jsi_ValueMakeNumber(interp, ret, (Jsi_Number)sqlite3_changes(jdb->db));
if (rc == JSI_BREAK)
rc = JSI_OK;
goto bail;
break;
case _JSI_EF_JSON:
if (opts.headers) {
Jsi_DSAppend(dStr, "[ ", NULL);
while( JSI_OK==(rc = dbEvalStep(&sEval)) ) {
int i;
int nCol;
dbEvalRowInfo(&sEval, &nCol, &apColName, &apColType);
if (cnt == 0) {
Jsi_DSAppend(dStr, "[", NULL);
for(i=0; i<nCol; i++) {
if (i)
Jsi_DSAppend(dStr, ", ", NULL);
Jsi_JSONQuote(interp, apColName[i], -1, dStr);
}
Jsi_DSAppend(dStr, "]", NULL);
cnt++;
}
if (cnt)
Jsi_DSAppend(dStr, ", ", NULL);
Jsi_DSAppend(dStr, "[", NULL);
for(i=0; i<nCol; i++) {
if (i)
Jsi_DSAppend(dStr, ", ", NULL);
dbEvalSetColumnJSON(&sEval, i, dStr);
}
Jsi_DSAppend(dStr, "]", NULL);
cnt++;
if (opts.limit && cnt>opts.limit) break;
}
Jsi_DSAppend(dStr, " ]", NULL);
} else {
Jsi_DSAppend(dStr, "[ ", NULL);
while( JSI_OK==(rc = dbEvalStep(&sEval)) ) {
int i;
int nCol;
dbEvalRowInfo(&sEval, &nCol, &apColName, &apColType);
if (cnt)
Jsi_DSAppend(dStr, ", ", NULL);
Jsi_DSAppend(dStr, "{", NULL);
for(i=0; i<nCol; i++) {
if (i)
Jsi_DSAppend(dStr, ", ", NULL);
Jsi_JSONQuote(interp, apColName[i], -1, dStr);
Jsi_DSAppend(dStr, ":", NULL);
dbEvalSetColumnJSON(&sEval, i, dStr);
}
Jsi_DSAppend(dStr, "}", NULL);
cnt++;
if (opts.limit && cnt>=opts.limit) break;
}
Jsi_DSAppend(dStr, " ]", NULL);
}
break;
case _JSI_EF_JSON2: {
while( JSI_OK==(rc = dbEvalStep(&sEval)) ) {
int i;
int nCol;
dbEvalRowInfo(&sEval, &nCol, &apColName, &apColType);
if (cnt == 0 && 1) {
Jsi_DSAppend(dStr, "{ \"names\": [ ", NULL);
for(i=0; i<nCol; i++) {
if (i)
Jsi_DSAppend(dStr, ", ", NULL);
Jsi_JSONQuote(interp, apColName[i], -1, dStr);
}
Jsi_DSAppend(dStr, " ], \"values\": [ ", NULL);
}
if (cnt)
Jsi_DSAppend(dStr, ", ", NULL);
Jsi_DSAppend(dStr, "[", NULL);
for(i=0; i<nCol; i++) {
if (i)
Jsi_DSAppend(dStr, ", ", NULL);
dbEvalSetColumnJSON(&sEval, i, dStr);
}
Jsi_DSAppend(dStr, " ]", NULL);
cnt++;
if (opts.limit && cnt>=opts.limit) break;
}
if (cnt)
Jsi_DSAppend(dStr, " ] } ", NULL);
}
break;
case _JSI_EF_LIST:
while( JSI_OK==(rc = dbEvalStep(&sEval)) ) {
int i;
int nCol;
dbEvalRowInfo(&sEval, &nCol, &apColName, &apColType);
if (cnt == 0 && opts.headers) {
for(i=0; i<nCol; i++) {
if (i)
Jsi_DSAppend(dStr, opts.separator, NULL);
Jsi_DSAppend(dStr, apColName[i], NULL);
}
}
if (cnt || opts.headers)
Jsi_DSAppend(dStr, "\n", NULL);
for(i=0; i<nCol; i++) {
if (i)
Jsi_DSAppend(dStr, opts.separator, NULL);
dbEvalSetColumn(&sEval, i, dStr);
}
cnt++;
if (opts.limit && cnt>=opts.limit) break;
}
break;
case _JSI_EF_COLUMN: {
int *wids = NULL;
Jsi_DString vStr = {};
while( JSI_OK==(rc = dbEvalStep(&sEval)) ) {
int i, w;
int nCol;
dbEvalRowInfo(&sEval, &nCol, &apColName, &apColType);
if (cnt == 0 && nCol>0) {
Jsi_DString sStr;
wids = (int*)Jsi_Calloc(nCol, sizeof(int));
Jsi_DSInit(&sStr);
for(i=0; i<nCol; i++) {
int j = Jsi_Strlen(apColName[i]);
wids[i] = (j<10?10:j);
if (width) {
Jsi_Value *wv = Jsi_ValueArrayIndex(interp, width, i);
if (wv) {
Jsi_Number dv;
Jsi_ValueGetNumber(interp, wv, &dv);
if (dv>0)
wids[i] = (int)dv;
}
}
w = (j<wids[i] ? j : wids[i]);
Jsi_DSAppendLen(dStr, apColName[i], w);
w = (j<wids[i] ? wids[i]-j+1 : 0);
while (w-- > 0)
Jsi_DSAppend(dStr, " ", NULL);
}
for(i=0; i<nCol && opts.headers; i++) {
w = wids[i];
w -= Jsi_Strlen(apColName[i]);
if (i) {
Jsi_DSAppend(dStr, opts.separator, NULL);
Jsi_DSAppend(&sStr, opts.separator, NULL);
}
w = wids[i];
while (w-- > 0)
Jsi_DSAppend(&sStr, "-", NULL);
}
if (opts.headers)
Jsi_DSAppend(dStr, "\n", Jsi_DSValue(&sStr), "\n", NULL);
Jsi_DSFree(&sStr);
}
if (cnt)
Jsi_DSAppend(dStr, "\n", NULL);
for(i=0; i<nCol; i++) {
if (i)
Jsi_DSAppend(dStr, opts.separator, NULL);
Jsi_DSSetLength(&vStr, 0);
dbEvalSetColumn(&sEval, i, &vStr);
int nl = Jsi_DSLength(&vStr);
if (nl > wids[i]) {
Jsi_DSSetLength(&vStr, wids[i]);
w = 0;
} else {
w = wids[i]-nl;
}
Jsi_DSAppend(dStr, Jsi_DSValue(&vStr), NULL);
while (w-- > 0)
Jsi_DSAppend(dStr, " ", NULL);
}
cnt++;
if (opts.limit && cnt>=opts.limit) break;
}
Jsi_DSFree(&vStr);
if (wids)
Jsi_Free(wids);
break;
}
case _JSI_EF_INSERT: {
Jsi_DString vStr = {};
while( JSI_OK==(rc = dbEvalStep(&sEval)) ) {
int i;
int nCol;
const char *tbl = (opts.table ? opts.table : "table");
Jsi_DSAppend(dStr, "INSERT INTO \"", tbl, "\" VALUES(", NULL);
dbEvalRowInfo(&sEval, &nCol, &apColName, &apColType);
for(i=0; i<nCol; i++) {
Jsi_Number dv;
const char *azArg;
Jsi_DSSetLength(&vStr, 0);
dbEvalSetColumn(&sEval, i, &vStr);
sqlite3_stmt *pStmt = sEval.pPreStmt->pStmt;
int ptype = sqlite3_column_type(pStmt, i);
azArg = Jsi_DSValue(&vStr);
const char *zSep = i>0 ? ",": "";
if(apColType && apColType[i]==SQLITE_NULL) {
Jsi_DSAppend(dStr, zSep, "NULL", NULL);
}else if( ptype ==SQLITE_TEXT ) {
if( zSep[0] ) Jsi_DSAppend(dStr,zSep, NULL);
dbOutputQuotedString(dStr, azArg);
}else if (ptype==SQLITE_INTEGER || ptype ==SQLITE_FLOAT) {
Jsi_DSAppend(dStr, zSep, azArg, NULL);
}else if (ptype ==SQLITE_BLOB) {
const void *pBlob = sqlite3_column_blob(pStmt, i );
int nBlob = sqlite3_column_bytes(pStmt, i);
if( zSep[0] ) Jsi_DSAppend(dStr,zSep, NULL);
dbOutputHexBlob(dStr, pBlob, nBlob);
}else if( Jsi_GetDouble(interp, azArg, &dv) == JSI_OK ){
Jsi_DSAppend(dStr, zSep, azArg, NULL);
}else{
if( zSep[0] ) Jsi_DSAppend(dStr,zSep, NULL);
dbOutputQuotedString(dStr, azArg);
}
}
Jsi_DSAppend(dStr, ");\n", NULL);
cnt++;
if (opts.limit && cnt>=opts.limit) break;
}
Jsi_DSFree(&vStr);
}
case _JSI_EF_TABS:
case _JSI_EF_CSV: {
Jsi_DString vStr = {};
while( JSI_OK==(rc = dbEvalStep(&sEval)) ) {
int i;
int nCol;
dbEvalRowInfo(&sEval, &nCol, &apColName, &apColType);
if (cnt == 0 && opts.headers) {
for(i=0; i<nCol; i++) {
if (i)
Jsi_DSAppend(dStr, opts.separator, NULL);
Jsi_DSAppend(dStr, apColName[i], NULL);
}
}
if (cnt || opts.headers)
Jsi_DSAppend(dStr, "\n", NULL);
for(i=0; i<nCol; i++) {
if (i)
Jsi_DSAppend(dStr, opts.separator, NULL);
Jsi_DSSetLength(&vStr, 0);
dbEvalSetColumn(&sEval, i, &vStr);
if (opts.mode == _JSI_EF_CSV)
dbOutputCsv(&opts, Jsi_DSValue(&vStr), dStr, 0);
else
Jsi_DSAppend(dStr, Jsi_DSValue(&vStr), NULL);
}
cnt++;
if (opts.limit && cnt>=opts.limit) break;
}
Jsi_DSFree(&vStr);
break;
}
case _JSI_EF_LINE: {
int i, w = 5, ww;
int nCol;
Jsi_DString vStr = {};
while( JSI_OK==(rc = dbEvalStep(&sEval)) ) {
dbEvalRowInfo(&sEval, &nCol, &apColName, &apColType);
if (cnt == 0) {
for(i=0; i<nCol; i++) {
ww = Jsi_Strlen(apColName[i]);
if (ww>w)
w = ww;
}
}
for(i=0; i<nCol; i++) {
Jsi_DString eStr;
Jsi_DSInit(&eStr);
Jsi_DSSetLength(&vStr, 0);
dbEvalSetColumn(&sEval, i, &vStr);
Jsi_DSPrintf(&eStr, "%*s = %s", w, apColName[i], Jsi_DSValue(&vStr));
Jsi_DSAppend(dStr, (cnt?"\n":""), Jsi_DSValue(&eStr), NULL);
Jsi_DSFree(&eStr);
}
cnt++;
if (opts.limit && cnt>=opts.limit) break;
}
Jsi_DSFree(&vStr);
break;
}
case _JSI_EF_HTML: {
Jsi_DString vStr = {};
while( JSI_OK==(rc = dbEvalStep(&sEval)) ) {
int i;
int nCol;
dbEvalRowInfo(&sEval, &nCol, &apColName, &apColType);
if (cnt == 0 && opts.headers) {
Jsi_DSAppend(dStr, "<TR>", NULL);
for(i=0; i<nCol; i++) {
Jsi_DSAppend(dStr, "<TH>", NULL);
dbOutputHtmlString(&opts, apColName[i], dStr);
Jsi_DSAppend(dStr, "</TH>", NULL);
}
Jsi_DSAppend(dStr, "</TR>", NULL);
}
if (cnt || opts.headers)
Jsi_DSAppend(dStr, "\n", NULL);
Jsi_DSAppend(dStr, "<TR>", NULL);
for(i=0; i<nCol; i++) {
Jsi_DSAppend(dStr, "<TD>", NULL);
Jsi_DSSetLength(&vStr, 0);
dbEvalSetColumn(&sEval, i, &vStr);
dbOutputHtmlString(&opts, Jsi_DSValue(&vStr), dStr);
Jsi_DSAppend(dStr, "</TD>", NULL);
}
Jsi_DSAppend(dStr, "</TR>", NULL);
cnt++;
if (opts.limit && cnt>=opts.limit) break;
}
Jsi_DSFree(&vStr);
break;
}
case _JSI_EF_ROWS:
{
Jsi_Value *vcur, *vrow;
int cnt = 0;
Jsi_Obj *oall, *ocur;
Jsi_ValueMakeArrayObject(interp, ret, oall = Jsi_ObjNewType(interp, JSI_OT_ARRAY));
while( JSI_OK==(rc = dbEvalStep(&sEval)) ) {
int i;
int nCol;
dbEvalRowInfo(&sEval, &nCol, &apColName, &apColType);
ocur = Jsi_ObjNewType(interp, JSI_OT_OBJECT);
vrow = Jsi_ValueMakeObject(interp, NULL, ocur);
for(i=0; i<nCol; i++) {
vcur = dbEvalSetColumnValue(&sEval, i, NULL);
Jsi_ObjInsert(interp, ocur, apColName[i], vcur, 0);
}
Jsi_ObjArrayAdd(interp, oall, vrow);
cnt++;
if (opts.limit && cnt>=opts.limit) break;
}
dbEvalFinalize(&sEval);
if (rc != JSI_ERROR)
rc = JSI_OK;
goto bail;
break;
}
case _JSI_EF_ARRAYS:
{
Jsi_Value *vcur, *vrow;
int cnt = 0;
Jsi_Obj *oall, *ocur;
Jsi_ValueMakeArrayObject(interp, ret, oall = Jsi_ObjNewType(interp, JSI_OT_ARRAY));
while( JSI_OK==(rc = dbEvalStep(&sEval)) ) {
int i;
int nCol;
dbEvalRowInfo(&sEval, &nCol, &apColName, &apColType);
if (cnt == 0 && opts.headers) {
vrow = Jsi_ValueMakeArrayObject(interp, NULL, ocur = Jsi_ObjNewType(interp, JSI_OT_ARRAY));
for(i=0; i<nCol; i++) {
vcur = Jsi_ValueNewStringDup(interp, apColName[i]);
Jsi_ObjArrayAdd(interp, ocur, vcur);
}
Jsi_ObjArrayAdd(interp, oall, vrow);
}
vrow = Jsi_ValueMakeArrayObject(interp, NULL, ocur = Jsi_ObjNewType(interp, JSI_OT_ARRAY));
for(i=0; i<nCol; i++) {
vcur = dbEvalSetColumnValue(&sEval, i, NULL);
Jsi_ObjArrayAdd(interp, ocur, vcur);
}
Jsi_ObjArrayAdd(interp, oall, vrow);
cnt++;
if (opts.limit && cnt>=opts.limit) break;
}
dbEvalFinalize(&sEval);
if (rc != JSI_ERROR)
rc = JSI_OK;
goto bail;
break;
}
case _JSI_EF_ARRAY1D:
{
Jsi_Value *vcur;
int cnt = 0;
Jsi_Obj *oall;
Jsi_ValueMakeArrayObject(interp, ret, oall = Jsi_ObjNewType(interp, JSI_OT_ARRAY));
while( JSI_OK==(rc = dbEvalStep(&sEval)) ) {
int i;
int nCol;
dbEvalRowInfo(&sEval, &nCol, &apColName, &apColType);
if (cnt == 0 && opts.headers) {
for(i=0; i<nCol; i++) {
vcur = Jsi_ValueNewStringDup(interp, apColName[i]);
Jsi_ObjArrayAdd(interp, oall, vcur);
}
}
for(i=0; i<nCol; i++) {
vcur = dbEvalSetColumnValue(&sEval, i, NULL);
Jsi_ObjArrayAdd(interp, oall, vcur);
}
cnt++;
if (opts.limit && cnt>=opts.limit) break;
}
dbEvalFinalize(&sEval);
if (rc != JSI_ERROR)
rc = JSI_OK;
goto bail;
break;
}
}
if (opts.retChanged)
Jsi_ValueMakeNumber(interp, ret, (Jsi_Number)sqlite3_changes(jdb->db));
else
Jsi_ValueFromDS(interp, dStr, ret);
if( rc==JSI_BREAK )
rc = JSI_OK;
bail:
dbEvalFinalize(&sEval);
if (isopts) {
Jsi_OptionsFree(interp, ExecFmtOptions, &opts, 0);
}
Jsi_DSFree(dStr);
Jsi_DSFree(&eStr);
jdb->optPtr = oEopt;
return rc;
}
|
CWE-120
| null | 519,895 |
193315919961460862896811147419755349925
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC WebSocketIdCmdOp(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr, int op)
{
Jsi_RC rc = JSI_OK;
jsi_wsCmdObj *cmdPtr = (jsi_wsCmdObj*)Jsi_UserObjGetData(interp, _this, funcPtr);
if (!cmdPtr)
return Jsi_LogError("Apply in a non-websock object");
Jsi_Value *v, *valPtr = Jsi_ValueArrayIndex(interp, args, 0);
Jsi_Number vid;
if (Jsi_ValueGetNumber(interp, valPtr, &vid) != JSI_OK || vid < 0)
return Jsi_LogError("Expected connection number id");
int id = (int)vid;
jsi_wsPss *pss = NULL;
Jsi_HashEntry *hPtr;
Jsi_HashSearch cursor;
for (hPtr = Jsi_HashSearchFirst(cmdPtr->pssTable, &cursor);
hPtr != NULL; hPtr = Jsi_HashSearchNext(&cursor)) {
jsi_wsPss* tpss = (jsi_wsPss*)Jsi_HashValueGet(hPtr);
WSSIGASSERT(tpss, PWS);
if (tpss->wid == id && tpss->state != PWS_DEAD) {
pss = tpss;
break;
}
}
if (!pss)
return Jsi_LogError("No such id: %d", id);
switch (op) {
case 0:
v = Jsi_ValueArrayIndex(interp, args, 1);
rc = Jsi_OptionsConf(interp, WPSOptions, pss, v, ret, 0);
break;
case 1:
jsi_wsDumpHeaders(cmdPtr, pss, Jsi_ValueArrayIndexToStr(interp, args, 1, NULL), ret);
break;
case 2:
if (!pss->spa) return JSI_OK;
jsi_wsDumpQuery(cmdPtr, pss, Jsi_ValueArrayIndexToStr(interp, args, 1, NULL), ret);
break;
}
return rc;
}
|
CWE-120
| null | 519,896 |
69834304729057399376283916525054984434
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_RC Jsi_DeleteData(Jsi_Interp* interp, void *m)
{
Jsi_Free(m);
return JSI_OK;
}
|
CWE-120
| null | 519,897 |
254681210158799955941362771658398292863
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_Value* Jsi_ValueNewStringConst(Jsi_Interp *interp, const char *s, int len) {
Jsi_Value *v = Jsi_ValueNew(interp);
v->vt = JSI_VT_STRING;
v->d.s.str = (char*)s;
v->d.s.len = (len<0?Jsi_Strlen(s):(uint)len);
v->f.bits.isstrkey = 1;
return v;
}
|
CWE-120
| null | 519,898 |
286172125276671242221913609318946245111
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC InterpAliasCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
InterpObj *udf = (InterpObj *)Jsi_UserObjGetData(interp, _this, funcPtr);
Jsi_Interp *sinterp = (udf ? udf->subinterp : interp );
Jsi_Hash *aliases = sinterp->aliasHash;
if (!aliases)
return Jsi_LogError("Sub-interp gone");
int argc = Jsi_ValueGetLength(interp, args);
if (argc == 0)
return Jsi_HashKeysDump(interp, aliases, ret, 0);
Jsi_HashEntry *hPtr;
char *key = Jsi_ValueArrayIndexToStr(interp, args, 0, NULL);
if (!key)
return Jsi_LogError("expected string");
AliasCmd* ac;
if (argc == 1) {
hPtr = Jsi_HashEntryFind(aliases, (void*)key);
if (!hPtr)
return JSI_OK;
ac = (AliasCmd*)Jsi_HashValueGet(hPtr);
if (!ac) return JSI_ERROR;
SIGASSERT(ac,ALIASCMD);
Jsi_ValueDup2(interp, ret, ac->func);
return JSI_OK;
}
Jsi_Value *afunc = Jsi_ValueArrayIndex(interp, args, 1);
if (argc == 2) {
hPtr = Jsi_HashEntryFind(aliases, (void*)key);
if (!hPtr)
return JSI_OK;
ac = (AliasCmd*)Jsi_HashValueGet(hPtr);
if (!Jsi_ValueIsNull(interp, afunc))
return Jsi_LogError("arg 2: expected null to query args");
if (!ac) return JSI_ERROR;
SIGASSERT(ac,ALIASCMD);
Jsi_ValueDup2(interp, ret, ac->args); //TODO: JSON??
return JSI_OK;
}
if (argc < 3)
return JSI_ERROR;
bool isthrd = (interp->threadId != sinterp->threadId);
//if (isthrd)
//return Jsi_LogError("alias not supported with threads");
bool isNew;
Jsi_Value *aargs = Jsi_ValueArrayIndex(interp, args, 2);
if (Jsi_ValueIsNull(interp, afunc) && Jsi_ValueIsNull(interp, aargs)) {
hPtr = Jsi_HashEntryFind(aliases, (void*)key);
if (hPtr == NULL)
return JSI_OK;
ac = (AliasCmd*)Jsi_HashValueGet(hPtr);
if (!ac) return JSI_ERROR;
if (0 && ac->cmdVal)
Jsi_DecrRefCount(interp, ac->cmdVal);
jsi_AliasFree(interp, NULL, ac);
Jsi_HashValueSet(hPtr, NULL);
Jsi_HashEntryDelete(hPtr);
return JSI_OK;
}
hPtr = Jsi_HashEntryNew(aliases, (void*)key, &isNew);
if (!hPtr)
return Jsi_LogError("create failed: %s", key);
if (!Jsi_ValueIsFunction(interp, afunc))
return Jsi_LogError("arg 2: expected function");
if (Jsi_ValueIsNull(interp, aargs) == 0 && Jsi_ValueIsArray(interp, aargs) == 0)
return Jsi_LogError("arg 3: expected array or null");
if (!isNew) {
jsi_AliasFree(interp, NULL, Jsi_HashValueGet(hPtr));
}
ac = (AliasCmd*)Jsi_Calloc(1, sizeof(AliasCmd));
SIGINIT(ac, ALIASCMD);
ac->cmdName = (const char*)Jsi_HashKeyGet(hPtr);
ac->func = afunc;
Jsi_IncrRefCount(interp, afunc);
if (!Jsi_ValueIsNull(interp, aargs)) {
ac->args = aargs;
Jsi_IncrRefCount(interp, aargs);
}
ac->intobj = udf;
ac->dinterp = interp;
ac->subinterp = sinterp;
Jsi_HashValueSet(hPtr, ac);
if (!isthrd)
return jsi_AliasCreateCmd(sinterp, key, ac);
Jsi_Value *vasync = Jsi_ValueArrayIndex(interp, args, 3);
bool async = 0;
if (vasync && Jsi_GetBoolFromValue(interp, vasync, &async))
return JSI_ERROR;
if (!async) {
if (Jsi_MutexLock(interp, sinterp->Mutex) != JSI_OK)
return JSI_ERROR;
Jsi_RC rc = jsi_AliasCreateCmd(sinterp, key, ac);
Jsi_MutexUnlock(interp, sinterp->Mutex);
return rc;
}
/* Post to thread event in sub-interps queue. */
if (Jsi_MutexLock(interp, sinterp->QMutex) != JSI_OK)
return JSI_ERROR;
/* Is an async call. */
InterpStrEvent *se, *s = (InterpStrEvent *)Jsi_Calloc(1, sizeof(*s));
// TODO: is s->data inited?
s->acdata = ac;
Jsi_DSInit(&s->func);
Jsi_DSAppend(&s->func, ac->cmdName, NULL);
se = sinterp->interpStrEvents;
if (!se)
sinterp->interpStrEvents = s;
else {
while (se->next)
se = se->next;
se->next = s;
}
Jsi_MutexUnlock(interp, sinterp->QMutex);
return JSI_OK;
}
|
CWE-120
| null | 519,899 |
107622048421683485314354492695828505452
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_Value* Jsi_ValueNewStringDup(Jsi_Interp *interp, const char *s) {
return Jsi_ValueNewString(interp, Jsi_Strdup(s), -1);
}
|
CWE-120
| null | 519,900 |
35241157993937178478466046237771350041
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
const char *jsi_ObjectTypeName(Jsi_Interp *interp, Jsi_otype otyp)
{
switch (otyp) {
case JSI_OT_NUMBER: return "number";
case JSI_OT_STRING: return "string";
case JSI_OT_BOOL: return "boolean";
case JSI_OT_ARRAY: return "array";
case JSI_OT_FUNCTION: return "function";
case JSI_OT_OBJECT: return "object";
case JSI_OT_REGEXP: return "regexp";
case JSI_OT_ITER: return "iter";
case JSI_OT_USEROBJ: return "userobj";
case JSI_OT_UNDEF: return "any";
}
return "undefined";
}
|
CWE-120
| null | 519,901 |
329202319516925571242937571004679007520
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC freeAssocTbl(Jsi_Interp *interp, Jsi_HashEntry *hPtr, void *ptr) {
if (!ptr) return JSI_OK;
jsi_DelAssocData(interp, ptr);
return JSI_OK;
}
|
CWE-120
| null | 519,902 |
134431699783479721435502931617086169612
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC MySqlExistsCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
Jsi_RC rc;
MySqlObj *jdb;
if (!(jdb = _mysql_getDbHandle(interp, _this, funcPtr))) return JSI_ERROR;
Jsi_Value *vSql = Jsi_ValueArrayIndex(interp, args, 0);
const char *zSql;
Jsi_DString dStr = {};
MyDbEvalContext sEval = {};
zSql = Jsi_ValueGetDString(interp, vSql, &dStr, 0);
Jsi_DString sStr;
Jsi_DSInit(&sStr);
sEval.nocache = jdb->queryOpts.nocache;
if (mdbEvalInit(interp, &sEval, jdb, zSql, &sStr, 0, 0) != JSI_OK)
return JSI_ERROR;
sEval.ret = *ret;
int cnt = 0;
if( JSI_OK==(rc = mdbEvalStep(&sEval)) ) {
int nCol = sEval.prep->numCol;
if (nCol>0)
cnt++;
}
mdbEvalFinalize(&sEval);
if( rc==JSI_BREAK ) {
rc = JSI_OK;
}
Jsi_DSFree(&dStr);
Jsi_ValueMakeBool(interp, ret, cnt);
return rc;
}
|
CWE-120
| null | 519,903 |
106986093375803560739681445170412830955
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
int Jsi_ValueCmp(Jsi_Interp *interp, Jsi_Value *v1, Jsi_Value* v2, int flags)
{
DECL_VALINIT(res1);
DECL_VALINIT(res2);
int r = 1;
int nocase = (flags&JSI_SORT_NOCASE), dict = ((flags & JSI_SORT_DICT));
if (v1 == v2)
return 1;
if (v1->vt != v2->vt) {
jsi_ValueToPrimitiveRes(interp, v1, &res1);
jsi_ValueToPrimitiveRes(interp, v2, &res2);
v1 = &res1;
v2 = &res2;
}
if (v1->vt != v2->vt) {
if ((flags&JSI_CMP_EXACT))
return 1;
if ((v1->vt == JSI_VT_UNDEF || v1->vt == JSI_VT_NULL) &&
(v2->vt == JSI_VT_UNDEF || v2->vt == JSI_VT_NULL)) {
r = 0;
} else {
Jsi_Number n1, n2;
n1 = Jsi_ValueToNumberInt(interp, v1, 0);
n2 = Jsi_ValueToNumberInt(interp, v2, 0);
r = (n2 - n1);
}
} else {
switch (v1->vt) {
case JSI_VT_NUMBER:
if (v2->d.num == v1->d.num) return 0;
r = (v2->d.num < v1->d.num ? -1 : 1);
break;
case JSI_VT_BOOL:
r = (v2->d.val - v1->d.val);
break;
case JSI_VT_STRING:
r = (Jsi_StrcmpDict(v2->d.s.str, v1->d.s.str, nocase, dict));
break;
case JSI_VT_OBJECT:
/* TODO: refer to objects joined to each other */
if (v2->vt != JSI_VT_OBJECT)
r = 1;
else if (v1->d.obj->ot == JSI_OT_STRING && v2->d.obj->ot == JSI_OT_STRING)
r = (Jsi_StrcmpDict(v2->d.obj->d.s.str, v1->d.obj->d.s.str, nocase, dict));
else
r = (v2->d.obj - v1->d.obj);
break;
case JSI_VT_UNDEF:
case JSI_VT_NULL:
r = 0;
break;
default:
Jsi_LogBug("Unexpected value type");
}
}
return r;
}
|
CWE-120
| null | 519,904 |
333190639270359787171873381246656005407
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static char **jsiRlGetMatches(const char *cstr, int start, int end) {
char **matches = NULL;
char *str = rl_line_buffer;
jsiRlStart = start;
if (1 || start == 0 || !completeValues) {
int rc;
Jsi_Interp* interp = jsi_interactiveInterp;
if (!completeValues)
completeValues = Jsi_ValueNew1(interp);
Jsi_Value *func = interp->onComplete;
if (func == NULL || !Jsi_ValueIsFunction(interp, func))
func = Jsi_NameLookup(interp, "Info.completions");
if (func && Jsi_ValueIsFunction(interp, func)) {
Jsi_Value *items[3] = {};
items[0] = Jsi_ValueNewStringDup(interp, str);
items[1] = Jsi_ValueNewNumber(interp, (Jsi_Number)start);
items[2] = Jsi_ValueNewNumber(interp, (Jsi_Number)end);;
Jsi_Value *args = Jsi_ValueMakeObject(interp, NULL, Jsi_ObjNewArray(interp, items, 3, 0));
Jsi_IncrRefCount(interp, args);
rc = Jsi_FunctionInvoke(interp, func, args, &completeValues, interp->csc);
Jsi_DecrRefCount(interp, args);
if (rc != JSI_OK)
fprintf(stderr, "bad completion: %s %d %d\n", str?str:"", start, end);
}
matches = rl_completion_matches(str, jsiRlCmdMatches);
}
return matches;
}
|
CWE-120
| null | 519,905 |
20472217862726871895685837010092580090
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static int jsi_wsServeHeader(jsi_wsPss *pss, struct lws *wsi, int strLen,
int code, const char *extra, const char *mime, Jsi_DString *jStr)
{
uchar ubuf[JSI_BUFSIZ], *p=ubuf, *end = &ubuf[sizeof(ubuf)-1];
if (!mime) mime = "text/html";
if (code<=0) code = 200;
if (lws_add_http_header_status(wsi, code, &p, end))
return -1;
const char *srv = pss->cmdPtr->server;
if (!srv) srv = "jsiWebSocket";
if (srv[0] && lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_SERVER, (uchar*)srv, Jsi_Strlen(srv), &p, end))
return -1;
if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE, (uchar *)mime, Jsi_Strlen(mime), &p, end))
return -1;
if (lws_add_http_header_content_length(wsi, strLen, &p, end))
return -1;
*p = 0;
Jsi_DSAppend(jStr, (char*)ubuf, extra, NULL);
p = ubuf;
if (lws_finalize_http_header(wsi, &p, end))
return -1;
*p = 0;
Jsi_DSAppend(jStr, (char*)ubuf, NULL);
return 0;
}
|
CWE-120
| null | 519,906 |
221385156321210176875345953750890231359
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC WebSocketIdConfCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
return WebSocketIdCmdOp(interp, args, _this, ret, funcPtr, 0);
}
|
CWE-120
| null | 519,907 |
296342832481014946238721760082789370926
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static int try_open_file(Jsi_Interp *interp, FileObj *udf, Jsi_Value *args)
{
int ret = JSI_ERROR;
fileObjErase(udf);
// TODO: stdin, stdout, stderr, etc.
Jsi_Value *fname = Jsi_ValueArrayIndex(interp, args, 0);
if (fname && Jsi_ValueIsString(interp, fname)) {
Jsi_Value *vmode = Jsi_ValueArrayIndex(interp, args, 1);
const char *mode = NULL;
const char *fstr = Jsi_ValueString(interp, fname, NULL);
if (vmode && Jsi_ValueIsString(interp,vmode)) {
mode = Jsi_ValueString(interp, vmode, NULL);
}
int writ = (mode && (Jsi_Strchr(mode,'w')||Jsi_Strchr(mode,'+')));
int aflag = (writ ? JSI_INTACCESS_WRITE : JSI_INTACCESS_READ);
if (interp->isSafe && Jsi_InterpAccess(interp, fname, aflag) != JSI_OK)
return Jsi_LogError("Safe open failed");
char *rmode = Jsi_Strdup(mode ? mode : "r");
Jsi_Channel chan = Jsi_Open(interp, fname, rmode);
if (chan) {
udf->chan = chan;
udf->fname = fname;
udf->interp = interp;
Jsi_IncrRefCount(interp, fname);
udf->filename = Jsi_Strdup(fstr);
udf->mode = Jsi_Strdup(rmode);
ret = JSI_OK;
}
Jsi_Free(rmode);
}
return ret;
}
|
CWE-120
| null | 519,908 |
13298187520614755986736402529038362275
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_Channel Jsi_GetStdChannel(Jsi_Interp *interp, int id) {
if (id<0 || id>2)
return NULL;
return jsiIntData.stdChans+id;
}
|
CWE-120
| null | 519,909 |
210336290291547994977434851334077606927
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC Jsi_DoneSqlite(Jsi_Interp *interp)
{
Jsi_UserObjUnregister(interp, &sqliteobject);
const char *provide = "Sqlite";
Jsi_PkgProvide(interp, provide, -1, NULL);
return JSI_OK;
}
|
CWE-120
| null | 519,910 |
214829114990190594183510364959416110637
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static MySqlObj *_mysql_getDbHandle(Jsi_Interp *interp, Jsi_Value *_this, Jsi_Func *funcPtr)
{
MySqlObj *jdb = (MySqlObj*)Jsi_UserObjGetData(interp, _this, funcPtr);
if (!jdb) {
Jsi_LogError("MySql call to a non-mysql object");
return NULL;
}
if (!jdb->db)
{
Jsi_LogError("MySql db is closed");
return NULL;
}
return jdb;
}
|
CWE-120
| null | 519,911 |
14677563476247682612642295498342078598
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void mdbEvalRowInfo( MyDbEvalContext *eval, int *pnCol, char ***papColName, Jsi_OptionId **papColType) {
if (!papColName) {
//TODO: Array ???
}
*papColName = eval->prep->colNames;
*papColType = eval->prep->colTypes;
*pnCol = eval->prep->numCol;
}
|
CWE-120
| null | 519,912 |
307387480503175280360368821671382802802
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_OpCodes *code_next() { JSI_NEW_CODES(0,OP_NEXT, 0); }
|
CWE-120
| null | 519,913 |
230088085624547968535720985395220061624
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void mdbOutputCsv(QueryOpts *p, const char *z, Jsi_DString *dStr, int bSep)
{
if( z==0 ) {
Jsi_DSAppend(dStr, p->nullvalue?p->nullvalue:"", NULL);
} else {
int i;
int nSep = Jsi_Strlen(p->separator);
for(i=0; z[i]; i++) {
if( needCsvQuote[((unsigned char*)z)[i]] ||
(z[i]==p->separator[0] && (nSep==1 || memcmp(z, p->separator, nSep)==0)) ) {
i = 0;
break;
}
}
if( i==0 ) {
Jsi_DSAppend(dStr, "\"", NULL);
for(i=0; z[i]; i++) {
if( z[i]=='"' ) Jsi_DSAppend(dStr, "\"", NULL);
Jsi_DSAppendLen(dStr, z+i, 1);
}
Jsi_DSAppend(dStr, "\"", NULL);
} else {
Jsi_DSAppend(dStr, z, NULL);
}
}
if( bSep ) {
Jsi_DSAppend(dStr, p->separator, NULL);
}
}
|
CWE-120
| null | 519,914 |
255676622792848612187421107875093732553
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC StringLastIndexOfCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
int sLen, bLen;
const char *v;
ChkString(_this, funcPtr, v, &sLen, &bLen);
Jsi_Value *seq = Jsi_ValueArrayIndex(interp, args, skip);
Jsi_Value *start = Jsi_ValueArrayIndex(interp, args, 1+skip);
if (!seq) {
Jsi_ValueMakeNumber(interp, ret, -1);
return JSI_OK;
}
const char *vseq = Jsi_ValueToString(interp, seq, NULL);
int istart = 0;
if (start) {
if (Jsi_GetIntFromValue(interp, start, &istart)) {
return JSI_ERROR;
}
if (istart < 0) istart = 0;
}
int r = Jsi_Strrpos(v, istart, vseq, 0);
Jsi_ValueMakeNumber(interp, ret, r);
return JSI_OK;;
}
|
CWE-120
| null | 519,915 |
293998853078619073808460842440274400292
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_RC Jsi_EvalZip(Jsi_Interp *interp, const char *exeFile, const char *mntDir, int *jsFound)
{
#if JSI__ZVFS==1
Jsi_StatBuf stat;
Jsi_Value *vinit, *linit, *vmnt = NULL;
Jsi_Value *vexe = Jsi_ValueNewStringKey(interp, exeFile);
Jsi_Value *ret = NULL;
Jsi_RC rc;
const char *omntDir = mntDir;
int pass = 0;
Jsi_IncrRefCount(interp, vexe);
Jsi_HashSet(interp->genValueTbl, vexe, vexe);
if (jsFound)
*jsFound = 0;
if (!mntDir)
ret = Jsi_ValueNew(interp);
else {
vmnt = Jsi_ValueNewStringKey(interp, mntDir);
Jsi_IncrRefCount(interp, vmnt);
Jsi_HashSet(interp->genValueTbl, vmnt, vmnt);
}
bool osafe = interp->isSafe;
if (interp->startSafe)
interp->isSafe = 0;
rc =Jsi_Mount(interp, vexe, vmnt, &ret);
interp->isSafe = osafe;
if (rc != JSI_OK)
return rc;
Jsi_DString dStr, bStr;
Jsi_DSInit(&dStr);
Jsi_DSInit(&bStr);
if (!mntDir) {
mntDir = Jsi_KeyAdd(interp, Jsi_ValueString(interp, ret, NULL));
Jsi_DecrRefCount(interp, ret);
}
dochk:
Jsi_DSAppend(&dStr, mntDir, "/main.jsi", NULL);
if (interp->pkgDirs)
Jsi_ValueArrayPush(interp, interp->pkgDirs, Jsi_ValueNewStringKey(interp, mntDir));
else {
interp->pkgDirs = Jsi_ValueNewArray(interp, &mntDir, 1);
Jsi_IncrRefCount(interp, interp->pkgDirs);
}
vinit = Jsi_ValueNewStringKey(interp, Jsi_DSValue(&dStr));
Jsi_IncrRefCount(interp, vinit);
Jsi_HashSet(interp->genValueTbl, vinit, vinit);
Jsi_DSFree(&dStr);
Jsi_DSAppend(&dStr, mntDir, "/lib", NULL);
const char *str = Jsi_DSValue(&dStr);
linit = Jsi_ValueNewStringKey(interp, str);
Jsi_IncrRefCount(interp, linit);
if (Jsi_Stat(interp, linit, &stat) == 0)
Jsi_ValueArrayPush(interp, interp->pkgDirs, linit);
Jsi_DecrRefCount(interp, linit);
Jsi_DSFree(&dStr);
Jsi_DSFree(&bStr);
if (Jsi_Stat(interp, vinit, &stat) == 0) {
if (jsFound)
*jsFound |= JSI_ZIP_MAIN;
interp->execZip = vexe;
return Jsi_EvalFile(interp, vinit, JSI_EVAL_ARGV0|JSI_EVAL_AUTOINDEX);
}
if (Jsi_AddAutoFiles(interp, mntDir) && omntDir)
*jsFound = JSI_ZIP_INDEX;
if (!pass++) {
str = Jsi_Strrchr(exeFile, '/');
if (str) str++;
else str = exeFile;
char *bn = Jsi_DSAppend(&bStr, mntDir, "/", str, NULL);
bn = Jsi_Strrchr(bn, '.');
if (bn) *bn = 0;
mntDir = Jsi_DSValue(&bStr);
linit = Jsi_ValueNewStringKey(interp, mntDir);
Jsi_IncrRefCount(interp, linit);
int bsi = Jsi_Stat(interp, linit, &stat);
Jsi_DecrRefCount(interp, linit);
if (bsi == 0)
goto dochk;
Jsi_DSFree(&bStr);
}
#endif
return JSI_OK;
}
|
CWE-120
| null | 519,916 |
128532157447305337433537472731546777478
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
const char *jsi_ValueTypeName(Jsi_Interp *interp, Jsi_Value *val)
{
switch (val->vt) {
case JSI_VT_NUMBER: return "number";
case JSI_VT_STRING: return "string";
case JSI_VT_BOOL: return "boolean";
case JSI_VT_OBJECT: if (val->d.obj->ot == JSI_OT_OBJECT && val->d.obj->isarrlist) return "array"; return jsi_ObjectTypeName(interp, val->d.obj->ot);
case JSI_VT_VARIABLE: return "variable";
case JSI_VT_NULL: return "null";
case JSI_VT_UNDEF: break;
}
return "undefined";
}
|
CWE-120
| null | 519,917 |
5785174870381406710882199150518824331
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
char *jsi_utf_tocase(const char *cp, int upper, Jsi_DString *dsPtr)
{
char unibuf[10];
while (*cp) {
#if JSI__UTF8
if (*cp&0x80) {
int32_t c;
Jsi_UtfToUniChar(cp, &c);
int n = Jsi_UniCharToUtf(c, unibuf);
unibuf[n] = 0;
cp += n;
} else
#endif
{
unibuf[0] = (upper?toupper(*cp):tolower(*cp));
unibuf[1] = 0;
cp++;
}
if (upper==2) //totile
upper = 0;
Jsi_DSAppend(dsPtr, unibuf, NULL);
}
return Jsi_DSValue(dsPtr);
}
|
CWE-120
| null | 519,918 |
239523622385620892597839126125298972221
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC NumberIsNaNCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr) {
return jsi_NumberIsFiniteCmd(interp, args, _this, ret, funcPtr, 3);
}
|
CWE-120
| null | 519,919 |
234335263436361033326178270608127695473
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
void Jsi_NumberItoA10(Jsi_Wide value, char* buf, int bsiz)
{
snprintf(buf, bsiz, "%" PRId64, value);
}
|
CWE-120
| null | 519,920 |
255886132200828946614799195857466322635
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_RC Jsi_MutexLock(Jsi_Interp *interp, Jsi_Mutex *mtx) { return JSI_OK; }
|
CWE-120
| null | 519,921 |
279977695320627991072193429116406047580
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
void Jsi_ShiftArgs(Jsi_Interp *interp, Jsi_Value *v) {
if (!v)
v = interp->args;
if (v==NULL || v->vt != JSI_VT_OBJECT || v->d.obj->arr == NULL || v->d.obj->arrCnt <= 0)
return;
Jsi_Obj *obj = v->d.obj;
int n = v->d.obj->arrCnt;
n--;
v = obj->arr[0];
if (v)
Jsi_DecrRefCount(interp, v);
if (n>0)
memmove(obj->arr, obj->arr+1, n*sizeof(Jsi_Value*));
obj->arr[n] = NULL;
Jsi_ObjSetLength(interp, obj, n);
}
|
CWE-120
| null | 519,922 |
310238853642349759646341902389898714455
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void dbReleaseColumnNames(DbEvalContext *p) {
//Jsi_Interp *interp = p->jdb->interp;
if( p->apColName && p->apColName != (char**)p->staticColNames) {
int i;
for(i=0; i<p->nCol; i++) {
Jsi_Free(p->apColName[i]);
}
Jsi_Free((char *)p->apColName);
}
if( p->apColType && p->apColType != p->staticColTypes) {
Jsi_Free((char *)p->apColType);
}
p->apColName = NULL;
p->apColType = NULL;
p->nCol = 0;
}
|
CWE-120
| null | 519,923 |
325380211593728248060291836810049125610
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC jsi_BitfieldToValue(Jsi_Interp *interp, Jsi_OptionSpec* spec, Jsi_Value **outValue,
Jsi_DString *outStr, void *record, Jsi_Wide flags)
{
Jsi_csgset *bsget = spec->init.OPT_BITS;
Jsi_Interp *d = interp;
int idx = spec->idx;
uchar *data = (uchar*)record;
int64_t inum;
Jsi_OptionSpec* enumSpec = (typeof(enumSpec))spec->data;
if (!d || !bsget || idx<0)
return Jsi_LogBug("invalid bitfield");
Jsi_RC rc = (*bsget)(interp, data, &inum, spec, idx, 0);
if (rc != JSI_OK)
return JSI_ERROR;
if (enumSpec) {
struct numStruct { int64_t numVal; } nval = { inum };
Jsi_OptionSpec eSpec[] = {
JSI_OPT(CUSTOM, struct numStruct, numVal, .help=spec->help, .flags=JSI_OPT_ENUM_SPEC, .custom=Jsi_Opt_SwitchEnum,
.data=(void*)enumSpec, .info=0, .tname=spec->tname, .value=0, .bits=0, .boffset=8*sizeof(int64_t) ), //TODO: extra
JSI_OPT_END(struct numStruct)
};
if (JSI_OK != jsi_EnumToValue(interp, eSpec, outValue, outStr, (void*)&nval, flags))
return JSI_ERROR;
} else if (outStr) {
char obuf[JSI_MAX_NUMBER_STRING];
snprintf(obuf, sizeof(obuf), "%" PRId64, inum);
Jsi_DSAppend(outStr, obuf, NULL);
} else {
Jsi_Number num = (Jsi_Number)inum;
Jsi_ValueMakeNumber(interp, outValue, num);
}
return JSI_OK;
}
|
CWE-120
| null | 519,924 |
90614448129127841826390992364696248781
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC NumberConstructor(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
if (Jsi_FunctionIsConstructor(funcPtr)) {
Jsi_Number nv = 0.0;
Jsi_Value *v = Jsi_ValueArrayIndex(interp, args, 0);
if (v) {
Jsi_ValueToNumber(interp, v);
nv = v->d.num;
}
_this->d.obj->ot = JSI_OT_NUMBER;
_this->d.obj->d.num = nv;
Jsi_ValueToObject(interp, _this);
Jsi_ValueMakeNumber(interp, ret, nv);
return JSI_OK;
}
Jsi_Value *v = Jsi_ValueArrayIndex(interp, args, 0);
if (v) {
Jsi_ValueToNumber(interp, v);
Jsi_ValueDup2(interp, ret, v);
Jsi_ValueToObject(interp, *ret);
return JSI_OK;
}
Jsi_ValueMakeNumber(interp, ret, 0.0);
return JSI_OK;
}
|
CWE-120
| null | 519,925 |
311011014689553214149536516847562577050
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC StringSplitCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this, //TODO: UTF
Jsi_Value **ret, Jsi_Func *funcPtr)
{
char **argv; int argc;
int sLen, bLen, spLen = 1, noEmpty=0;
Jsi_RC rc = JSI_OK;
const char *v, *split = "";
ChkString(_this, funcPtr, v, &sLen, &bLen);
Jsi_Value *spliton = Jsi_ValueArrayIndex(interp, args, skip);
if (spliton) {
if (Jsi_ValueIsNull(interp, spliton))
noEmpty = 1;
else if (Jsi_ValueIsString(interp, spliton))
split = Jsi_ValueString(interp, spliton, &spLen);
}
Jsi_DString sStr;
Jsi_DSInit(&sStr);
if (spLen)
Jsi_SplitStr(v, &argc, &argv, split, &sStr);
Jsi_Obj *obj = Jsi_ObjNewType(interp, JSI_OT_ARRAY);
int i, n = 0, siz = argc;
if (noEmpty) {
for (i=0, siz=0; i<argc; i++) if (argv[i][0]) siz++;
} else if (!spLen)
argc = siz = bLen;
if (Jsi_ObjArraySizer(interp, obj, siz) <= 0) {
rc = Jsi_LogError("index too large: %d", siz);
Jsi_ObjFree(interp, obj);
goto bail;
}
Jsi_ValueMakeArrayObject(interp, ret, obj);
for (i = 0; i < argc; ++i) {
if (noEmpty && !argv[i][0]) continue;
char ctmp[2] = " ", *cst = ctmp;
if (!spLen)
ctmp[0] = v[i];
else
cst = argv[i];
Jsi_Value *v = Jsi_ValueNewStringDup(interp, cst);
Jsi_IncrRefCount(interp, v);
obj->arr[n++] = v;
}
Jsi_ObjSetLength(interp, obj, siz);
bail:
Jsi_DSFree(&sStr);
return rc;
}
|
CWE-120
| null | 519,926 |
179403226097911394426199472449774228364
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC StringRepeatCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
int sLen, bLen;
const char *v;
ChkString(_this, funcPtr, v, &sLen, &bLen);
Jsi_Value *start = Jsi_ValueArrayIndex(interp, args, skip);
Jsi_Number ncnt;
if (!start || Jsi_GetNumberFromValue(interp,start, &ncnt) != JSI_OK || ncnt>MAX_LOOP_COUNT || ncnt<0 || bLen<=0) {
return JSI_ERROR;
}
int cnt = (int)ncnt;
Jsi_DString dStr = {};
while (cnt-- > 0) {
Jsi_DSAppendLen(&dStr, v, bLen);
if (Jsi_DSLength(&dStr)>JSI_MAX_ALLOC_BUF) {
Jsi_DSFree(&dStr);
return Jsi_LogError("too long");
}
}
Jsi_ValueFromDS(interp, &dStr, ret);
return JSI_OK;
}
|
CWE-120
| null | 519,927 |
51197306265893288108088295642445454035
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
bool Jsi_OptionsValid(Jsi_Interp *interp, Jsi_OptionSpec* spec)
{
int i = 0;
while (spec[i].id>=JSI_OPTION_BOOL && spec[i].id < JSI_OPTION_END) {
SIGASSERTMASK(spec+i, OPTS, 0xff);
if (spec[i].help && Jsi_Strchr(spec[i].help, '\n')) {
if (interp)
Jsi_LogError("item \"%s\": help contains newline", spec[i].name);
return 0;
}
i++;
}
return (i>0);
}
|
CWE-120
| null | 519,928 |
128420146238034110732928340496785700915
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC jsi_wsfreePss(Jsi_Interp *interp, Jsi_HashEntry* hPtr, void *ptr) {
jsi_wsPss *pss = (jsi_wsPss*)ptr;
WSSIGASSERT(pss, PWS);
if (pss) {
pss->hPtr = NULL;
jsi_wsdeletePss(pss);
}
return JSI_OK;
}
|
CWE-120
| null | 519,929 |
76864201572598134859205073709758756288
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC mdbEvalCallCmd( MyDbEvalContext *p, Jsi_Interp *interp, Jsi_RC result)
{
int cnt = 0;
Jsi_RC rc = result;
Jsi_Value *varg1;
Jsi_Obj *argso;
char **apColName = NULL;
Jsi_OptionId *apColType = NULL;
if (p->jdb->debug & mdbTMODE_EVAL)
JSI_DBQUERY_PRINTF( "DEBUG: eval\n");
while( (rc==JSI_OK) && JSI_OK==(rc = mdbEvalStep(p)) ) {
int i;
int nCol;
cnt++;
mdbEvalRowInfo(p, &nCol, &apColName, &apColType);
if (nCol<=0)
continue;
if (Jsi_ValueIsNull(interp,p->tocall))
continue;
/* Single object containing sql result members. */
varg1 = Jsi_ValueMakeObject(interp, NULL, argso = Jsi_ObjNew(interp));
for(i=0; i<nCol; i++) {
Jsi_Value *nnv = mdbEvalSetColumnValue(p, i, NULL);
Jsi_ObjInsert(interp, argso, apColName[i], nnv, 0);
}
Jsi_IncrRefCount(interp, varg1);
bool rb = Jsi_FunctionInvokeBool(interp, p->tocall, varg1);
if (Jsi_InterpGone(interp))
return JSI_ERROR;
Jsi_DecrRefCount(interp, varg1);
if (rb)
break;
}
//mdbEvalFinalize(p);
if( rc==JSI_OK || rc==JSI_BREAK ) {
//Jsi_ResetResult(interp);
rc = JSI_OK;
}
return rc;
}
|
CWE-120
| null | 519,930 |
190089649383272717097334192906839867499
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static int tree_postorder(Jsi_Tree *treePtr, Jsi_TreeEntry *hPtr, Jsi_TreeWalkProc *callback, void *data) {
uint epoch = treePtr->epoch;
if (hPtr == NULL) return JSI_OK;
if (hPtr->right != NULL) {
if (tree_postorder(treePtr, hPtr->right, callback, data) != JSI_OK || epoch != treePtr->epoch)
return JSI_ERROR;
}
if (hPtr->left != NULL) {
if (tree_postorder(treePtr, hPtr->left, callback, data) != JSI_OK || epoch != treePtr->epoch)
return JSI_ERROR;
}
if (callback(treePtr, hPtr, data) != JSI_OK || epoch != treePtr->epoch)
return JSI_ERROR;
return JSI_OK;
}
|
CWE-120
| null | 519,931 |
23056862417365620031406376734926522936
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
int Jsi_Eof(Jsi_Interp *interp, Jsi_Channel chan) {
if (chan->fsPtr==0 || !chan->fsPtr->eofProc) return -1;
return chan->fsPtr->eofProc(chan);
}
|
CWE-120
| null | 519,932 |
254383820505575100982014356801788625430
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static bool jsi_wswebsocketObjIsTrue(void *data)
{
return 1;
}
|
CWE-120
| null | 519,933 |
38970015853675456483399135370967732368
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
int jsi_PstateSetString(jsi_Pstate *ps, const char *str)
{
Jsi_Interp *interp = ps->interp;
jsi_Lexer *l = ps->lexer;
jsi_PstateClear(ps);
l->ltype = LT_STRING;
Jsi_HashEntry *hPtr = Jsi_HashEntryNew(interp->codeTbl, (void*)str, NULL);
assert(hPtr);
l->d.str = (char*)Jsi_HashKeyGet(hPtr);
return JSI_OK;
}
|
CWE-120
| null | 519,934 |
215830574930834806648279959068929938905
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_Interp* Jsi_InterpNew(Jsi_InterpOpts *opts)
{
return jsi_InterpNew(NULL, NULL, opts);
}
|
CWE-120
| null | 519,935 |
59190975120360263826726342754335591851
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_OpCodes *code_dec(jsi_Pstate *p, jsi_Pline *line, int e) { JSI_NEW_CODESLN(0,OP_DEC, e); }
|
CWE-120
| null | 519,936 |
65456607246970529087470125927730163283
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void jsi_PushFunc(jsi_Pstate *ps, jsi_OpCode *ip, jsi_ScopeChain *scope, Jsi_Value *currentScope) {
/* TODO: now that we're caching ps, may need to reference function ps for context_id??? */
Jsi_Interp *interp = ps->interp;
Jsi_FuncObj *fo = jsi_FuncObjNew(interp, (Jsi_Func *)ip->data);
fo->scope = jsi_ScopeChainDupNext(interp, scope, currentScope);
Jsi_Obj *obj = Jsi_ObjNewType(interp, JSI_OT_FUNCTION);
obj->d.fobj = fo;
Jsi_Value *v = _jsi_STACKIDX(interp->framePtr->Sp), *fun_prototype = jsi_ObjValueNew(interp);
fun_prototype->d.obj->__proto__ = interp->Object_prototype;
Jsi_ValueMakeObject(interp, &v, obj);
Jsi_ValueInsert(interp, v, "prototype", fun_prototype, JSI_OM_DONTDEL|JSI_OM_DONTENUM);
/* TODO: make own prototype and prototype.constructor */
bool isNew;
Jsi_HashEntry *hPtr; Jsi_Value *vv;
if (interp->framePtr->Sp == 1 && (vv=_jsi_STACKIDX(0))->vt == JSI_VT_VARIABLE) {
const char *varname = NULL;
vv = vv->d.lval;
if (vv && vv->f.bits.lookupfailed && vv->d.lookupFail) {
varname = vv->d.lookupFail;
vv->f.bits.lookupfailed = 0;
}
if (varname) {
if (!fo->func->name)
fo->func->name = varname;
hPtr = Jsi_HashEntryNew(interp->varTbl, varname, &isNew);
if (hPtr)
Jsi_HashValueSet(hPtr, obj);
}
}
hPtr = Jsi_HashEntryNew(interp->funcObjTbl, fo, &isNew);
if (hPtr && isNew) {
Jsi_ObjIncrRefCount(interp, obj);
Jsi_HashValueSet(hPtr, obj);
}
jsiPush(interp,1);
}
|
CWE-120
| null | 519,937 |
126352529550017121446994142307040103262
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC jsi_StringFree(Jsi_Interp *interp, Jsi_HashEntry *hPtr, void *d) {
Jsi_String *s = (Jsi_String *)d;
if (s->flags&1)
Jsi_Free(s->str);
Jsi_Free(s);
return JSI_OK;
}
|
CWE-120
| null | 519,938 |
318585241246749771345344216898279155672
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC InterpInfoCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
InterpObj *udf = (InterpObj *)Jsi_UserObjGetData(interp, _this, funcPtr);
Jsi_Interp *subinterp = interp;
if (udf) {
if (!udf->subinterp)
return Jsi_LogError("Sub-interp gone");
subinterp = udf->subinterp;
}
return jsi_InterpInfo(subinterp, args, _this, ret, funcPtr);
}
|
CWE-120
| null | 519,939 |
107338764250136845644513341952757591890
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC jsi_wswebsockUpdate(Jsi_Interp *interp, void *data)
{
jsi_wsCmdObj *cmdPtr = (jsi_wsCmdObj*)data;
WSSIGASSERT(cmdPtr,OBJ);
jsi_wsService(cmdPtr);
return JSI_OK;
}
|
CWE-120
| null | 519,940 |
273002760527720277986045056112161569581
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_OpCodes *code_mod() { JSI_NEW_CODES(0,OP_MOD, 0); }
|
CWE-120
| null | 519,941 |
204021840735343711897748008530059688070
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void jsonNewDString(Jsi_Interp *interp, Jsi_DString *dStr, const char* str, int len)
{
char buf[JSI_MAX_NUMBER_STRING], *dp = buf;
const char *cp = str;
int ulen;
while ((cp-str)<len) {
if (*cp == '\\') {
switch (cp[1]) {
case 'b': *dp++ = '\b'; break;
case 'n': *dp++ = '\n'; break;
case 'r': *dp++ = '\r'; break;
case 'f': *dp++ = '\f'; break;
case 't': *dp++ = '\t'; break;
case '\"': *dp++ = '\"'; break;
case '\\': *dp++ = '\\'; break;
case 'u':
if ((ulen=Jsi_UtfDecode(cp+2, dp))) {
dp += ulen;
cp += 4;
} else {
*dp++ = '\\';
*dp++ = 'u';
}
break;
}
cp+=2;
} else {
*dp++ = *cp++;
}
if ((dp-buf)>90) {
*dp = 0;
Jsi_DSAppendLen(dStr, buf, dp-buf);
dp = buf;
}
}
*dp = 0;
Jsi_DSAppendLen(dStr, buf, dp-buf);
}
|
CWE-120
| null | 519,942 |
137127704923966456922944060939894237510
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
void jsi_memDebugBreak() {
}
|
CWE-120
| null | 519,943 |
260607720978075101736726238915092928627
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void dbOutputCsv(QueryOpts *p, const char *z, Jsi_DString *dStr, int bSep)
{
if( z==0 ) {
Jsi_DSAppend(dStr, p->nullvalue?p->nullvalue:"", NULL);
} else {
int i;
int nSep = Jsi_Strlen(p->separator);
for(i=0; z[i]; i++) {
if( needCsvQuote[((unsigned char*)z)[i]] ||
(z[i]==p->separator[0] && (nSep==1 || memcmp(z, p->separator, nSep)==0)) ) {
i = 0;
break;
}
}
if( i==0 ) {
Jsi_DSAppend(dStr, "\"", NULL);
for(i=0; z[i]; i++) {
if( z[i]=='"' ) Jsi_DSAppend(dStr, "\"", NULL);
Jsi_DSAppendLen(dStr, z+i, 1);
}
Jsi_DSAppend(dStr, "\"", NULL);
} else {
Jsi_DSAppend(dStr, z, NULL);
}
}
if( bSep ) {
Jsi_DSAppend(dStr, p->separator, NULL);
}
}
|
CWE-120
| null | 519,944 |
157127456606723978084790615367569651510
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
int Jsi_ValueGetLength(Jsi_Interp *interp, Jsi_Value *v) {
if (Jsi_ValueIsArray(interp, v))
return v->d.obj->arrCnt;
Jsi_LogWarn("expected array");
return 0;
}
|
CWE-120
| null | 519,945 |
49631981595354599408380512479070227492
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_RC Jsi_LogMsg(Jsi_Interp *interp, uint code, const char *format,...) {
if (Jsi_InterpGone(interp))
return JSI_ERROR;
va_list va;
va_start (va, format);
char pbuf[JSI_BUFSIZ/8] = "";
char buf[JSI_BUFSIZ/2];
const char *term = "", *pterm=pbuf;
static char lastMsg[JSI_BUFSIZ/2] = "";
static int lastCnt = 0;
static Jsi_Interp *LastInterp = NULL;
Jsi_Interp *lastInterp = LastInterp;
const char *emsg = buf, *mt;
int islog, line = 0, lofs = 0, noDups=0;
bool isHelp = (format[0]=='.' && !Jsi_Strncmp(format, "...", 3));
Jsi_OptionSpec *oep = interp->parseMsgSpec;
const char *pps = "", *curFile = "";
char *ss = interp->lastPushStr;
if (interp==NULL)
interp = jsiIntData.mainInterp;
LastInterp = interp;
if (lastInterp != interp)
noDups = 1;
/* Filter out try/catch (TODO: and non-syntax errors??). */
if (interp == NULL) {
//nullInterp:
if (logHook)
(*logHook)(format, va);
else {
vfprintf(stderr, format, va);
fputc('\n', stderr);
}
va_end(va);
return JSI_ERROR;
}
curFile = jsi_GetCurFile(interp);
switch (code) {
case JSI_LOG_INFO: if (!interp->logOpts.Info) goto bail; break;
case JSI_LOG_WARN: if (!interp->logOpts.Warn) goto bail; break;
case JSI_LOG_DEBUG: if (!interp->logOpts.Debug && !jsi_LogEnabled(interp, code)) goto bail; break;
case JSI_LOG_TRACE: if (!interp->logOpts.Trace && !jsi_LogEnabled(interp, code)) goto bail; break;
case JSI_LOG_TEST: if (!interp->logOpts.Test && !jsi_LogEnabled(interp, code)) goto bail; break;
case JSI_LOG_PARSE: break; //if (!interp->parent) goto nullInterp; break;
case JSI_LOG_ERROR: {
if (!interp->logOpts.Error) goto bail;
if ((interp->framePtr->tryDepth - interp->framePtr->withDepth)>0 && interp->inParse<=0
&& (!interp->tryList || !(interp->tryList->inCatch|interp->tryList->inFinal))) {
/* Should only do the first or traceback? */
if (!interp->errMsgBuf[0]) {
vsnprintf(interp->errMsgBuf, sizeof(interp->errMsgBuf), format, va);
//interp->errMsgBuf[sizeof(interp->errMsgBuf)-1] = 0;
interp->errFile = jsi_GetCurFile(interp);
interp->errLine = (interp->curIp?interp->curIp->Line:0);
emsg = interp->errMsgBuf;
}
goto done;
}
interp->logErrorCnt++;
break;
}
}
mt = (code <= JSI__LOGLAST ? jsi_LogCodes[code] : "");
if (isHelp) mt = "help";
assert((JSI__LOGLAST+2) == (sizeof(jsi_LogCodes)/sizeof(jsi_LogCodes[0])));
if (!Jsi_Strchr(format,'\n')) term = "\n";
if (interp->strict && interp->lastParseOpt)
ss = (char*)Jsi_ValueToString(interp, interp->lastParseOpt, NULL);
if (code != JSI_LOG_INFO && code < JSI_LOG_TEST && interp && ss && ss[0]) {
char psbuf[JSI_BUFSIZ/6];
if (Jsi_Strchr(ss,'%')) {
char *s = ss, *sd = psbuf;
int plen=0, llen = sizeof(psbuf)-2;
while (*s && plen<llen) {
if (*s == '%')
sd[plen++] = '%';
sd[plen++] = *s;
s++;
}
sd[plen] = 0;
ss = psbuf;
}
while (*ss && isspace(*ss))
ss++;
if (*ss && !isHelp)
snprintf(pbuf, sizeof(pbuf), " (at or near \"%s\")\n", ss);
}
pbuf[sizeof(pbuf)-1] = 0;
if (interp->inParse && interp->parseLine) {
line = interp->parseLine->first_line;
lofs = interp->parseLine->first_column;
} else if (interp->inParse && interp->parsePs) {
line = interp->parsePs->lexer->cur_line;
lofs = interp->parsePs->lexer->cur_char;
} else if (interp->curIp) {
if (interp->callerErr && interp->framePtr && interp->framePtr->parent) {
jsi_Frame *fptr = interp->framePtr->parent;
line = fptr->line;
lofs = 0;
curFile = fptr->fileName;
} else {
line = interp->curIp->Line;
lofs = interp->curIp->Lofs;
if (line<=0)
line = interp->framePtr->line;
}
}
islog = (interp->parent && interp->debugOpts.msgCallback && code != JSI_LOG_BUG);
Jsi_DString pStr;
Jsi_DSInit(&pStr);
if (oep) {
if (oep->id != JSI_OPTION_CUSTOM || !oep->custom)
pps = Jsi_DSPrintf(&pStr, "for option \"%s\": ", oep->name);
else {
Jsi_OptionCustom* cust = Jsi_OptionCustomBuiltin(oep->custom);
pps = Jsi_DSPrintf(&pStr, "for %s option \"%s\": ", (cust?cust->name:""), oep->name);
}
}
char *cpt;
if (curFile && interp->logOpts.ftail && (cpt =Jsi_Strrchr(curFile, '/')) && cpt[1])
curFile = cpt+1;
if (curFile && curFile[0] && Jsi_Strchr(curFile,'%')==0 && !islog) {
if (!interp->subOpts.logColNums)
snprintf(buf, sizeof(buf), "%s:%d: %s: %s%s%s%s", curFile, line, mt, pps, format, pterm, term);
else
snprintf(buf, sizeof(buf), "%s:%d.%d: %s: %s%s%s%s", curFile, line, lofs, pps, mt,format, pterm, term);
} else {
snprintf(buf, sizeof(buf), "%s: %s%s%s%s", mt, pps, format, pterm, term);
}
Jsi_DSFree(&pStr);
buf[sizeof(buf)-1]=0;
if (logHook)
(*logHook)(buf, va);
else if (interp->subOpts.logAllowDups)
vfprintf(stderr, buf, va);
else {
char buf1[JSI_BUFSIZ/2];
vsnprintf(buf1, sizeof(buf1), buf, va);
if (!isHelp && !noDups) {
if (buf1[0] && lastCnt && Jsi_Strcmp(buf1, lastMsg)==0) {
lastCnt++;
goto done;
} else if (lastMsg[0] && lastCnt>1 ) {
fprintf(stderr, "REPEAT: Last msg repeated %d times...\"\n" ,lastCnt);
}
if (buf1[0] == 0 || (buf1[0] == '.' && buf1[1] == 0))
goto done;
}
lastCnt = 1;
Jsi_Strcpy(lastMsg, buf1);
if (!islog)
Jsi_Puts(interp, jsi_Stderr, buf1, -1);
//fputs(buf1, stderr);
else {
Jsi_DString jStr={}, kStr={};
Jsi_DSPrintf(&kStr, "[%s, \"%s\", \"%s\", %d, %d ]",
Jsi_JSONQuote(interp, buf1, -1, &jStr), mt, curFile, line, lofs);
if (Jsi_FunctionInvokeJSON(interp->parent, interp->debugOpts.msgCallback, Jsi_DSValue(&kStr), NULL) != JSI_OK)
code = 1;
Jsi_DSFree(&jStr);
Jsi_DSFree(&kStr);
}
}
done:
va_end(va);
if (interp->debugOpts.hook) {
static int inhook = 0;
if (!inhook) {
inhook = 1;
(*interp->debugOpts.hook)(interp, curFile, interp->curIp?interp->curIp->Line:0, interp->level, interp->curFunction, "DEBUG", NULL, emsg);
}
inhook = 0;
}
if ((code & jsi_fatalexit) && !interp->opts.no_exit)
jsi_DoExit(interp, 1);
return (code==JSI_LOG_ERROR?JSI_ERROR:JSI_OK);
bail:
va_end(va);
return JSI_OK;
}
|
CWE-120
| null | 519,946 |
331417810821787987263246910640732751371
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_RC jsi_InitFilesys(Jsi_Interp *interp, int release)
{
if (release) {
jsi_FilesysDone(interp);
return JSI_OK;
}
Jsi_DSInit(&jsiIntData.pwdStr);
Jsi_Hash *fsys = Jsi_UserObjRegister(interp, &fileobject);
if (!fsys)
return Jsi_LogBug("Can not init file system");
Jsi_CommandCreateSpecs(interp, fileobject.name, filesysCmds, fsys, JSI_CMDSPEC_ISOBJ);
if (jsiFSList == NULL) {
Jsi_FSRegister(&jsiFilesystem, NULL);
SetupStdChan(jsiIntData.stdChans, stdin, &jsiFilesystem, JSI_FS_READONLY);
SetupStdChan(jsiIntData.stdChans+1, stdout, &jsiFilesystem, JSI_FS_WRITEONLY);
SetupStdChan(jsiIntData.stdChans+2, stderr, &jsiFilesystem, JSI_FS_WRITEONLY);
}
#if JSI__ZVFS==1
Jsi_InitZvfs(interp, 0);
#endif
#ifndef JSI_OMIT_VFS
jsi_InitVfs(interp, 0);
#endif
return JSI_OK;
}
|
CWE-120
| null | 519,947 |
103829389837498814136337583633879343942
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_ListEntry* Jsi_ListPush(Jsi_List *list, Jsi_ListEntry *item, Jsi_ListEntry *before)
{
Assert(item && list);
if (item->list && (item->list->head == item || item->prev || item->next)) {
Assert(list->opts.freeListProc == item->list->opts.freeListProc);
Jsi_ListPop(item->list, item);
}
if (!item->list)
item->list = list;
else if (list != item->list) {
Assert(list->opts.freeListProc == item->list->opts.freeListProc);
item->list = list;
}
if (!list->head) {
list->head = list->tail = item;
} else if (item == list->head) {
assert(0);
} else if (before == NULL) {
item->prev = list->tail;
list->tail->next = item;
list->tail = item;
} else if (before == list->head) {
item->next = list->head;
list->head->prev = item;
list->head = item;
} else {
item->next = before;
item->prev = before->prev;
before->prev->next = item;
before->prev = item;
}
list->numEntries++;
item->list = list;
return item;
}
|
CWE-120
| null | 519,948 |
54856136539183993175985095953201757621
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC MySqlLastQueryCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
MySqlObj *jdb;
if (!(jdb = _mysql_getDbHandle(interp, _this, funcPtr))) return JSI_ERROR;
const char *str = mysql_info(jdb->db);
if (str)
Jsi_ValueMakeStringDup(interp, ret, str);
return JSI_OK;
}
|
CWE-120
| null | 519,949 |
211015225616741276309817980290070271489
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_RC Jsi_PrototypeObjSet(Jsi_Interp *interp, const char *key, Jsi_Obj *obj)
{
Jsi_Value *val;
Jsi_HashEntry *hPtr = Jsi_HashEntryFind(interp->protoTbl, key);
if (!hPtr)
return JSI_ERROR;
val = (Jsi_Value *)Jsi_HashValueGet(hPtr);
obj->__proto__ = val;
return JSI_OK;
}
|
CWE-120
| null | 519,950 |
73321777812916859306282118973656179865
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC jsi_wsHandlerAdd(Jsi_Interp *interp, jsi_wsCmdObj *cmdPtr, const char *ext, const char *cmd, int flags)
{
Jsi_HashEntry *hPtr;
jsi_wsHander *hdlPtr;
Jsi_Value *valPtr = Jsi_ValueNewStringDup(interp, cmd);
hPtr = Jsi_HashEntryNew(cmdPtr->handlers, ext, NULL);
if (!hPtr)
return JSI_ERROR;
hdlPtr = (jsi_wsHander *)Jsi_Calloc(1, sizeof(*hdlPtr));
hdlPtr->val = valPtr;
hdlPtr->flags = flags;
Jsi_HashValueSet(hPtr, hdlPtr);
Jsi_IncrRefCount(interp, valPtr);
return JSI_OK;
}
|
CWE-120
| null | 519,951 |
49955488052554044963749941967782320045
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_RC Jsi_InitSqlite(Jsi_Interp *interp, int release)
{
if (release) return Jsi_DoneSqlite(interp);
Jsi_Hash* dbSys;
#if JSI_USE_STUBS
if (Jsi_StubsInit(interp, 0) != JSI_OK)
return JSI_ERROR;
#endif
if (!(dbSys = Jsi_UserObjRegister(interp, &sqliteobject)))
return Jsi_LogError("Failed to init sqlite extension");
Jsi_Value *info = Jsi_ValueNew1(interp);
Jsi_JSONParseFmt(interp, &info, "{libVer:\"%s\", hdrVer:\"%s\", hdrNum:%d, hdrSrcId:\"%s\", pkgVer:%d}",
(char *)sqlite3_libversion(), SQLITE_VERSION, SQLITE_VERSION_NUMBER, SQLITE_SOURCE_ID, jsi_DbPkgVersion);
Jsi_PkgOpts dbPkgOpts = { db_ObjCmd_Specs, &dbObjCmd, sqliteCmds, info };
Jsi_RC rc = Jsi_PkgProvideEx(interp, "Sqlite", jsi_DbPkgVersion, Jsi_InitSqlite, &dbPkgOpts);
Jsi_DecrRefCount(interp, info);
if (rc != JSI_OK)
return JSI_ERROR;
if (!Jsi_CommandCreateSpecs(interp, sqliteobject.name, sqliteCmds, dbSys, JSI_CMDSPEC_ISOBJ))
return JSI_ERROR;
#ifdef JSI_DB_TEST
if (getenv("RUN_DB_TEST"))
TestSqlite(interp);
#endif
jsi_DbVfs **dbVfsPtrPtr = (jsi_DbVfs **)Jsi_InterpGetData(interp, JSI_SQLITE_DB_VFS, NULL);
if (dbVfsPtrPtr)
*dbVfsPtrPtr = &SqliteDbVfs;
return JSI_OK;
}
|
CWE-120
| null | 519,952 |
107988147639795445740022866179721803657
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
void Jsi_Release(Jsi_Interp* interp, void *data) {
Jsi_HashEntry *hPtr = Jsi_HashEntryFind(interp->preserveTbl, data);
if (!hPtr) return;
PreserveData *ptr = (PreserveData*)Jsi_HashValueGet(hPtr);
if (!ptr) return;
assert(ptr->interp == interp);
if (--ptr->refCnt > 0) return;
if (ptr->proc)
(*ptr->proc)(interp, data);
Jsi_Free(ptr);
Jsi_HashEntryDelete(hPtr);
}
|
CWE-120
| null | 519,953 |
304135408651040926076382068466986811313
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void IterObjInsertKey(Jsi_IterObj *io, const char *key)
{
assert(!io->isArrayList);
if (io->depth) {
uint i;
for (i=0; i<io->count; i++) {
if (!Jsi_Strcmp(key, io->keys[i]))
return;
}
}
if (io->count >= io->size) {
io->size += 10;
io->keys = (const char**)Jsi_Realloc(io->keys, io->size * sizeof(io->keys[0]));
}
io->keys[io->count] = key;
io->count++;
}
|
CWE-120
| null | 519,954 |
235047839764195323863571918277105218154
| 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)
{
return InterpEvalCmd_(interp, args, _this, ret, funcPtr, 0);
}
|
CWE-120
| null | 519,955 |
213741665876033701198150664767347240328
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC MySqlAffectedRowsCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
MySqlObj *jdb;
if (!(jdb = _mysql_getDbHandle(interp, _this, funcPtr))) return JSI_ERROR;
Jsi_ValueMakeNumber(interp, ret, (Jsi_Number)mysql_affected_rows(jdb->db));
return JSI_OK;
}
|
CWE-120
| null | 519,956 |
176156936989108342552073252463931131532
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void dbPrepStmtLimit( Jsi_Db *jdb)
{
while(jdb->stmtCacheCnt>jdb->stmtCacheMax ) {
Jsi_ListEntry *l = Jsi_ListPopBack(jdb->stmtCache);
dbPrepStmtFree(jdb, (SqlPreparedStmt*)Jsi_ListValueGet(l));
jdb->stmtCacheCnt = Jsi_ListSize(jdb->stmtCache);
}
}
|
CWE-120
| null | 519,957 |
308353918355156276454007299469612084779
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_ListEntry* Jsi_ListPop(Jsi_List *list, Jsi_ListEntry *item)
{
Assert(item && list->head && list->tail && item->list);
SIGASSERT(list, LIST);
SIGASSERT(item, LISTENTRY);
if (item == list->head) {
if (list->head == list->tail)
list->head = list->tail = NULL;
else
list->head = list->head->next;
}
else if (item == list->tail) {
list->tail = list->tail->prev;
list->tail->next = NULL;
} else {
item->prev->next = item->next;
if (item->next)
item->next->prev = item->prev;
}
list->numEntries--;
item->next = item->prev = NULL;
return item;
}
|
CWE-120
| null | 519,958 |
297050787265362360389109473241852158975
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_OpCodes *code_add() { JSI_NEW_CODES(0,OP_ADD, 0); }
|
CWE-120
| null | 519,959 |
184944184993895902892581622863677090886
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC freeFuncObjTbl(Jsi_Interp *interp, Jsi_HashEntry *hPtr, void *ptr) {
Jsi_Obj *v = (Jsi_Obj *)ptr;
if (!v) return JSI_OK;
SIGASSERT(v,OBJ);
if (v->ot != JSI_OT_FUNCTION)
fprintf(stderr, "invalid func obj\n");
else if (v->d.fobj) {
if (v->d.fobj->scope) {
jsi_ScopeChain *scope = v->d.fobj->scope;
v->d.fobj->scope = NULL;
jsi_ScopeChainFree(interp, scope);
}
}
Jsi_ObjDecrRefCount(interp, v);
return JSI_OK;
}
|
CWE-120
| null | 519,960 |
71467626894595063994345203439629622458
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_OpCodes *codes_join(Jsi_OpCodes *a, Jsi_OpCodes *b)
{
Jsi_OpCodes *ret = codes_new(a->code_len + b->code_len);
memcpy(ret->codes, a->codes, a->code_len * sizeof(jsi_OpCode));
memcpy(&ret->codes[a->code_len], b->codes, b->code_len * sizeof(jsi_OpCode));
ret->code_size = a->code_len + b->code_len;
ret->code_len = ret->code_size;
ret->expr_counter = a->expr_counter + b->expr_counter;
#if 0
a->code_len=0;
jsi_FreeOpcodes(a);
b->code_len=0;
jsi_FreeOpcodes(b);
#else
Jsi_Free(a->codes);
Jsi_Free(b->codes);
#ifdef JSI_MEM_DEBUG
if (a->hPtr)
Jsi_HashEntryDelete(a->hPtr);
if (b->hPtr)
Jsi_HashEntryDelete(b->hPtr);
#endif
Jsi_Free(a);
Jsi_Free(b);
#endif
jsiOpCodesCnt[1]++;
jsiOpCodesCnt[2]-=2;
return ret;
}
|
CWE-120
| null | 519,961 |
75210084751388124374812377363893862168
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
void *Jsi_PrototypeGet(Jsi_Interp *interp, const char *key)
{
Jsi_HashEntry *hPtr = Jsi_HashEntryFind(interp->protoTbl, key);
if (!hPtr)
return NULL;
return Jsi_HashValueGet(hPtr);
}
|
CWE-120
| null | 519,962 |
84919820213434334295419714898187446648
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC SqliteInterruptCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
Jsi_Db *jdb;
if (!(jdb = dbGetDbHandle(interp, _this, funcPtr))) return JSI_ERROR;
sqlite3_interrupt(jdb->db);
return JSI_OK;
}
|
CWE-120
| null | 519,963 |
173360820576650173587728523654727367500
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_RC Jsi_Mount( Jsi_Interp *interp, Jsi_Value *archive, Jsi_Value *mount, Jsi_Value **ret)
{
#if JSI__ZVFS==1
return Zvfs_Mount(interp, archive, mount, ret);
#else
return JSI_ERROR;
#endif
}
|
CWE-120
| null | 519,964 |
206744035132653711328371190190720110130
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC StringTrimLeftCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
return _StringTrimCmd(interp, args, _this, ret, funcPtr, 1);
}
|
CWE-120
| null | 519,965 |
166819785604607145134492065001886954929
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
void jsi_ScopeChainFree(Jsi_Interp *interp, jsi_ScopeChain *sc)
{
int i;
for (i = 0; i < sc->chains_cnt; ++i) {
Jsi_DecrRefCount(interp, sc->chains[i]);
}
Jsi_Free(sc->chains);
_JSI_MEMCLEAR(sc);
Jsi_Free(sc);
}
|
CWE-120
| null | 519,966 |
279721093427502865633723731809434374470
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC FilesysTellCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
UdfGet(udf, _this, funcPtr);
Jsi_Wide pos = Jsi_Tell(interp, udf->chan);
Jsi_ValueMakeNumber(interp, ret, (Jsi_Number)pos);
return JSI_OK;
}
|
CWE-120
| null | 519,967 |
314798222495929890329059829286907217847
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_MapEntry* Jsi_MapSearchFirst (Jsi_Map *mapPtr, Jsi_MapSearch *searchPtr, int flags){
SIGASSERT(mapPtr, MAP);
searchPtr->typ = mapPtr->typ;
switch (mapPtr->typ) {
case JSI_MAP_HASH: return (Jsi_MapEntry*)Jsi_HashSearchFirst(mapPtr->v.hash, &searchPtr->v.hash);
case JSI_MAP_TREE: return (Jsi_MapEntry*)Jsi_TreeSearchFirst(mapPtr->v.tree, &searchPtr->v.tree, flags, NULL);
case JSI_MAP_LIST: return (Jsi_MapEntry*)Jsi_ListSearchFirst(mapPtr->v.list, &searchPtr->v.list, flags);
case JSI_MAP_NONE: break;
}
return NULL;
}
|
CWE-120
| null | 519,968 |
163974425801226165432338143829118077450
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static jsi_ForinVar *forinvar_new(jsi_Pstate *pstate, const char *varname, Jsi_OpCodes *local, Jsi_OpCodes *lval)
{
jsi_ForinVar *r = (jsi_ForinVar*)Jsi_Calloc(1,sizeof(*r));
r->sig = JSI_SIG_FORINVAR;
r->varname = varname;
r->local = local;
r->lval = lval;
return r;
}
|
CWE-120
| null | 519,969 |
226575509812411117511334787695972178603
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC ThreadEvalCallback(Jsi_Interp *interp, void* data) {
Jsi_RC rc;
if ((rc=SubInterpEvalCallback(interp, data)) != JSI_OK)
interp->threadErrCnt++;
return rc;
}
|
CWE-120
| null | 519,970 |
72289977051055343467535684642323673745
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC FilesysLstatCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
Jsi_Value **ret, Jsi_Func *funcPtr)
{
UdfGet(udf, _this, funcPtr);
#if JSI__FILESYS==1
return jsi_FileStatCmd(interp, udf->fname, _this, ret, funcPtr, 1);
#else
return JSI_ERROR;
#endif
}
|
CWE-120
| null | 519,971 |
237095235720752644065377943692644298466
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void IterObjInsert(Jsi_IterObj *io, Jsi_TreeEntry *hPtr)
{
IterObjInsertKey(io, (const char*)Jsi_TreeKeyGet(hPtr));
}
|
CWE-120
| null | 519,972 |
223369747566581706798941908527222321631
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static const char *jsi_evalprint(Jsi_Value *v)
{
static char buf[JSI_MAX_NUMBER_STRING];
if (!v)
return "nil";
if (v->vt == JSI_VT_NUMBER) {
snprintf(buf, sizeof(buf), "NUM:%" JSI_NUMGFMT " ", v->d.num);
} else if (v->vt == JSI_VT_BOOL) {
snprintf(buf, sizeof(buf), "BOO:%d", v->d.val);
} else if (v->vt == JSI_VT_STRING) {
snprintf(buf, sizeof(buf), "STR:'%s'", v->d.s.str);
} else if (v->vt == JSI_VT_VARIABLE) {
snprintf(buf, sizeof(buf), "VAR:%p", v->d.lval);
} else if (v->vt == JSI_VT_NULL) {
snprintf(buf, sizeof(buf), "NULL");
} else if (v->vt == JSI_VT_OBJECT) {
snprintf(buf, sizeof(buf), "OBJ:%p", v->d.obj);
} else if (v->vt == JSI_VT_UNDEF) {
snprintf(buf, sizeof(buf), "UNDEFINED");
}
return buf;
}
|
CWE-120
| null | 519,973 |
168814686036739745354698690777546360684
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static void jsi_wsDumpHeaders(jsi_wsCmdObj *cmdPtr, jsi_wsPss *pss, const char *name, Jsi_Value **ret)
{
Jsi_Interp *interp = cmdPtr->interp;
Jsi_Obj *nobj;
Jsi_Value *nv;
if (pss->hdrNum<=0)
return;
if (!name) {
nobj = Jsi_ObjNewType(interp, JSI_OT_ARRAY);
Jsi_ValueMakeObject(interp, ret, nobj);
int nsiz = Jsi_ObjArraySizer(interp, nobj, pss->hdrNum);
if (nsiz < pss->hdrNum) {
printf("header failed, %d != %d", nsiz, pss->hdrNum);
return;
}
}
Jsi_DString dStr = {}, vStr = {};
int i;
const char *nam, *val, *cp = Jsi_DSValue(&pss->dHdrs);
for (i=0; i<pss->hdrNum; i+=2) {
int sz = pss->hdrSz[i], sz2 = pss->hdrSz[i+1];
Jsi_DSSetLength(&dStr, 0);
Jsi_DSSetLength(&vStr, 0);
nam = Jsi_DSAppendLen(&dStr, cp, sz);
cp += 1 + sz;
val = Jsi_DSAppendLen(&vStr, cp, sz2);
if (name) {
if (!Jsi_Strcmp(nam, name)) {
Jsi_ValueMakeStringDup(interp, ret, val);
break;
}
} else {
nv = Jsi_ValueNewStringDup(interp, val);
Jsi_ObjArraySet(interp, nobj, Jsi_ValueNewStringDup(interp, nam), i);
Jsi_ObjArraySet(interp, nobj, nv, i+1);
}
cp += (1 + sz2);
}
Jsi_DSFree(&dStr);
Jsi_DSFree(&vStr);
}
|
CWE-120
| null | 519,974 |
39395867450437325650856976775898048845
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC mdbEvalPrep(MyDbEvalContext *p) {
MysqlPrep *prep = p->prep;
Jsi_Interp *interp = p->jdb->interp;
Jsi_RC rc = JSI_OK;
if( p->prep==0 ) {
rc = mdbPrepareAndBind(p); //p->jdb, p->zSql, &p->zSql, &p->prep);
if( rc!=JSI_OK )
return rc;
prep = p->prep;
if (p->jdb->optPtr->prefetch) {
my_bool aBool = 1;
mysql_stmt_attr_set(prep->myStmt, STMT_ATTR_UPDATE_MAX_LENGTH, &aBool);
}
if (mysql_stmt_execute(prep->myStmt)) {
Jsi_Interp *interp = p->jdb->interp;
rc = Jsi_LogError("execute failed: %s", mysql_error(p->jdb->db));
}
if (p->jdb->optPtr->prefetch && mysql_stmt_store_result(prep->myStmt)) {
Jsi_LogWarn("prefetch failed, disabling: %s", mysql_error(p->jdb->db));
p->jdb->optPtr->prefetch = 0;
}
MYSQL_RES *res = mysql_stmt_result_metadata(prep->myStmt);
MYSQL_FIELD *field;
if (res) {
// Setup field mappings to/from Jsi.
prep->fieldResult = (SqlFieldResults*)Jsi_Calloc(res->field_count, sizeof(*prep->fieldResult));
prep->colNames = (char**)Jsi_Calloc(res->field_count, sizeof(char*));
prep->colTypes = (Jsi_OptionId*)Jsi_Calloc(res->field_count, sizeof(int));
int iCnt = 0;
while((field = mysql_fetch_field(res)))
{
assert(iCnt<prep->numCol);
SqlFieldResults *fres = prep->fieldResult+iCnt;
MYSQL_BIND *bindResult = prep->bindResult+iCnt;
bindResult->buffer = &fres->buffer.vchar;
fres->field = field;
prep->colNames[iCnt] = field->name;
switch (field->type) {
case MYSQL_TYPE_TINY:
case MYSQL_TYPE_BIT:
if (field->length == 1) {
fres->jsiTypeMap = JSI_OPTION_BOOL;
fres->mapType = MYSQL_TYPE_DOUBLE;
fres->vsize = 1;
break;
}
case MYSQL_TYPE_SHORT:
case MYSQL_TYPE_LONG:
case MYSQL_TYPE_DECIMAL:
fres->jsiTypeMap = JSI_OPTION_INT64;
fres->mapType = MYSQL_TYPE_LONG;
fres->vsize = sizeof(long long);
break;
case MYSQL_TYPE_LONGLONG:
fres->jsiTypeMap = JSI_OPTION_INT64;
fres->mapType = MYSQL_TYPE_LONGLONG;
fres->vsize = sizeof(long long);
break;
case MYSQL_TYPE_FLOAT:
case MYSQL_TYPE_DOUBLE:
fres->jsiTypeMap = JSI_OPTION_DOUBLE;
fres->mapType = MYSQL_TYPE_DOUBLE;
fres->vsize = sizeof(double);
break;
case MYSQL_TYPE_TIME:
case MYSQL_TYPE_DATE:
case MYSQL_TYPE_DATETIME:
case MYSQL_TYPE_TIMESTAMP:
fres->jsiTypeMap = JSI_OPTION_TIME_D; //TODO: time
fres->mapType = MYSQL_TYPE_DATETIME;
fres->vsize = sizeof(MYSQL_TIME);
break;
case MYSQL_TYPE_STRING:
default:
if (IS_NUM(field->type)) {
fres->mapType = MYSQL_TYPE_LONGLONG;
fres->jsiTypeMap = JSI_OPTION_DOUBLE;
fres->vsize = sizeof(double);
} else {
fres->jsiTypeMap = JSI_OPTION_STRING;
fres->mapType = MYSQL_TYPE_STRING;
if (p->jdb->optPtr->prefetch)
fres->vsize = field->max_length;
else
fres->vsize = p->jdb->optPtr->maxString;
if (fres->vsize <= 0)
fres->vsize = JSI_BUFSIZ;
bindResult->buffer = fres->buffer.vstring = (char*)Jsi_Malloc(fres->vsize);
fres->buffer.vstring[0] = 0;
}
break;
}
prep->colTypes[iCnt] = fres->jsiTypeMap;
bindResult->buffer_type = fres->mapType;
bindResult->buffer_length = fres->vsize;
bindResult->length = &fres->len;
bindResult->is_null = &fres->isnull;
iCnt++;
}
}
else return JSI_BREAK;
if (mysql_stmt_bind_result(prep->myStmt, prep->bindResult)) {
fprintf(stderr, "mysql_stmt_bind_Result(), failed. Error:%s\n", mysql_stmt_error(prep->myStmt));
return JSI_ERROR;
}
mysql_free_result(res);
}
return rc;
}
|
CWE-120
| null | 519,975 |
23463682346569909260183384572295683902
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
void Jsi_InterpFreeData(Jsi_Interp *interp, const char *key)
{
Jsi_HashEntry *hPtr;
hPtr = Jsi_HashEntryFind(interp->assocTbl, key);
if (!hPtr)
return;
Jsi_HashEntryDelete(hPtr);
}
|
CWE-120
| null | 519,976 |
91703321021812003582730423026593550427
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static int jsi_FSEofProc(Jsi_Channel chan) { return feof(_JSI_GETFP(chan,1));}
|
CWE-120
| null | 519,977 |
293401382102123840273372187403131363742
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_Value** jsi_ValuesAlloc(Jsi_Interp *interp, int cnt, Jsi_Value**old, int oldsz) {
int i;
Jsi_Value **v = (Jsi_Value **)Jsi_Realloc(old, cnt* sizeof(Jsi_Value*));
for (i=oldsz; i<cnt; i++)
v[i] = NULL;
return v;
}
|
CWE-120
| null | 519,978 |
16422006176030276705007925168782033055
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_MapEntry* Jsi_MapEntryNew (Jsi_Map *mapPtr, const void *key, bool *isNew){
SIGASSERT(mapPtr, MAP);
switch (mapPtr->typ) {
case JSI_MAP_HASH: return (Jsi_MapEntry*)Jsi_HashEntryNew(mapPtr->v.hash, key, isNew);
case JSI_MAP_TREE: return (Jsi_MapEntry*)Jsi_TreeEntryNew(mapPtr->v.tree, key, isNew);
case JSI_MAP_LIST: {
Jsi_ListEntry *lptr = Jsi_ListEntryNew(mapPtr->v.list, NULL, (key?mapPtr->v.list->head:NULL));
if (isNew) *isNew = 1;
return (Jsi_MapEntry*)lptr;
}
break;
case JSI_MAP_NONE: break;
}
return NULL;
}
|
CWE-120
| null | 519,979 |
203761964418831359281202554038075756319
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
void jsi_VALCHK(Jsi_Value *val) {
SIGASSERTV(val,VALUE);
assert(val->vt <= JSI_VT__MAX);
if (val->vt == JSI_VT_OBJECT)
OBJCHK(val->d.obj);
}
|
CWE-120
| null | 519,980 |
135869798998767468473760296764702447251
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static Jsi_RC jsi_wsEvalSSI(Jsi_Interp *interp, jsi_wsCmdObj *cmdPtr, Jsi_Value *fn, Jsi_DString *dStr,
int lvl, jsi_wsPss *pss) {
int flen, rlen;
char fbuf[PATH_MAX];
char *fs, *fname = Jsi_ValueString(interp, fn, &flen), *fend = fname;
if (lvl>10 || !fname || !pss)
return JSI_ERROR;
Jsi_Value *fval;
Jsi_RC rc = JSI_OK;
Jsi_DString tStr = {}, lStr = {};
const char *cs = NULL;
char *root = Jsi_ValueString(interp, cmdPtr->rootdir, &rlen);
if (!Jsi_Strncmp(root, fname, rlen))
fname = fname + rlen;
fs = Jsi_Strrchr(fname, '/');
if (fs) {
flen = fs-fname;
fend = fs+1;
}
if (lvl>0) {
rc = jsi_wsFileRead(interp, fn, &tStr, cmdPtr, pss);
cs = Jsi_DSValue(&tStr);
} else {
snprintf(fbuf, sizeof(fbuf), "%s/%.*s/%s", root, flen, fname, cmdPtr->includeFile);
fval = Jsi_ValueNewStringConst(interp, fbuf, -1);
Jsi_IncrRefCount(interp, fval);
rc = jsi_wsFileRead(interp, fval, &tStr, cmdPtr, pss);
if (rc == JSI_OK)
cs = Jsi_DSValue(&tStr);
Jsi_DecrRefCount(interp, fval);
}
char *cp, *sp, *se, pref[] = "<!--#", suffix[] = "-->", *msg = NULL;
struct {
int inif, inelse, matched, elide;
} II[11] = {};
const int maxNest = 10;
int ii = 0;
int plen = 5, elen, llen;
while (rc == JSI_OK && cs) {
char *ext = NULL, *sfname = fname;
int sflen = flen;
sp = Jsi_Strstr(cs, pref);
if (!sp || !(se=Jsi_Strstr(sp+plen, suffix))) {
Jsi_DSAppend(dStr, cs, NULL);
break;
}
sp += plen-1;
llen = se-sp;
Jsi_DSSetLength(&lStr, 0);
cp = Jsi_DSAppendLen(&lStr, sp, llen);
if (Jsi_Strchr(cp, '\n')) { rc = Jsi_LogError("unexpected newline in directive \"%.10s\"", cp); break; }
if (!II[ii].elide)
Jsi_DSAppendLen(dStr, cs, sp-cs-4);
if (!Jsi_Strncmp(cp, "#include file=\"", 12) || !Jsi_Strncmp(cp, "#include virtual=\"", 15)) {
if (cp[llen-1] != '"' || cp[llen-2] == '=') { msg = "missing end quote in"; break; }
if (!II[ii].elide) {
Jsi_DSSetLength(&lStr, llen-1);
int isvirt = (cp[9]=='v');
cp += (isvirt ? 18 : 15);
if (cp[0] == '$' && lvl == 0) { // substitute file suffix
char sfx[20] = {};
uint i;
for (i=0; i<sizeof(sfx); i++) {
if ((sfx[i] = cp[i+1]) == '"' || !sfx[i]) {
sfx[i] = 0;
break;
}
}
snprintf(fbuf, sizeof(fbuf), "%s/%.*s/%s/%s%s", root, flen, fname, sfx, fend, sfx);
} else {
snprintf(fbuf, sizeof(fbuf), "%s/%.*s/%s", root, sflen, sfname, cp);
ext = Jsi_Strrchr(fbuf, '.');
}
fval = Jsi_ValueNewStringConst(interp, fbuf, -1);
Jsi_IncrRefCount(interp, fval);
if (!ext || ext[0] != '.' || !jsi_wsIsSSIExt(interp, cmdPtr, pss, ext+1))
rc = jsi_wsFileRead(interp, fval, dStr, cmdPtr, pss);
else
rc = jsi_wsEvalSSI(interp, cmdPtr, fval, dStr, lvl+1, pss);
if (cmdPtr->noWarn)
rc = JSI_OK;
Jsi_DecrRefCount(interp, fval);
}
} else if (!Jsi_Strncmp(cp, "#echo \"${", 9)) {
if (cp[llen-1] != '"' || cp[llen-2] != '}') { msg = "missing end quote"; break; }
Jsi_DSSetLength(&lStr, llen-2);
cp += 9;
llen -= 9;
if (!Jsi_Strcmp(cp, "#")) {
if (!pss->key[0])
snprintf(pss->key, sizeof(pss->key), "%d%p%d", pss->wid, pss, (int)cmdPtr->startTime);
Jsi_DSPrintf(dStr, "'%s'", pss->key);
} else {
Jsi_Value *val = NULL;
if (!cmdPtr->udata) {
val = Jsi_ValueObjLookup(interp, cmdPtr->udata, cp, 0);
if (!val) { msg = "udata lookup failure"; break; }
cp = Jsi_ValueString(interp, val, NULL);
Jsi_DSPrintf(dStr, "'%s'", cp);
}
}
} else if (!Jsi_Strncmp(cp, "#if expr=\"", 10) || !Jsi_Strncmp(cp, "#elif expr=\"", 12)) {
if (llen<11 || cp[llen-1] != '"' || cp[llen-2] == '=') { msg = "missing end quote"; break; }
Jsi_DSSetLength(&lStr, llen-1);
bool iselif = (cp[1]=='e');
cp += (iselif?12:10);
if (!iselif) {
if (II[ii].inif) {
if ((ii+1)>=maxNest) { msg = "nested \"#if\" too deep"; break; }
ii++;
II[ii] = II[maxNest];
II[ii].elide = II[ii-1].elide;
}
II[ii].inif = 1;
} else {
if (!II[ii].inif) { msg = "unexpected \"#elif\""; break; }
}
elen = Jsi_Strlen(cp);
if (elen<4|| cp[0] != '$' || cp[1] != '{' || cp[elen-1] != '}') {
msg = "expr must be of form ${X}"; break;
}
Jsi_DSSetLength(&lStr, llen-2);
cp += 2;
// Extract modifiers before bool var name to lookup.
bool warn = 0, req = 0, nifval = 0, not = 0, isq=0, isu=0, qfirst=0;
while (*cp && !isalpha(*cp)) {
bool fail = 0;
switch (*cp) {
case '~': qfirst = 1; break;
case ':': isu = 1; break;
case '?': isq = 1; break;
case '@': warn = !II[ii].matched; break;
case '*': req = !II[ii].matched; break;
case '!': not = 1; break;
default: fail=1; break;
}
if (fail) { msg = "modifier must be one of: !:=?@*"; break; }
cp++;
}
Jsi_Value *val = NULL;
if (!val && qfirst && pss->queryObj)
val = Jsi_ValueObjLookup(interp, pss->queryObj, cp, 0);
if (!val && !isq && cmdPtr->udata)
val = Jsi_ValueObjLookup(interp, cmdPtr->udata, cp, 0);
if (!val && !qfirst && !isu && pss->queryObj)
val = Jsi_ValueObjLookup(interp, pss->queryObj, cp, 0);
if (!val) {
if (req) { msg = "symbol not found"; break; }
if (warn) Jsi_LogWarn("symbol \"%s\" not found: %s", cp, fbuf);
} else if (Jsi_ValueGetBoolean(interp, val, &nifval) != JSI_OK) {
const char *valStr = NULL;
if (val) valStr = Jsi_ValueString(interp, val, NULL);
if (!valStr || Jsi_GetBool(interp, valStr, &nifval) != JSI_OK) {
if (!warn) { msg = "symbol not a boolean"; break; }
Jsi_LogWarn("symbol \"%s\" should be a boolean: %s", cp, fbuf);
}
}
if (not) nifval = !nifval;
if (!iselif) {
if (nifval)
II[ii].matched = 1;
else
II[ii].elide = 1;
} else {
if (II[ii].matched || !nifval)
II[ii].elide = 1;
else if (nifval) {
II[ii].matched = 1;
II[ii].elide = (ii?II[ii-1].elide:0);
}
}
} else if (!Jsi_Strncmp(cp, "#else", 5)) {
if (!II[ii].inif || II[ii].inelse) { msg = "unexpected \"#else\""; break; }
II[ii].inelse = 1;
II[ii].elide = (ii&&II[ii-1].elide?1:II[ii].matched);
} else if (!Jsi_Strncmp(cp, "#endif", 6)) {
if (!II[ii].inif) { msg = "unexpected \"#endif\""; break; }
II[ii].inelse = II[ii].inif = II[ii].elide = II[ii].matched = 0;
if (ii>0)
ii--;
} else {
msg = "expected directive #include/#if/#elif/#else/#endif";
break;
}
cs = se + 3;
if (*cs == '\n')
cs++;
}
if (rc == JSI_OK && II[ii].inif && !msg) {
msg = "missing \"#endif\"";
sp = "";
}
if (msg) {
while (*fname=='/') fname++;
rc = Jsi_LogError("SHTML Error in \"%s\": %s: at \"%.40s\" ", fname, msg, sp);
}
Jsi_DSFree(&tStr);
Jsi_DSFree(&lStr);
return rc;
}
|
CWE-120
| null | 519,981 |
301873126489962597935108176183282593936
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_RC jsi_JsPreprocessLineCB(Jsi_Interp* interp, char *buf, size_t bsiz, uint ilen, int jOpts[4], int lineNo) {
const char *jpp = interp->jsppChars;
if (!jpp[0] || !jpp[1])
return JSI_OK;
if (buf[0] && jpp[0] == buf[0] && ilen>2 && buf[ilen-2]==jpp[1]) {
Jsi_DString dStr = {};
buf[ilen-2] = 0; // Remove last char and newline.
Jsi_Value *inStr = Jsi_ValueNewStringDup(interp, buf+1);
Jsi_IncrRefCount(interp, inStr);
Jsi_RC rc = Jsi_FunctionInvokeString(interp, interp->jsppCallback, 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_DSAppendLen(&dStr, "\n", 1);
Jsi_Strncpy(buf, Jsi_DSValue(&dStr), bsiz);
buf[bsiz-1] = 0;
Jsi_DSFree(&dStr);
}
return JSI_OK;
}
|
CWE-120
| null | 519,982 |
28154966928033492691521849055921980961
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_RC Jsi_MapKeysDump(Jsi_Interp *interp, Jsi_Map *mapPtr, Jsi_Value **ret, int flags){
SIGASSERT(mapPtr, MAP);
switch (mapPtr->typ) {
case JSI_MAP_HASH: return Jsi_HashKeysDump(interp, mapPtr->v.hash, ret, flags);
case JSI_MAP_TREE: return Jsi_TreeKeysDump(interp, mapPtr->v.tree, ret, flags);
case JSI_MAP_LIST: break; // TODO: dump numbers?
case JSI_MAP_NONE: break;
}
return JSI_ERROR;
}
|
CWE-120
| null | 519,983 |
138260980075690293313870172956496570252
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
static int jsi_cmpstringp(const void *p1, const void *p2)
{
return Jsi_Strcmp(* (char * const *) p1, * (char * const *) p2);
}
|
CWE-120
| null | 519,984 |
35541938787218790752914331221249364297
| null | null |
other
|
jsish
|
430ea27accd4d4ffddc946c9402e7c9064835a18
| 0 |
Jsi_RC Jsi_SqlObjBinds(Jsi_Interp* interp, Jsi_DString* zStr, const char *varName, bool addTypes, bool addDefaults, bool nullDefaults) {
Jsi_Value *v, *vnPtr = Jsi_VarLookup(interp, varName);
if (!vnPtr || !Jsi_ValueIsObjType(interp, vnPtr, JSI_OT_OBJECT))
return Jsi_LogError("varName must be an Object: %s", varName);
char *cp, *zSql = Jsi_DSValue(zStr);
int create = !Jsi_Strncasecmp(zSql,"create",6);
int insert = !Jsi_Strncasecmp(zSql,"insert",6);
if (!create && !insert) return JSI_OK;
const char *cPtr = Jsi_Strstr(zSql, " %s");
if (!cPtr) cPtr = Jsi_Strstr(zSql, "\t%s");
if (!cPtr)
return Jsi_LogError("Object varName must contain a ' %%s': %s", varName);
Jsi_DString sStr = {}, vStr = {}, jStr = {};
Jsi_DSAppendLen(&sStr, zSql, cPtr?(cPtr-zSql):-1);
Jsi_DSAppend(&sStr, " (", NULL);
Jsi_IterObj *io = Jsi_IterObjNew(interp, NULL);
Jsi_IterGetKeys(interp, vnPtr, io, 0);
uint i;
const char *pre = "", *kstr;
if (!create)
Jsi_DSAppend(&vStr, " VALUES(", NULL);
for (i=0; i<io->count; i++) {
kstr = io->keys[i];
const char *qs = "", *qe = "";
if (!Jsi_StrIsAlnum(kstr) || Jsi_IsReserved(interp, kstr, 1)) {
qe = qs = "'";
}
Jsi_DSAppend(&sStr, pre, qs, kstr, qe, NULL);
if (create) {
const char *typ = NULL, *dflt=(nullDefaults?"NULL":NULL);
if (addTypes && ((v = Jsi_ValueObjLookup(interp, vnPtr, kstr, 1)))) {
if (Jsi_ValueIsBoolean(interp, v)) {
typ = "BOOLEAN";
if (!nullDefaults && addDefaults) {
bool bv = 0;
Jsi_ValueGetBoolean(interp, v, &bv);
dflt = (bv?"1":"0");
}
} else if (Jsi_ValueIsNumber(interp, v)) {
typ = "NUMERIC";
if (!Jsi_Strcmp(kstr,"rowid"))
typ = "INTEGER PRIMARY KEY";
else if (!nullDefaults && addDefaults) {
Jsi_Number nv = 0;
Jsi_DSFree(&jStr);
Jsi_ValueGetNumber(interp, v, &nv);
dflt = Jsi_DSPrintf(&jStr, "%" JSI_NUMGFMT, nv);
}
} else if (Jsi_ValueIsArray(interp, v) || Jsi_ValueIsObjType(interp, v, JSI_OT_OBJECT)) {
typ = "CHARJSON";
if (!nullDefaults && addDefaults) {
Jsi_DSFree(&jStr);
Jsi_DSAppend(&jStr, "'", NULL);
Jsi_ValueGetDString(interp, v, &jStr, JSI_OUTPUT_JSON|JSI_JSON_STRICT);
Jsi_DSAppend(&jStr, "'", NULL);
dflt = Jsi_DSValue(&jStr);
}
} else {
typ = "TEXT";
if (!nullDefaults && addDefaults) {
if ((cp=Jsi_ValueString(interp, v, NULL))) {
Jsi_DSFree(&jStr);
dflt = Jsi_DSAppend(&jStr, "'", cp, "'", NULL);
} else
dflt = "NULL";
}
}
}
if (typ)
Jsi_DSAppend(&sStr, " ", typ, (dflt?" DEFAULT ":""), dflt, NULL);
} else {
Jsi_DSAppend(&vStr, pre, "$", varName, "(", kstr, ")", NULL);
}
pre = ",";
}
if (!create)
Jsi_DSAppend(&vStr, ")", NULL);
Jsi_IterObjFree(io);
Jsi_DSAppend(&sStr, ") ", Jsi_DSValue(&vStr), cPtr+3, NULL);
Jsi_DSFree(zStr);
Jsi_DSAppend(zStr, Jsi_DSValue(&sStr), NULL);
Jsi_DSFree(&sStr); Jsi_DSFree(&vStr); Jsi_DSFree(&jStr);
return JSI_OK;
}
|
CWE-120
| null | 519,985 |
226492744650542142107261624736482213448
| null | null |
other
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.