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
bool Jsi_ValueIsStringKey(Jsi_Interp* interp, Jsi_Value *key) { if (key->vt == JSI_VT_STRING && key->f.bits.isstrkey) return 1; if (key->vt == JSI_VT_OBJECT && key->d.obj->ot == JSI_OT_STRING && key->d.obj->isstrkey) return 1; return 0; }
CWE-120
null
520,386
271663927345392349671668729818945073521
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static int jsi_FSAccessProc(Jsi_Interp *interp, Jsi_Value* path, int mode) { const char *pathPtr = Jsi_ValueToString(interp, path, NULL); Jsi_DString dStr = {}; if (*pathPtr == '~') pathPtr = jsi_TildePath(interp, pathPtr, &dStr); int rc = access(pathPtr, mode); Jsi_DSFree(&dStr); return rc; }
CWE-120
null
520,387
242605698010064399867000196862772810861
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static Jsi_OpCodes *code_div() { JSI_NEW_CODES(0,OP_DIV, 0); }
CWE-120
null
520,388
120386362593128020283562840675246134899
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
Jsi_RC jsi_FunctionSubCall(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this, Jsi_Value **ret, Jsi_Value *tocall, int discard) { Jsi_RC rc = JSI_OK; const char *oldCurFunc = interp->curFunction, *spnam = ""; jsi_OpCode *ip = interp->curIp; int adds, as_constructor = (ip->op == OP_NEWFCALL); double timStart = 0; int docall; int calltrc = 0, profile = interp->profile, coverage = interp->coverage; jsi_PkgInfo *pkg; int tc; //char *lpv = interp->lastPushStr; if (tocall->vt == JSI_VT_UNDEF && tocall->f.bits.lookupfailed && tocall->d.lookupFail && !interp->noAutoLoad) { spnam = tocall->d.lookupFail; tocall->f.bits.lookupfailed = 0; tocall = jsi_LoadFunction(interp, spnam, tocall); interp->lastPushStr = (char*)spnam; interp->curIp = ip; } if (!Jsi_ValueIsFunction(interp, tocall)) { // if (tocall->f.bits.subscriptfailed && tocall->d.lookupFail) // spnam = tocall->d.lookupFail; jsi_DumpFunctions(interp, spnam); rc = JSI_ERROR; goto empty_func; } if (tocall->d.obj->d.fobj==NULL || tocall->d.obj->d.fobj->func==NULL) { /* empty function */ empty_func: //jsiPop(interp, stackargc); //jsiClearStack(interp,1); //Jsi_ValueMakeUndef(interp, &_jsi_TOP); interp->curFunction = oldCurFunc; Jsi_DecrRefCount(interp, _this); if (rc==JSI_OK) rc = JSI_CONTINUE; return rc; //goto done; } Jsi_FuncObj *fobj = tocall->d.obj->d.fobj; Jsi_Func *funcPtr = fobj->func; if (funcPtr->callback == jsi_NoOpCmd || tocall->d.obj->isNoOp) { jsi_NoOpCmd(interp, NULL, NULL, NULL, NULL); goto empty_func; } if (!interp->asserts && funcPtr->callback == jsi_AssertCmd) goto empty_func; const char *onam = funcPtr->name; // if (!onam) // Override blank name with last index. // funcPtr->name = lpv; if (funcPtr->name && funcPtr->name[0] && funcPtr->type == FC_NORMAL) interp->curFunction = funcPtr->name; adds = funcPtr->callflags.bits.addargs; Jsi_CmdSpec *cs = funcPtr->cmdSpec; if (adds && (cs->flags&JSI_CMDSPEC_NONTHIS)) adds = 0; Jsi_Func *pprevActive = interp->prevActiveFunc, *prevActive = interp->prevActiveFunc = interp->activeFunc; interp->activeFunc = funcPtr; rc = jsi_SharedArgs(interp, args, funcPtr, 1); /* make arg vars to share arguments */ if (rc != JSI_OK) goto bail; funcPtr->callflags.bits.addargs = 0; jsi_InitLocalVar(interp, args, funcPtr); jsi_SetCallee(interp, args, tocall); pkg = funcPtr->pkg; tc = interp->traceCall; if (pkg) { tc |= pkg->popts.modConf.traceCall; profile |= pkg->popts.modConf.profile; coverage |= pkg->popts.modConf.coverage; } if (as_constructor) { /* new Constructor */ Jsi_Obj *newobj = Jsi_ObjNewType(interp, JSI_OT_OBJECT); Jsi_Value *proto = NULL; if (!interp->subOpts.noproto) proto = Jsi_ValueObjLookup(interp, tocall, "prototype", 0); if (proto && proto->vt == JSI_VT_OBJECT) { newobj->__proto__ = proto; newobj->clearProto = 1; Jsi_IncrRefCount(interp, proto); } Jsi_ValueReset(interp, &_this); Jsi_ValueMakeObject(interp, &_this, newobj); /* TODO: constructor specifics??? */ calltrc = (tc&jsi_callTraceNew); } if (funcPtr->type == FC_NORMAL) calltrc = (tc&jsi_callTraceFuncs); else calltrc = (tc&jsi_callTraceCmds); if (calltrc && funcPtr->name) jsi_TraceFuncCall(interp, funcPtr, ip, _this, args, 0, tc); //Jsi_Value *spretPtr = *ret; interp->activeFunc = funcPtr; docall = (rc==JSI_OK); if (profile || coverage) { interp->profileCnt++; timStart = jsi_GetTimestamp(); } if (funcPtr->type == FC_NORMAL) { if (docall) { rc = jsi_evalcode(interp->ps, funcPtr, funcPtr->opcodes, tocall->d.obj->d.fobj->scope, args, _this, ret); } interp->funcCallCnt++; } else if (!funcPtr->callback) { Jsi_LogError("can not call:\"%s()\"", funcPtr->name); } else { int oldcf = funcPtr->callflags.i; funcPtr->callflags.bits.iscons = (as_constructor?JSI_CALL_CONSTRUCTOR:0); if (funcPtr->f.bits.hasattr) { #define SPTR(s) (s?s:"") if ((funcPtr->f.bits.isobj) && _this->vt != JSI_VT_OBJECT) { rc = JSI_ERROR; docall = 0; Jsi_LogError("'this' is not object: \"%s()\"", funcPtr->name); } else if ((!(funcPtr->f.bits.iscons)) && as_constructor) { rc = JSI_ERROR; docall = 0; Jsi_LogError("can not call as constructor: \"%s()\"", funcPtr->name); } else { int aCnt = Jsi_ValueGetLength(interp, args); if (aCnt<(cs->minArgs+adds)) { Jsi_LogError("missing args, expected \"%s(%s)\" ", cs->name, SPTR(cs->argStr)); rc = JSI_ERROR; docall = 0; } else if (cs->maxArgs>=0 && (aCnt>cs->maxArgs+adds)) { Jsi_LogError("extra args, expected \"%s(%s)\" ", cs->name, SPTR(cs->argStr)); rc = JSI_ERROR; docall = 0; } } } if (docall) { funcPtr->fobj = fobj; // Backlink for bind. funcPtr->callflags.bits.isdiscard = discard; rc = funcPtr->callback(interp, args, _this, ret, funcPtr); interp->cmdCallCnt++; } funcPtr->callflags.i = oldcf; } if (profile || coverage) { double timEnd = jsi_GetTimestamp(), timUsed = (timEnd - timStart);; assert(timUsed>=0); funcPtr->allTime += timUsed; if (interp->framePtr->evalFuncPtr) interp->framePtr->evalFuncPtr->subTime += timUsed; else interp->subTime += timUsed; } if (calltrc && (tc&jsi_callTraceReturn) && funcPtr->name) jsi_TraceFuncCall(interp, funcPtr, ip, _this, NULL, *ret, tc); if (!onam) funcPtr->name = NULL; if (docall) { funcPtr->callCnt++; if (rc == JSI_OK && !as_constructor && funcPtr->retType && (interp->typeCheck.all || interp->typeCheck.run)) rc = jsi_ArgTypeCheck(interp, funcPtr->retType, *ret, "returned from", funcPtr->name, 0, funcPtr, 0); } interp->prevActiveFunc = pprevActive; interp->activeFunc = prevActive; if (as_constructor) { if (_this->vt == JSI_VT_OBJECT) _this->d.obj->constructor = tocall->d.obj; if ((*ret)->vt != JSI_VT_OBJECT) { Jsi_ValueReset(interp, ret); Jsi_ValueCopy(interp, *ret, _this); } } bail: jsi_SharedArgs(interp, args, funcPtr, 0); /* make arg vars to shared arguments */ Jsi_DecrRefCount(interp, _this); interp->curFunction = oldCurFunc; return rc; }
CWE-120
null
520,389
291330770776927321184068828291174379529
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static int dbGetIntBool(Jsi_Interp *interp, Jsi_Value* v) { if (Jsi_ValueIsNumber(interp, v)) { Jsi_Number d; Jsi_ValueGetNumber(interp, v, &d); return (int)d; } if (Jsi_ValueIsBoolean(interp, v)) { bool n; Jsi_ValueGetBoolean(interp, v, &n); return n; } return 0; }
CWE-120
null
520,390
99171571368034128426614955117337920932
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static int JsiNumberBase(const char *str, int *base, int *sign) { int i = 0; *base = 10; while (isspace(UCHAR(str[i]))) { i++; } if (str[i] == '-') { *sign = -1; i++; } else { if (str[i] == '+') { i++; } *sign = 1; } if (str[i] != '0') { /* base 10 */ return 0; } /* We have 0<x>, so see if we can convert it */ switch (str[i + 1]) { case 'x': case 'X': *base = 16; break; case 'o': case 'O': *base = 8; break; case 'b': case 'B': *base = 2; break; default: return 0; } i += 2; /* Ensure that (e.g.) 0x-5 fails to parse */ if (str[i] != '-' && str[i] != '+' && !isspace(UCHAR(str[i]))) { /* Parse according to this base */ return i; } /* Parse as base 10 */ return 10; }
CWE-120
null
520,391
237971962618621717368261678897705538454
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
char jsi_toHexChar(char code) { static char hex[] = "0123456789abcdef"; return hex[code & 15]; }
CWE-120
null
520,392
244301667511193331514807703386004152252
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
int jsi_PstateSetFile(jsi_Pstate *ps, Jsi_Channel fp, int skipbang) { jsi_Lexer *l = ps->lexer; jsi_PstateClear(ps); l->ltype = LT_FILE; l->d.fp = fp; Jsi_Rewind(ps->interp, fp); if (skipbang) { char buf[JSI_BUFSIZ]; if (Jsi_Gets(ps->interp, fp, buf, sizeof(buf)) && (buf[0] != '#' || buf[1] != '!')) { Jsi_Rewind(ps->interp, fp); } } return JSI_OK; }
CWE-120
null
520,393
101563267374302319539606651984990015792
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
void jsi_PstateClear(jsi_Pstate *ps) { jsi_Lexer* l = ps->lexer; if (l->ltype == LT_FILE) { if (l->d.fp) Jsi_Close(ps->interp, l->d.fp); l->d.fp = NULL; } if (l->ltype == LT_STRING) { l->d.str = NULL; } l->ltype = LT_NONE; l->last_token = 0; l->cur_line = 1; l->cur_char = 0; l->cur = 0; ps->err_count = 0; }
CWE-120
null
520,394
174047574126553122791355584732640286170
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
void *Jsi_StackPeek(Jsi_Stack *stack) { if (stack->len == 0) return NULL; return stack->vector[stack->len - 1]; }
CWE-120
null
520,395
80940054206804501976980998706550466036
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
Jsi_RC Jsi_FunctionInvokeJSON(Jsi_Interp *interp, Jsi_Value *func, const char *json, Jsi_Value **ret) { if (!Jsi_ValueIsFunction(interp, func)) return JSI_ERROR; Jsi_Value *aPtr = Jsi_ValueNew1(interp); Jsi_RC rc = Jsi_JSONParse(interp, json, &aPtr, 0); if (rc == JSI_OK) rc = Jsi_FunctionInvoke(interp, func, aPtr, ret, NULL); Jsi_DecrRefCount(interp, aPtr); return rc; }
CWE-120
null
520,396
7721754090051145224617163169191198486
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static int jsi_wsServeString(jsi_wsPss *pss, struct lws *wsi, const char *buf, int code, const char *extra, const char *mime) { int strLen = Jsi_Strlen(buf); Jsi_DString jStr = {}; int rc = jsi_wsServeHeader(pss, wsi, strLen, code, extra, mime, &jStr); if (rc>=0) { Jsi_DSAppend(&jStr, buf, NULL); char *vStr = Jsi_DSValue(&jStr); int vLen = Jsi_DSLength(&jStr); rc = jsi_wswrite(pss, wsi, (unsigned char*)vStr, vLen, LWS_WRITE_HTTP); } Jsi_DSFree(&jStr); return (rc>=0?1:0); }
CWE-120
null
520,397
30340518288766437892640417183475550699
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
Jsi_Regex* Jsi_RegExpNew(Jsi_Interp *interp, const char *regtxt, int eflag) { bool isNew; Jsi_HashEntry *hPtr; int flag = REG_EXTENDED; char c, *cm, *ce; const char *cp; Jsi_Regex *re; if (interp->subOpts.noRegex) { Jsi_LogError("regex disabled for interp"); return NULL; } eflag |= JSI_REG_STATIC; if (!regtxt[0]) return NULL; hPtr = Jsi_HashEntryFind(interp->regexpTbl, regtxt); if (hPtr) { re = (Jsi_Regex*)Jsi_HashValueGet(hPtr); if (JSI_REG_STATIC & eflag) re->eflags |= JSI_REG_STATIC; return re; } cp = regtxt+1; if (regtxt[0] != '/') return NULL; ce = (char*)Jsi_Strrchr(cp, '/'); if (ce == cp || !ce) return NULL; cm = ce + 1; while (*cm) { c = *cm++; if (c == 'i') flag |= REG_ICASE; else if (c == 'g') eflag |= JSI_REG_GLOB; else if (c == 'm') { /* PERL NON-STANDARD */ eflag |= JSI_REG_NEWLINE; flag |= REG_NEWLINE; } #ifdef RE_DOT_NEWLINE else if (c == 's') { /* PERL NON-STANDARD */ eflag |= JSI_REG_DOT_NEWLINE; flag |= RE_DOT_NEWLINE; } #endif } *ce = 0; regex_t reg; if (regcomp(&reg, cp, flag)) { *ce++ = '/'; Jsi_LogError("Invalid regex string '%s'", cp); return NULL; } *ce++ = '/'; re = (Jsi_Regex*)Jsi_Calloc(1, sizeof(Jsi_Regex)); SIGINIT(re, REGEXP); assert (re); re->reg = reg; re->eflags = eflag; re->flags = flag; hPtr = Jsi_HashEntryNew(interp->regexpTbl, regtxt, &isNew); assert(hPtr); Jsi_HashValueSet(hPtr, re); re->pattern = (char*)Jsi_HashKeyGet(hPtr); return re; }
CWE-120
null
520,398
5164247727797755485462307610828441591
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
Jsi_Value *Jsi_ValueNew(Jsi_Interp *interp) { return ValueNew(interp); }
CWE-120
null
520,399
159307526733027346217977565808807702965
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
void Jsi_ValueFromDS(Jsi_Interp *interp, Jsi_DString *dsPtr, Jsi_Value **ret) { char *cp = NULL; int len = Jsi_DSLength(dsPtr); if (len && !(cp=(char*)dsPtr->strA)) cp = Jsi_StrdupLen(dsPtr->Str, len); dsPtr->strA = NULL; dsPtr->Str[0] = 0; dsPtr->len = 0; dsPtr->spaceAvl = dsPtr->staticSize; if (!cp) Jsi_ValueMakeStringDup(interp, ret, ""); else Jsi_ValueMakeBlob(interp, ret, (uchar*)cp, len); }
CWE-120
null
520,400
283820602066896549715760012545914490472
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static bool sqliteObjIsTrue(void *data) { Jsi_Db *db = (Jsi_Db*)data; SQLSIGASSERT(db,DB); if (!db->db) return 0; else return 1; }
CWE-120
null
520,401
171916121113027051770911937087431610891
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static void insert_case1(Jsi_TreeEntry* n) { if (n->parent == NULL) set_color(n, _JSI_TREE_BLACK); else insert_case2(n); }
CWE-120
null
520,402
300855107041223828428222662287494351297
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
Jsi_Filesystem* Jsi_FilesystemForPath(Jsi_Interp *interp, Jsi_Value* path, void**clientDataPtr) { FSList *fsl = jsiFSList; if (!fsl) return NULL; clientDataPtr = NULL; const char *pathStr = Jsi_ValueToString(interp, path, NULL); if (!pathStr || pathStr[0] == '~') return &jsiFilesystem; if (pathStr[0] == '.' && pathStr[1] == 0) return (jsiIntData.cwdFsPtr ? jsiIntData.cwdFsPtr : &jsiFilesystem); Jsi_Value *tpath = NULL; if (Jsi_Strstr(pathStr, "..")) { Jsi_DString dStr; Jsi_DSInit(&dStr); pathStr = Jsi_ValueNormalPath(interp, path, &dStr); tpath = path = Jsi_ValueNewStringDup(interp, pathStr); Jsi_IncrRefCount(interp, tpath); Jsi_DSFree(&dStr); } while (1) { if (fsl->fsPtr->pathInFilesystemProc && fsl->fsPtr->pathInFilesystemProc(interp, path, clientDataPtr)) break; if (!fsl->next) break; fsl = fsl->next; } if (tpath) Jsi_DecrRefCount(interp, tpath); return (fsl ? fsl->fsPtr : &jsiFilesystem); }
CWE-120
null
520,403
141355714234661555332727169364736473908
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
Jsi_TreeEntry *Jsi_TreeSearchFirst (Jsi_Tree *treePtr, Jsi_TreeSearch *searchPtr, int flags, const void *startKey) { Jsi_TreeEntry *hPtr = NULL, *hPtr2 = NULL; if (!treePtr) return NULL; memset(searchPtr, 0, sizeof(*searchPtr)); searchPtr->treePtr = treePtr; searchPtr->flags = flags; searchPtr->Ptrs = searchPtr->staticPtrs; searchPtr->max = sizeof(searchPtr->staticPtrs)/sizeof(searchPtr->staticPtrs[0]); searchPtr->epoch = treePtr->epoch; if (startKey || (flags & JSI_TREE_SEARCH_KEY)) hPtr2 = Jsi_TreeEntryFind(treePtr, startKey);; searchPtr->current = treePtr->root; hPtr = searchAdd(searchPtr, treePtr->root); if (hPtr2 && hPtr && hPtr2 != hPtr) while (hPtr && hPtr2 != hPtr) // TODO: need a more efficient way to do this... hPtr = Jsi_TreeSearchNext(searchPtr); return hPtr; }
CWE-120
null
520,404
290350906990324337279217938938754787286
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
uint Jsi_TreeSize(Jsi_Tree *treePtr) { return treePtr->numEntries; }
CWE-120
null
520,405
130323525538582937378329995212124188868
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
Jsi_Value *jsi_MakeFuncValueSpec(Jsi_Interp *interp, Jsi_CmdSpec *cmdSpec, void *privData) { Jsi_Obj *o = Jsi_ObjNew(interp); Jsi_Func *f = jsi_FuncNew(interp); o->ot = JSI_OT_FUNCTION; f->type = FC_BUILDIN; f->cmdSpec = cmdSpec; f->callback = cmdSpec->proc; f->privData = privData; f->f.flags = (cmdSpec->flags & JSI_CMD_MASK); f->script = interp->curFile; o->d.fobj = jsi_FuncObjNew(interp, f); return Jsi_ValueMakeObject(interp, NULL, o); }
CWE-120
null
520,406
30645246473369639348313061816097352515
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
void Jsi_InterpOnDelete(Jsi_Interp *interp, Jsi_DeleteProc *freeProc, void *ptr) { if (freeProc) Jsi_HashSet(interp->onDeleteTbl, ptr, (void*)freeProc); else { Jsi_HashEntry *hPtr = Jsi_HashEntryFind(interp->onDeleteTbl, ptr); if (hPtr) Jsi_HashEntryDelete(hPtr); } }
CWE-120
null
520,407
248292120447726276568341517945073590500
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static int node_color(Jsi_TreeEntry* n) { return n == NULL ? _JSI_TREE_BLACK : n->f.bits.color; }
CWE-120
null
520,408
189650859932527027790288224078639874292
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static Jsi_OpCodes *code_newfcall(jsi_Pstate *p, jsi_Pline *line, int argc, const char *name, Jsi_OpCodes *argCodes) { jsi_FuncCallCheck(p,line,argc,1, name, NULL, argCodes); JSI_NEW_CODESLN(0,OP_NEWFCALL, argc); }
CWE-120
null
520,409
83534608789065999017242979080299346090
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
int Jsi_Read(Jsi_Interp *interp, Jsi_Channel chan, char *bufPtr, int toRead) { if (chan->fsPtr==0 || !chan->fsPtr->readProc) return -1; return chan->fsPtr->readProc(chan, bufPtr, toRead); }
CWE-120
null
520,410
28889174424187845309087267178419860810
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
char* Jsi_ValueNormalPath(Jsi_Interp *interp, Jsi_Value *file, Jsi_DString *dStr) { return Jsi_NormalPath(interp, Jsi_ValueString(interp, file, NULL), dStr); }
CWE-120
null
520,411
22139223897691754475463640957293642883
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static void dbDeleteCmd(Jsi_Db *jdb) { Jsi_Interp *interp = jdb->interp; if (jdb->debug & TMODE_DELETE) JSI_DBQUERY_PRINTF( "DEBUG: delete\n"); dbFlushStmtCache(jdb); if (jdb->stmtHash) Jsi_HashDelete(jdb->stmtHash); //closeIncrblobChannels(jdb); if (jdb->db) { DbClose(jdb->db); } while( jdb->pFunc ) { SqlFunc *pFunc = jdb->pFunc; jdb->pFunc = pFunc->pNext; Jsi_DSFree(&pFunc->dScript); Jsi_DecrRefCount(interp, pFunc->tocall); Jsi_Free((char*)pFunc); } while( jdb->pCollate ) { SqlCollate *pCollate = jdb->pCollate; jdb->pCollate = pCollate->pNext; Jsi_Free((char*)pCollate); } Jsi_OptionsFree(interp, SqlOptions, jdb, 0); if (jdb->stmtCache) Jsi_ListDelete(jdb->stmtCache); }
CWE-120
null
520,412
75873799250912560342914592307600521667
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static bool fileObjEqual(void *data1, void *data2) { return (data1 == data2); }
CWE-120
null
520,413
192252443926629624567006772650496042335
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
Jsi_ListEntry* Jsi_ListSearchNext (Jsi_ListSearch *searchPtr) { Jsi_ListEntry *lptr = searchPtr->nextEntryPtr; searchPtr->nextEntryPtr = (lptr?(searchPtr->flags & JSI_LIST_REVERSE ? Jsi_ListEntryPrev(lptr): Jsi_ListEntryNext(lptr)):NULL); return lptr; }
CWE-120
null
520,414
87545385372670016398384748102494554204
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
char * Jsi_Gets(Jsi_Interp *interp, Jsi_Channel chan, char *s, int size) { if (chan->fsPtr==0 || !chan->fsPtr->getsProc) return NULL; return chan->fsPtr->getsProc(chan, s, size); }
CWE-120
null
520,415
6245601230766112096656845517303155634
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static Jsi_RC StringMapCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this, Jsi_Value **ret, Jsi_Func *funcPtr) { /* Now handles perl regex flag extensions.*/ const char *source_str; const char *replace_str = NULL; uint i, j; int slen, source_len, replace_len, bLen; const char *p; bool nocase = 0; /* Is a generic String.replace if _this->d.obj is a function */ ChkString(_this, funcPtr, source_str, &source_len, &bLen); int argc = Jsi_ValueGetLength(interp, args); Jsi_Value *repVal = Jsi_ValueArrayIndex(interp, args, skip); if (Jsi_ValueIsArray(interp, repVal)==0 || repVal->d.obj->arrCnt&1) return Jsi_LogError("expected even length array"); if (argc>(skip+1) && Jsi_ValueGetBoolean(interp, Jsi_ValueArrayIndex(interp, args, skip+1), &nocase) != JSI_OK) return Jsi_LogError("expected boolean"); Jsi_DString dStr; Jsi_DSInit(&dStr); Jsi_Obj *obj = repVal->d.obj; p = source_str; for (j=0; j<(uint)bLen; j++, p++) { for (i=0; i<obj->arrCnt; i+=2) { if (!obj->arr[i]) continue; if (!obj->arr[i+1]) continue; const char *cp = Jsi_ValueToString(interp, obj->arr[i], &slen); if (!cp || !slen) { Jsi_DSFree(&dStr); return Jsi_LogError("map src can not be empty"); } int res = (nocase ? Jsi_Strncasecmp(cp, p, slen) : Jsi_Strncmp(cp, p, slen)); if (!res) { replace_str = Jsi_ValueToString(interp, obj->arr[i+1], &replace_len); Jsi_DSAppendLen(&dStr, replace_str, replace_len); p += slen-1; j += slen-1; break; } } if (i>=obj->arrCnt) Jsi_DSAppendLen(&dStr, p, 1); } Jsi_ValueFromDS(interp, &dStr, ret); return JSI_OK; }
CWE-120
null
520,416
223084321899700182473026819330259082220
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
jsi_ws_http_redirect(struct lws *wsi, int code, Jsi_DString *tStr, unsigned char **p, unsigned char *end) { char *loc = Jsi_DSValue(tStr); uchar *start = *p; char* cookie = Jsi_Strchr(loc, '|'); if (cookie) { *cookie= 0; cookie++; } if (lws_add_http_header_status(wsi, code, p, end) || lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_LOCATION, (uchar *)loc, Jsi_Strlen(loc), p, end) || lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE,(uchar *)"text/html", 9, p,end) || lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH, (uchar *)"0", 1, p, end)) return -1; if (cookie && lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_SET_COOKIE, (uchar *)cookie, Jsi_Strlen(cookie), p, end)) return -1; if (lws_finalize_http_header(wsi, p, end)) return -1; return lws_write(wsi, start, *p - start, LWS_WRITE_HTTP_HEADERS); }
CWE-120
null
520,417
193515463405361904256680154682077871045
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static Jsi_RC SysVerConvertCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this, Jsi_Value **ret, Jsi_Func *funcPtr) { Jsi_Value *val = Jsi_ValueArrayIndex(interp, args, 0); Jsi_Value *flag = Jsi_ValueArrayIndex(interp, args, 1); if (!val) goto bail; if (Jsi_ValueIsNumber(interp, val)) { char buf[JSI_MAX_NUMBER_STRING*2]; Jsi_Number n; if (Jsi_GetNumberFromValue(interp, val, &n) != JSI_OK) goto bail; jsi_VersionNormalize(n, buf, sizeof(buf)); int trunc = 0; if (flag && (Jsi_GetIntFromValue(interp, flag, &trunc) != JSI_OK || trunc<0 || trunc>2)) return Jsi_LogError("arg2: bad trunc: expected int between 0 and 2"); if (trunc) { int len = Jsi_Strlen(buf)-1; while (trunc>0 && len>1) { if (buf[len] == '0' && buf[len-1] == '.') buf[len-1] = 0; len -= 2; trunc--; } } Jsi_ValueMakeStringDup(interp, ret, buf); return JSI_OK; } if (Jsi_ValueIsString(interp, val)) { Jsi_Number n; if (jsi_GetVerFromVal(interp, val, &n, 0) == JSI_OK) { Jsi_ValueMakeNumber(interp, ret, n); return JSI_OK; } } bail: Jsi_ValueMakeNull(interp, ret); return JSI_OK; }
CWE-120
null
520,418
316933509065410921674826487419064128880
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static void mdbEvalFinalize(MyDbEvalContext *p) { if( p->prep) { mdbReleaseStmt(p->jdb, p->prep, p->nocache); p->prep = 0; } Jsi_DSFree(p->dzSql); }
CWE-120
null
520,419
132992048295999651796276984002995103161
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
jsonGenObject(Jsi_Interp *interp, Jsi_JsonParser *p, const char *js, uint pos, uint *endPos) { Jsi_Obj *obj = Jsi_ObjNewType(interp, JSI_OT_OBJECT); Jsi_Value *nv, *v = Jsi_ValueMakeObject(interp, NULL, obj); uint i, n, len; Jsi_JsonTok *tok; const char *t; tok = p->tokens+pos; for (i=pos+1, n=0; i<p->toknext && n<tok->size; i++, n++) { Jsi_DString dStr; t = Jsi_JsonGetTokstr(p, js, i, &len); i++; n++; if (n>=tok->size) nv = Jsi_ValueMakeUndef(interp, NULL); else nv = jsonGen1Value(interp, p, js, i, &i, 0); Jsi_DSInit(&dStr); Jsi_DSAppendLen(&dStr, t, len); Jsi_ObjInsert(interp, obj, Jsi_DSValue(&dStr), nv, 0); Jsi_DSFree(&dStr); } if (endPos) *endPos = i; return v; }
CWE-120
null
520,420
13241787751973698209901853253008918449
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
Jsi_RC Jsi_FunctionArguments(Jsi_Interp *interp, Jsi_Value *func, int *argcPtr) { Jsi_FuncObj *funcPtr; Jsi_Func *f; if (!Jsi_ValueIsFunction(interp, func)) return JSI_ERROR; funcPtr = func->d.obj->d.fobj; f = funcPtr->func; SIGASSERT(f, FUNC); *argcPtr = f->argnames->count; return JSI_OK; }
CWE-120
null
520,421
130517800854327664323476007211055641306
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static int jsi_FSChmodProc(Jsi_Interp *interp, Jsi_Value* path, int mode) { #ifdef __WIN32 return -1; #else const char *pathPtr = Jsi_ValueToString(interp, path, NULL); Jsi_DString dStr = {}; if (*pathPtr == '~') pathPtr = jsi_TildePath(interp, pathPtr, &dStr); int rc = chmod(pathPtr, mode); Jsi_DSFree(&dStr); return rc; #endif }
CWE-120
null
520,422
309369172650348520611937708738727874467
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static Jsi_RC JSONParseCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this, Jsi_Value **ret, Jsi_Func *funcPtr) { bool strict = 1; Jsi_Value *jsv = Jsi_ValueArrayIndex(interp, args, 1); if (jsv && Jsi_ValueGetBoolean(interp, jsv, &strict) != JSI_OK) return Jsi_LogError("Expected boolean"); jsv = Jsi_ValueArrayIndex(interp, args, 0); const char *js = Jsi_ValueToString(interp, jsv, NULL); return Jsi_JSONParse(interp, js, ret, strict); }
CWE-120
null
520,423
140862502135176144690839217097972368890
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static Jsi_RC jsi_ValueToEnum(Jsi_Interp *interp, Jsi_OptionSpec* spec, Jsi_Value *inValue, const char *inStr, void *record, Jsi_Wide flags) { int n = 0; char *s = (char*)(((char*)record) + spec->offset); const char **list = (const char **)spec->data; Jsi_OptionSpec* es=NULL; int fflags = (flags|spec->flags); int cflags = (fflags&JSI_OPT_CUST_NOCASE?JSI_CMP_NOCASE:0); if (fflags&JSI_OPT_ENUM_EXACT) cflags |= JSI_CMP_EXACT; if (list && (fflags & JSI_OPT_ENUM_SPEC)) { es = (typeof(es))list; while (es->id != JSI_OPTION_END) es++; list = es->init.STRKEY; es = (typeof(es))spec->data; } if (!list) return Jsi_LogError("custom enum spec did not set data: %s", spec->name); if (inStr) { if (JSI_OK != Jsi_GetIndex(interp, (char*)inStr, list, "enum", cflags, &n)) return JSI_ERROR; } else #ifndef JSI_LITE_ONLY if (JSI_OK != Jsi_ValueGetIndex(interp, inValue, list, "enum", cflags, &n)) return JSI_ERROR; #endif if (fflags&JSI_OPT_ENUM_UNSIGNED) { uint64_t u = (uint64_t)n; if (es) u = es[n].value; switch (spec->size) { case 1: *(uint8_t*)s = (uint8_t)u; break; case 2: *(uint16_t*)s = (uint16_t)u; break; case 4: *(uint32_t*)s = (uint32_t)u; break; case 8: *(uint64_t*)s = (uint64_t)u; break; default: return Jsi_LogError("enum size must be 1, 2, 4, or 8: %s", spec->name); } } else { int64_t m = n; if (es) m = es[n].value; switch (spec->size) { case 1: *(int8_t*)s = (int8_t)m; break; case 2: *(int16_t*)s = (int16_t)m; break; case 4: *(int32_t*)s = (int32_t)m; break; case 8: *(int64_t*)s = (int64_t)m; break; default: return Jsi_LogError("enum size must be 1, 2, 4, or 8: %s", spec->name); } } return JSI_OK; }
CWE-120
null
520,424
303389544130000343555266058659991775024
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static Jsi_RC dbEvalStepSub(DbEvalContext *p, int release, int *erc) { int rcs; Jsi_Db *jdb = p->jdb; Jsi_Interp *interp = jdb->interp; JSI_NOTUSED(interp); SqlPreparedStmt *pPreStmt = p->pPreStmt; SQLSIGASSERT(pPreStmt, STMT); sqlite3_stmt *pStmt = pPreStmt->pStmt; if (jdb->debug & TMODE_STEP) JSI_DBQUERY_PRINTF( "DEBUG: step: %s\n", pPreStmt->zSql); rcs = sqlite3_step(pStmt); if( rcs==SQLITE_BUSY ) { if (erc) *erc = -2; return JSI_ERROR; } if( rcs==SQLITE_ROW ) { return JSI_OK; } if( p->pArray ) { dbEvalRowInfo(p, 0, 0, 0); } rcs = sqlite3_reset(pStmt); jdb->stepCnt = sqlite3_stmt_status(pStmt,SQLITE_STMTSTATUS_FULLSCAN_STEP,1); jdb->sortCnt = sqlite3_stmt_status(pStmt,SQLITE_STMTSTATUS_SORT,1); if (release==0 && rcs==SQLITE_OK) return JSI_BREAK; dbReleaseColumnNames(p); p->pPreStmt = 0; if( rcs!=SQLITE_OK ) { /* If a run-time error occurs, report the error and stop reading ** the SQL. */ Jsi_LogError("%s", sqlite3_errmsg(jdb->db)); dbReleaseStmt(jdb, pPreStmt, 1); return JSI_ERROR; } else { dbReleaseStmt(jdb, pPreStmt, p->nocache); } return JSI_BREAK; }
CWE-120
null
520,425
243001630519789490048107430813627185385
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static void MutexDone(Jsi_Mutex *mtx) { pthread_mutex_destroy(&mtx->mtx); }
CWE-120
null
520,426
329420073814448045152246723760117797341
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
jsi_ScopeChain *jsi_ScopeChainNew(Jsi_Interp *interp, int cnt) { jsi_ScopeChain *r = (jsi_ScopeChain *)Jsi_Calloc(1, sizeof(*r)); r->interp = interp; SIGINIT(r,SCOPE); r->chains = (Jsi_Value **)Jsi_Calloc(cnt, sizeof(r->chains[0])); r->chains_cnt = cnt; return r; }
CWE-120
null
520,427
317653463143905314161625468871038652107
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
Jsi_Value *jsi_LoadFunction(Jsi_Interp *interp, const char *str, Jsi_Value *tret) { Jsi_DString dStr = {}; Jsi_Value *v; int i; const char *curFile = interp->curFile; interp->curFile = "<jsiLoadFunction>"; for (i=0; i<2; i++) { Jsi_DSAppend(&dStr, "Jsi_Auto.", str, NULL); Jsi_VarLookup(interp, Jsi_DSValue(&dStr)); v = Jsi_NameLookup(interp, Jsi_DSValue(&dStr)); if (v) jsi_ValueDebugLabel(v, "jsiLoadFunction","f1"); Jsi_DSFree(&dStr); if (v) { const char *cp = Jsi_ValueGetDString(interp, v, &dStr, 0); v = NULL; if (Jsi_EvalString(interp, cp, 0) == JSI_OK) { v = Jsi_NameLookup(interp, str); if (v) jsi_ValueDebugLabel(v, "jsiLoadFunction","f2"); } Jsi_DSFree(&dStr); if (v) { tret = v; break; } } if (interp->autoLoaded++ || i>0) break; /* Index not in memory, so try loading Jsi_Auto from the autoload.jsi file. */ if (interp->autoFiles == NULL) return tret; Jsi_Value **ifs = &interp->autoFiles; int i, ifn = 1; if (Jsi_ValueIsArray(interp, interp->autoFiles)) { ifs = interp->autoFiles->d.obj->arr; ifn = interp->autoFiles->d.obj->arrCnt; } for (i=0; i<ifn; i++) { if (Jsi_EvalFile(interp, ifs[i], 0) != JSI_OK) break; interp->autoLoaded++; } } interp->curFile = curFile; return tret; }
CWE-120
null
520,428
94953010453403246744452857362547193313
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static Jsi_RC mdbEvalStepSub(MyDbEvalContext *eval, int release, int *erc) { MySqlObj *jdb = eval->jdb; Jsi_Interp *interp = jdb->interp; MysqlPrep *prep = eval->prep; SQLSIGASSERT(prep, STMT); MYSQL_STMT *myStmt = prep->myStmt; if (jdb->debug & mdbTMODE_STEP) JSI_DBQUERY_PRINTF( "DEBUG: step: %s\n", prep->zSql); int m = mysql_stmt_fetch(myStmt); if (m == MYSQL_NO_DATA) return JSI_BREAK; if (m) return Jsi_LogError("fetch failed: %s", mysql_error(jdb->db)); return JSI_OK; #if 0 if( eval->pArray ) { mdbEvalRowInfo(eval, 0, 0, 0); } if (release==0) return JSI_BREAK; eval->prep = 0; return JSI_OK; #endif }
CWE-120
null
520,429
77091480990253297779866759895453955722
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static int dbExecCmd(Jsi_Db *jdb, const char *zQuery, int *erc) { int rc = sqlite3_exec(jdb->db, zQuery, 0, 0, 0); if (rc == SQLITE_BUSY) { if (erc) *erc = -2; } else if (rc != SQLITE_OK) { if (erc) *erc = -1; } else return 1; return 0; }
CWE-120
null
520,430
125517773392001876020763296648257362104
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static int dbWalHandler( void *cd, sqlite3 *db, const char *zDb, int nEntry ){ int rc; Jsi_Db *jdb = (Jsi_Db*)cd; Jsi_Interp *interp = jdb->interp; Jsi_Value *vpargs, *items[3] = {}, *ret; items[0] = Jsi_ValueNewObj(interp, jdb->fobj); items[1] = Jsi_ValueMakeStringDup(interp, NULL, zDb); items[2] = Jsi_ValueMakeNumber(interp, NULL, (Jsi_Number)nEntry); vpargs = Jsi_ValueMakeObject(interp, NULL, Jsi_ObjNewArray(interp, items, 3, 0)); Jsi_IncrRefCount(interp, vpargs); ret = Jsi_ValueNew(interp); rc = Jsi_FunctionInvoke(interp, jdb->onWalHook, vpargs, &ret, NULL); Jsi_DecrRefCount(interp, vpargs); if (rc != JSI_OK) { jdb->errCnt++; rc = 1; } else rc = dbGetIntBool(jdb->interp, ret); Jsi_DecrRefCount(interp, ret); return rc; }
CWE-120
null
520,431
79433273307993841147188509576685470035
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
Jsi_RC jsi_InitValue(Jsi_Interp *interp, int release) { return JSI_OK; }
CWE-120
null
520,432
128922510753332110838284576802712667158
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
Jsi_HashSearchFirst(Jsi_Hash *tablePtr, Jsi_HashSearch *searchPtr) { searchPtr->tablePtr = tablePtr; searchPtr->nextIndex = 0; searchPtr->nextEntryPtr = NULL; return Jsi_HashSearchNext(searchPtr); }
CWE-120
null
520,433
11185088338400935086117946636548294061
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static void dbFlushStmtCache( Jsi_Db *jdb ) { Jsi_ListClear(jdb->stmtCache); jdb->stmtCacheCnt = 0; }
CWE-120
null
520,434
82926391073716538534274808501681922040
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static Jsi_RC dbPrepareAndBind( Jsi_Db *jdb, /* Database object */ char const *zIn, /* SQL to compile */ char const **pzOut, /* OUT: Pointer to next SQL statement */ SqlPreparedStmt **ppPreStmt /* OUT: Object used to cache statement */ ) { if (dbPrepareStmt(jdb, zIn, pzOut, ppPreStmt) != JSI_OK) return JSI_ERROR; return dbBindStmt(jdb, *ppPreStmt); }
CWE-120
null
520,435
83672654393689564585580566912054932633
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
Jsi_Wide Jsi_Tell(Jsi_Interp *interp, Jsi_Channel chan) { if (chan->fsPtr==0 || !chan->fsPtr->tellProc) return -1; return chan->fsPtr->tellProc(chan); }
CWE-120
null
520,436
240765413986710395734627976481436126208
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static jsi_CaseExprStat *exprstat_new(jsi_Pstate *pstate, Jsi_OpCodes *expr, Jsi_OpCodes *stat, int isdef) { jsi_CaseExprStat *r = (jsi_CaseExprStat*)Jsi_Calloc(1,sizeof(*r)); r->sig = JSI_SIG_CASESTAT; r->expr = expr; r->stat = stat; r->isdefault = isdef; return r; }
CWE-120
null
520,437
323988420143202071283833192480471318151
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
HashStringCreate( Jsi_Hash *tablePtr, const void *key, bool *newPtr) { jsi_Hash hval; Jsi_HashEntry **bucketPtr; Jsi_HashEntry *hPtr; size_t size, hindex; hval = HashString((const char*)key); hindex = hval & tablePtr->mask; for (hPtr = tablePtr->buckets[hindex]; hPtr != NULL; hPtr = hPtr->nextPtr) { if (hPtr->hval == hval) { const char *p1, *p2; for (p1 = (const char*)key, p2 = hPtr->key.string; ; p1++, p2++) { if (*p1 != *p2) { break; } if (*p1 == '\0') { if (newPtr) *newPtr = 0; return hPtr; } } } } if (newPtr) *newPtr = 1; size = sizeof(Jsi_HashEntry) + Jsi_Strlen((char*)key) - sizeof(jsi_HashKey) + 1; hPtr = (Jsi_HashEntry*)Jsi_Calloc(1, size); hPtr->typ = JSI_MAP_HASH; bucketPtr = tablePtr->buckets + hindex; hPtr->tablePtr = tablePtr; hPtr->nextPtr = *bucketPtr; hPtr->hval = hval; hPtr->clientData = 0; Jsi_Strcpy(hPtr->key.string, (char*)key); *bucketPtr = hPtr; tablePtr->numEntries++; if (tablePtr->numEntries >= tablePtr->rebuildSize) RebuildTable(tablePtr); return hPtr; }
CWE-120
null
520,438
97119483222084922932056555941240369644
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static const char* jsw_getReasonStr(enum lws_callback_reasons reason) { typedef struct { enum lws_callback_reasons r; const char *name; } ssType; static ssType ss[] = { #define MKLCBS(n) { n, #n } MKLCBS(LWS_CALLBACK_PROTOCOL_INIT), MKLCBS(LWS_CALLBACK_PROTOCOL_DESTROY), MKLCBS(LWS_CALLBACK_WSI_CREATE), MKLCBS(LWS_CALLBACK_WSI_DESTROY),MKLCBS(LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS), MKLCBS(LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS), MKLCBS(LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION), MKLCBS(LWS_CALLBACK_OPENSSL_CONTEXT_REQUIRES_PRIVATE_KEY), MKLCBS(LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED), MKLCBS(LWS_CALLBACK_HTTP), MKLCBS(LWS_CALLBACK_HTTP_BODY), MKLCBS(LWS_CALLBACK_HTTP_BODY_COMPLETION), MKLCBS(LWS_CALLBACK_HTTP_FILE_COMPLETION), MKLCBS(LWS_CALLBACK_HTTP_WRITEABLE), MKLCBS(LWS_CALLBACK_CLOSED_HTTP), MKLCBS(LWS_CALLBACK_FILTER_HTTP_CONNECTION), MKLCBS(LWS_CALLBACK_ESTABLISHED), MKLCBS(LWS_CALLBACK_CLOSED), MKLCBS(LWS_CALLBACK_SERVER_WRITEABLE), MKLCBS(LWS_CALLBACK_RECEIVE), MKLCBS(LWS_CALLBACK_RECEIVE_PONG), MKLCBS(LWS_CALLBACK_WS_PEER_INITIATED_CLOSE), MKLCBS(LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION), MKLCBS(LWS_CALLBACK_CONFIRM_EXTENSION_OKAY), MKLCBS(LWS_CALLBACK_CLIENT_CONNECTION_ERROR), MKLCBS(LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH), MKLCBS(LWS_CALLBACK_CLIENT_ESTABLISHED), MKLCBS(LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER), MKLCBS(LWS_CALLBACK_CLIENT_RECEIVE), MKLCBS(LWS_CALLBACK_CLIENT_RECEIVE_PONG), MKLCBS(LWS_CALLBACK_CLIENT_WRITEABLE), MKLCBS(LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED), MKLCBS(LWS_CALLBACK_WS_EXT_DEFAULTS), MKLCBS(LWS_CALLBACK_FILTER_NETWORK_CONNECTION), MKLCBS(LWS_CALLBACK_GET_THREAD_ID), MKLCBS(LWS_CALLBACK_ADD_POLL_FD), MKLCBS(LWS_CALLBACK_DEL_POLL_FD), MKLCBS(LWS_CALLBACK_CHANGE_MODE_POLL_FD), MKLCBS(LWS_CALLBACK_LOCK_POLL), MKLCBS(LWS_CALLBACK_UNLOCK_POLL), #if (LWS_LIBRARY_VERSION_MAJOR>1) MKLCBS(LWS_CALLBACK_CGI), MKLCBS(LWS_CALLBACK_CGI_TERMINATED), MKLCBS(LWS_CALLBACK_CGI_STDIN_DATA), MKLCBS(LWS_CALLBACK_CGI_STDIN_COMPLETED), MKLCBS(LWS_CALLBACK_SESSION_INFO), MKLCBS(LWS_CALLBACK_GS_EVENT), MKLCBS(LWS_CALLBACK_HTTP_PMO), MKLCBS(LWS_CALLBACK_RAW_RX), MKLCBS(LWS_CALLBACK_RAW_CLOSE), MKLCBS(LWS_CALLBACK_RAW_WRITEABLE), MKLCBS(LWS_CALLBACK_RAW_ADOPT), MKLCBS(LWS_CALLBACK_RAW_ADOPT_FILE), MKLCBS(LWS_CALLBACK_ADD_HEADERS), MKLCBS(LWS_CALLBACK_CHECK_ACCESS_RIGHTS), MKLCBS(LWS_CALLBACK_PROCESS_HTML), MKLCBS(LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP), MKLCBS(LWS_CALLBACK_CLOSED_CLIENT_HTTP), MKLCBS(LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ), MKLCBS(LWS_CALLBACK_RECEIVE_CLIENT_HTTP), MKLCBS(LWS_CALLBACK_COMPLETED_CLIENT_HTTP), MKLCBS(LWS_CALLBACK_CLIENT_HTTP_WRITEABLE), MKLCBS(LWS_CALLBACK_HTTP_BIND_PROTOCOL), MKLCBS(LWS_CALLBACK_HTTP_DROP_PROTOCOL), MKLCBS(LWS_CALLBACK_OPENSSL_PERFORM_SERVER_CERT_VERIFICATION), MKLCBS(LWS_CALLBACK_RAW_RX_FILE), MKLCBS(LWS_CALLBACK_RAW_WRITEABLE_FILE), MKLCBS(LWS_CALLBACK_RAW_CLOSE_FILE), MKLCBS(LWS_CALLBACK_USER), #endif #if (LWS_LIBRARY_VERSION_NUMBER>=3000000) MKLCBS(LWS_CALLBACK_SSL_INFO), MKLCBS(LWS_CALLBACK_CGI_PROCESS_ATTACH), MKLCBS(LWS_CALLBACK_CLIENT_CLOSED), MKLCBS(LWS_CALLBACK_TIMER), MKLCBS(LWS_CALLBACK_EVENT_WAIT_CANCELLED), MKLCBS(LWS_CALLBACK_CHILD_CLOSING), MKLCBS(LWS_CALLBACK_CHILD_WRITE_VIA_PARENT), MKLCBS(LWS_CALLBACK_VHOST_CERT_AGING), MKLCBS(LWS_CALLBACK_VHOST_CERT_UPDATE), #endif {(enum lws_callback_reasons)0, NULL } }; int i = -1; while (ss[++i].name) if (ss[i].r == reason) return ss[i].name; return ""; }
CWE-120
null
520,439
83170566721586651133945486946003563186
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
const char *Jsi_ObjTypeStr(Jsi_Interp *interp, Jsi_Obj *o) { switch (o->ot) { case JSI_OT_BOOL: return "boolean"; break; case JSI_OT_FUNCTION: return "function"; break; case JSI_OT_NUMBER: return "number"; break; case JSI_OT_STRING: return "string"; break; case JSI_OT_REGEXP: return "regexp"; break; case JSI_OT_ITER: return "iter"; break; case JSI_OT_OBJECT: if (!o->isarrlist) return "object"; case JSI_OT_ARRAY: return "array"; break; case JSI_OT_USEROBJ: if (o->__proto__) { Jsi_HashEntry *hPtr; Jsi_HashSearch search; for (hPtr = Jsi_HashSearchFirst(interp->thisTbl,&search); hPtr != NULL; hPtr = Jsi_HashSearchNext(&search)) if (Jsi_HashValueGet(hPtr) == o->__proto__) return (char*)Jsi_HashKeyGet(hPtr); } return "userobj"; break; //return Jsi_ObjGetType(interp, v->d.obj); default: break; } return ""; }
CWE-120
null
520,440
183832723883411178105649743106051343416
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static void delete_case2(Jsi_TreeEntry* n) { Jsi_TreeEntry* s = sibling(n); if (node_color(s) == _JSI_TREE_RED) { set_color(n->parent, _JSI_TREE_RED); set_color(s, _JSI_TREE_BLACK); if (n == n->parent->left) rotate_left(n->parent); else rotate_right(n->parent); } delete_case3(n); }
CWE-120
null
520,441
61863238480532694890948146312237909658
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static Jsi_RC jsi_BitsetToValue(Jsi_Interp *interp, Jsi_OptionSpec* spec, Jsi_Value **outValue, Jsi_DString *outStr, void *record, Jsi_Wide flags) { int i, n, cnt = 0, *s = (int*)(((char*)record) + spec->offset); const char **list = (const char**)spec->data; if (!list) return Jsi_LogError("custom enum spec did not set data: %s", spec->name); if (outStr) { n = *s; for (i=0; list[i]; i++) { if (i >= (int)(spec->size*8)) return Jsi_LogError("list larger than field size: %s", spec->name); if (!(n & (1<<i))) continue; if (cnt++) Jsi_DSAppendLen(outStr, ", ", 1); Jsi_DSAppendLen(outStr, list[i], -1); } return JSI_OK; } #ifndef JSI_LITE_ONLY Jsi_Obj *obj = Jsi_ObjNewType(interp, JSI_OT_ARRAY); n = *s; for (i=0; list[i]; i++) { Jsi_Value *v; if (!(n&(1<<i))) continue; cnt++; v = Jsi_ValueMakeStringKey(interp, NULL, list[i]); Jsi_ObjArrayAdd(interp, obj, v); } Jsi_ValueMakeArrayObject(interp, outValue, obj); #endif return JSI_OK; }
CWE-120
null
520,442
79131544401689818868311298281156207788
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
void Jsi_MapSearchDone (Jsi_MapSearch *searchPtr){ switch (searchPtr->typ) { case JSI_MAP_HASH: break; case JSI_MAP_TREE: Jsi_TreeSearchDone(&searchPtr->v.tree); break; case JSI_MAP_LIST: break; case JSI_MAP_NONE: break; } }
CWE-120
null
520,443
60720066267739288821058253371421858415
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
Jsi_RC jsi_evalStrFile(Jsi_Interp* interp, Jsi_Value *path, const char *str, int flags, int level) { Jsi_Channel tinput = NULL, input = Jsi_GetStdChannel(interp, 0); Jsi_Value *npath = path; Jsi_RC rc = JSI_ERROR; const char *ustr = NULL, *ostr = str; if (Jsi_MutexLock(interp, interp->Mutex) != JSI_OK) return rc; int oldSp, uskip = 0, fncOfs = 0, fnLen; int oldef = interp->evalFlags; jsi_Pstate *oldps = interp->ps; const char *oldFile = interp->curFile; char *origFile = Jsi_ValueString(interp, path, &fnLen); const char *fname = origFile; char *oldDir = interp->curDir, *cp; char dirBuf[PATH_MAX]; jsi_Pstate *ps = NULL; jsi_FileInfo *fi = NULL; int exists = (flags&JSI_EVAL_EXISTS); int ignore = (flags&JSI_EVAL_ERRIGNORE); if (flags & JSI_EVAL_GLOBAL) level = 1; int oisi = interp->isMain; if (flags & JSI_EVAL_ISMAIN) interp->isMain = 1; oldSp = interp->framePtr->Sp; dirBuf[0] = 0; Jsi_DString dStr, fStr; Jsi_DSInit(&dStr); Jsi_DSInit(&fStr); if (str == NULL) { if (fname != NULL) { if (fnLen>2 && fname[fnLen-1]=='/') { Jsi_DSAppendLen(&fStr, fname, fnLen-1); const char *fcp = Jsi_DSValue(&fStr), *fce = strrchr(fcp,'/'); if (fce) { fname = Jsi_DSAppend(&fStr, fce, ".jsi", NULL); npath = Jsi_ValueNewStringDup(interp, fname); Jsi_IncrRefCount(interp, npath); } } if (!Jsi_Strcmp(fname,"-")) input = Jsi_GetStdChannel(interp, 0); else { /* Use translated FileName. */ if (interp->curDir && fname[0] != '/' && fname[0] != '~') { char dirBuf2[PATH_MAX], *np; snprintf(dirBuf, sizeof(dirBuf), "%s/%s", interp->curDir, fname); if ((np=Jsi_FileRealpathStr(interp, dirBuf, dirBuf2)) == NULL) { Jsi_LogError("Can not open '%s'", fname); goto bail; } if (npath != path) Jsi_IncrRefCount(interp, npath); npath = Jsi_ValueNewStringDup(interp, np); Jsi_IncrRefCount(interp, npath); fname = Jsi_ValueString(interp, npath, NULL); } if (flags&JSI_EVAL_ARGV0) { if (interp->argv0) Jsi_DecrRefCount(interp, interp->argv0); interp->argv0 = Jsi_ValueNewStringDup(interp, fname); Jsi_IncrRefCount(interp, interp->argv0); } bool osafe = interp->isSafe; if (interp->startSafe && flags&JSI_EVAL_ARGV0) { if (interp->safeReadDirs || interp->safeMode == jsi_safe_None) interp->isSafe = 0; else { char vds[PATH_MAX], *cp; const char *vda[2] = {vds}; Jsi_Strncpy(vds, Jsi_ValueString(interp, npath, NULL), sizeof(vds)-1); vds[sizeof(vds)-1] = 0; cp = Jsi_Strrchr(vds, '/'); if (cp) cp[1] = 0; Jsi_DString pStr = {}; vda[1] = Jsi_GetCwd(interp, &pStr); interp->safeReadDirs = Jsi_ValueNewArray(interp, vda, 2); Jsi_IncrRefCount(interp, interp->safeReadDirs); if (interp->safeMode == jsi_safe_WriteRead || interp->safeMode == jsi_safe_Lockdown) { if (!interp->safeWriteDirs) { interp->safeWriteDirs = interp->safeReadDirs; Jsi_IncrRefCount(interp, interp->safeWriteDirs); } } else if (interp->safeMode == jsi_safe_Write) { interp->safeWriteDirs = Jsi_ValueNewArray(interp, vda+1, 1); Jsi_IncrRefCount(interp, interp->safeWriteDirs); } Jsi_DSFree(&pStr); } } tinput = input = Jsi_Open(interp, npath, (exists?"-r":"r")); interp->isSafe = osafe; if (!input) { if (exists) rc = JSI_OK; //Jsi_LogError("Can not open '%s'", fname); goto bail; } } cp = Jsi_Strrchr(fname, '.'); if (cp && !Jsi_Strcmp(cp, ".jsi") && interp->isMain) { interp->typeCheck.parse = interp->typeCheck.run = interp->typeCheck.all = 1; interp->strict = 1; } bool isNew; Jsi_HashEntry *hPtr; hPtr = Jsi_HashEntryNew(interp->fileTbl, fname, &isNew); if (isNew == 0 && hPtr) { if ((flags & JSI_EVAL_ONCE)) { rc = JSI_OK; goto bail; } fi = (jsi_FileInfo *)Jsi_HashValueGet(hPtr); if (!fi) goto bail; interp->curFile = fi->fileName; interp->curDir = fi->dirName; } else { fi = (jsi_FileInfo *)Jsi_Calloc(1,sizeof(*fi)); if (!fi) goto bail; Jsi_HashValueSet(hPtr, fi); fi->origFile = (char*)Jsi_KeyAdd(interp, origFile); interp->curFile = fi->fileName = (char*)Jsi_KeyAdd(interp, fname); char *dfname = Jsi_Strdup(fname); if ((cp = Jsi_Strrchr(dfname,'/'))) *cp = 0; interp->curDir = fi->dirName = (char*)Jsi_KeyAdd(interp, dfname); Jsi_Free(dfname); } if (!input->fname) input->fname = interp->curFile; int cnt = 0, noncmt = 0, jppOpts[4]={}; uint ilen; char buf[JSI_BUFSIZ*2]; const char *jpp; while (cnt<MAX_LOOP_COUNT) { if (!Jsi_Gets(interp, input, buf, sizeof(buf))) break; if (++cnt==1 && (!(flags&JSI_EVAL_NOSKIPBANG)) && (buf[0] == '#' && buf[1] == '!')) { Jsi_DSAppend(&dStr, "\n", NULL); uskip=1; continue; } if (!noncmt) { int bi; if (!buf[0] || (buf[0] == '/' && buf[1] == '/')) goto cont; for (bi=0; buf[bi]; bi++) if (!isspace(buf[bi])) break; if (!buf[bi]) goto cont; } if (!noncmt++) fncOfs = Jsi_DSLength(&dStr)-uskip; jpp = interp->jsppChars; if (jpp || interp->unitTest) ilen = Jsi_Strlen(buf); if (interp->unitTest && buf[0]==';' && buf[1] && buf[2]) { if (interp->unitTest&1 && jsi_JsPreprocessLine(interp, buf, sizeof(buf), ilen, jppOpts, cnt) != JSI_OK) goto bail; } else if (interp->jsppCallback && interp->jsppChars) { if (jsi_JsPreprocessLineCB(interp, buf, sizeof(buf), ilen, jppOpts, cnt) != JSI_OK) goto bail; } cont: Jsi_DSAppend(&dStr, buf, NULL); } if (cnt>=MAX_LOOP_COUNT) Jsi_LogError("source file too large"); str = Jsi_DSValue(&dStr); } if (interp->curDir && (flags&JSI_EVAL_AUTOINDEX)) Jsi_AddAutoFiles(interp, interp->curDir); } ustr = str + fncOfs; // See if "use XXX" is on first non // or empty line (or second if there is a #! on first line) if (ustr && *ustr && !Jsi_Strncmp(ustr+uskip, "\"use ", 5)) { ustr += 5+uskip; const char *cpe = ustr; while (*cpe && *cpe != '\"' && *cpe != '\n' && (isalpha(*cpe) || *cpe ==',' || *cpe =='!')) cpe++; if (*cpe == '\"') { Jsi_DString cStr; Jsi_DSInit(&cStr); cpe = Jsi_DSAppendLen(&cStr, ustr, (cpe-ustr)); rc = jsi_ParseTypeCheckStr(interp, cpe); Jsi_DSFree(&cStr); if (rc != JSI_OK) goto bail; } } /* TODO: cleanup interp->framePtr->Sp stuff. */ oldSp = interp->framePtr->Sp; // Evaluate code. rc = JSI_OK; ps = jsiNewParser(interp, str, input, 0); interp->evalFlags = flags; if (!ps) rc = JSI_ERROR; else { Jsi_ValueMakeUndef(interp, &interp->retValue); interp->ps = ps; Jsi_Value *retValue = interp->retValue; if (!interp->strict) interp->strict = (jsi_GetDirective(interp, ps->opcodes, "use strict")!=NULL); const char *curFile = interp->curFile; if (level <= 0) rc = jsi_evalcode(ps, NULL, ps->opcodes, interp->gsc, interp->csc, interp->csc, &retValue); else { jsi_Frame *fptr = interp->framePtr; while (fptr && fptr->level > level) fptr = fptr->parent; if (!fptr) rc = JSI_ERROR; else rc = jsi_evalcode(ps, NULL, ps->opcodes, fptr->ingsc, fptr->incsc, fptr->inthis, &retValue); } interp->curFile = curFile; if (rc != JSI_OK) rc = (ignore?JSI_OK:JSI_ERROR); else if (ps->last_exception || oldps->last_exception) Jsi_ValueDup2(interp, &oldps->last_exception, ps->last_exception); //TODO: dup even if null? interp->ps = oldps; interp->evalFlags = oldef; if (rc == JSI_OK && ps && !ostr) fi->str = ps->lexer->d.str; } bail: interp->curFile = oldFile; interp->curDir = oldDir; interp->framePtr->Sp = oldSp; interp->isMain = oisi; if (path != npath) Jsi_DecrRefCount(interp, npath); Jsi_DSFree(&dStr); Jsi_DSFree(&fStr); if (tinput) Jsi_Close(interp, tinput); Jsi_MutexUnlock(interp, interp->Mutex); if (interp->exited && interp->level <= 0) { rc = JSI_EXIT; if (!interp->parent) Jsi_InterpDelete(interp); } return rc; }
CWE-120
null
520,444
241015807697092380707902293335723402669
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static void DeBackSlashify(char *cp) { char *dp = cp; while (*cp) { if (*cp == '\\') { *dp = '/'; } else *dp = *cp; cp++; dp++; } *dp = 0; }
CWE-120
null
520,445
31088036731362020495468779789180863213
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static Jsi_OpCodes *code_ewith(jsi_Pstate *p, jsi_Pline *line) { JSI_NEW_CODESLN(0,OP_EWITH, 0); }
CWE-120
null
520,446
109691835581584880385006634030509616722
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static int jsi_wsService(jsi_wsCmdObj *cmdPtr) { int n = 0; struct timeval tv; if (cmdPtr->inUpdate) return 0; cmdPtr->inUpdate = 1; gettimeofday(&tv, NULL); int to = cmdPtr->recvBufTimeout; if (to>0 && cmdPtr->recvBufCnt) { // Flush buffered data. jsi_wsPss *pss = NULL; Jsi_HashEntry *hPtr; Jsi_HashSearch cursor; for (hPtr = Jsi_HashSearchFirst(cmdPtr->pssTable, &cursor); hPtr != NULL; hPtr = Jsi_HashSearchNext(&cursor)) { pss = (jsi_wsPss*)Jsi_HashValueGet(hPtr); WSSIGASSERT(pss, PWS); if (pss->state == PWS_DEAD) continue; if (Jsi_DSLength(&pss->recvBuf)<=0) continue; if (pss->stats.recvLast && difftime(time(NULL), pss->stats.recvLast)<(double)to) continue; jsi_wsrecv_flush(cmdPtr, pss); } } /* * This provokes the LWS_CALLBACK_SERVER_WRITEABLE for every * live websocket connection using the DUMB_INCREMENT protocol, * as soon as it can take more packets (usually immediately) */ if (((unsigned int)tv.tv_usec - cmdPtr->oldus) > 50000) { lws_callback_on_writable_all_protocol(cmdPtr->context, &cmdPtr->protocols[JWS_PROTOCOL_WEBSOCK]); cmdPtr->oldus = tv.tv_usec; } #ifdef EXTERNAL_POLL /* * this represents an existing server's single poll action * which also includes libwebsocket sockets */ n = poll(jsi_wspollfds, jsi_wsnum_pollfds, 50); if (n < 0) { n = 0; goto done; } if (n) for (n = 0; n < jsi_wsnum_pollfds; n++) if (jsi_wspollfds[n].revents) /* * returns immediately if the fd does not * match anything under libwebsockets * control */ if (lws_service_fd(context, &jsi_wspollfds[n]) < 0) { n = -1; goto done; } done: #else n = lws_service(cmdPtr->context, 50); #endif if (cmdPtr->onModify) { jsi_wsOnModify(cmdPtr); } cmdPtr->inUpdate = 0; return n; }
CWE-120
null
520,447
263673998955457709328205118021083593614
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static int jsi_wscallback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len) { struct lws_context *context = lws_get_context(wsi); const char *inPtr = (char*)in; char client_name[128], client_ip[128]; const char *res = ""; #ifdef EXTERNAL_POLL int m; int fd = (int)(long)user; #endif jsi_wsCmdObj *cmdPtr = (jsi_wsCmdObj *)lws_context_user(context); if (!cmdPtr) { fprintf(stderr, "bad ws context\n"); return -1; } jsi_wsPss *pss = NULL; Jsi_Interp *interp = cmdPtr->interp; Jsi_Value* callPtr = NULL; int rc = 0, deflt = 0; WSSIGASSERT(cmdPtr, OBJ); if (Jsi_InterpGone(interp)) cmdPtr->deleted = 1; if (cmdPtr->debug>=128) fprintf(stderr, "HTTP CALLBACK: len=%d, %p %d:%s\n", (int)len, user, reason, jsw_getReasonStr(reason)); switch (reason) { #ifndef EXTERNAL_POLL case LWS_CALLBACK_GET_THREAD_ID: case LWS_CALLBACK_UNLOCK_POLL: case LWS_CALLBACK_PROTOCOL_INIT: case LWS_CALLBACK_ADD_POLL_FD: case LWS_CALLBACK_DEL_POLL_FD: case LWS_CALLBACK_CHANGE_MODE_POLL_FD: case LWS_CALLBACK_LOCK_POLL: return rc; #else /* * callbacks for managing the external poll() array appear in * protocol 0 callback */ case LWS_CALLBACK_ADD_POLL_FD: if (jsi_wsnum_pollfds >= max_poll_elements) { lwsl_err("LWS_CALLBACK_ADD_POLL_FD: too many sockets to track\n"); return 1; } fd_lookup[fd] = jsi_wsnum_pollfds; jsi_wspollfds[jsi_wsnum_pollfds].fd = fd; jsi_wspollfds[jsi_wsnum_pollfds].events = (int)(long)len; jsi_wspollfds[jsi_wsnum_pollfds++].revents = 0; break; case LWS_CALLBACK_DEL_POLL_FD: if (!--jsi_wsnum_pollfds) break; m = fd_lookup[fd]; /* have the last guy take up the vacant slot */ jsi_wspollfds[m] = jsi_wspollfds[jsi_wsnum_pollfds]; fd_lookup[jsi_wspollfds[jsi_wsnum_pollfds].fd] = m; break; #endif default: deflt = 1; break; } if (deflt && cmdPtr->debug>16 && cmdPtr->debug<128) { fprintf(stderr, "HTTP CALLBACK: len=%d, %p %d:%s\n", (int)len, user, reason, jsw_getReasonStr(reason)); } switch (reason) { case LWS_CALLBACK_WSI_DESTROY: break; #if (LWS_LIBRARY_VERSION_MAJOR>1) // Handle GET file download in client mode. case LWS_CALLBACK_RECEIVE_CLIENT_HTTP: { char buffer[1024 + LWS_PRE]; char *px = buffer + LWS_PRE; int lenx = sizeof(buffer) - LWS_PRE; if (lws_http_client_read(wsi, &px, &lenx) < 0) return -1; break; } case LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ: if (jsi_wsrecv_callback(interp, cmdPtr, pss, inPtr, len, 0) != JSI_OK) rc = 1; break; case LWS_CALLBACK_COMPLETED_CLIENT_HTTP: if (jsi_wsrecv_callback(interp, cmdPtr, pss, inPtr, len, 1) != JSI_OK) rc = 1; break; case LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER: if (cmdPtr->post) { unsigned char **p = (unsigned char **)in, *end = (*p) + len; int n = 0; char buf[JSI_MAX_NUMBER_STRING]; Jsi_ValueString(interp, cmdPtr->post, &n); snprintf(buf, sizeof(buf), "%d", n); if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH, (unsigned char *)buf, 2, p, end)) return -1; if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE, (unsigned char *)"application/x-www-form-urlencoded", 33, p, end)) return -1; /* inform lws we have http body to send */ lws_client_http_body_pending(wsi, 1); lws_callback_on_writable(wsi); } break; case LWS_CALLBACK_CLIENT_HTTP_WRITEABLE: { int n = 0; char *cps = Jsi_ValueString(interp, cmdPtr->post, &n); char *buf = (char*)Jsi_Calloc(1, LWS_PRE + n + 1); Jsi_Strcpy(buf + LWS_PRE, cps); n = lws_write(wsi, (unsigned char *)&buf[LWS_PRE], strlen(&buf[LWS_PRE]), LWS_WRITE_HTTP); Jsi_Free(buf); if (n < 0) return -1; /* we only had one thing to send, so inform lws we are done * if we had more to send, call lws_callback_on_writable(wsi); * and just return 0 from callback. On having sent the last * part, call the below api instead.*/ lws_client_http_body_pending(wsi, 0); break; } #endif case LWS_CALLBACK_FILTER_NETWORK_CONNECTION: break; case LWS_CALLBACK_PROTOCOL_INIT: break; case LWS_CALLBACK_CLOSED_HTTP: if (cmdPtr->debug>2) fprintf(stderr, "CLOSED\n"); if (!pss) pss = jsi_wsgetPss(cmdPtr, wsi, user, 0, 1); if (pss) jsi_wsdeletePss(pss); break; case LWS_CALLBACK_WSI_CREATE: break; case LWS_CALLBACK_CONFIRM_EXTENSION_OKAY: break; case LWS_CALLBACK_FILTER_HTTP_CONNECTION: if (cmdPtr->debug>1) fprintf(stderr, "FILTER CONNECTION: %s\n", inPtr); pss = jsi_wsgetPss(cmdPtr, wsi, user, 1, 1); Jsi_DSSet(&pss->url, inPtr); jsi_wsgetUriArgValue(interp, wsi, &pss->query, &pss->queryObj); if (cmdPtr->instCtx == context && (cmdPtr->clientName[0] || cmdPtr->clientIP[0])) { pss->clientName = cmdPtr->clientName; pss->clientIP = cmdPtr->clientIP; } Jsi_DSSetLength(&pss->dHdrs, 0); pss->hdrNum = jsi_wsGetHeaders(pss, wsi, &pss->dHdrs, pss->hdrSz, sizeof(pss->hdrSz)/sizeof(int)); if (cmdPtr->onFilter && !cmdPtr->deleted) { // 4 args: ws, id, url, bool int killcon = 0, n = 0; Jsi_Obj *oarg1; Jsi_Value *vpargs, *vargs[10], *ret = Jsi_ValueNew1(interp); vargs[n++] = Jsi_ValueNewObj(interp, cmdPtr->fobj); vargs[n++] = Jsi_ValueNewNumber(interp, (Jsi_Number)(pss->wid)); vargs[n++] = Jsi_ValueNewBlob(interp, (uchar*)in, len); vargs[n++] = Jsi_ValueNewBoolean(interp, 1); vpargs = Jsi_ValueMakeObject(interp, NULL, oarg1 = Jsi_ObjNewArray(interp, vargs, n, 0)); Jsi_IncrRefCount(interp, vpargs); Jsi_ValueMakeUndef(interp, &ret); rc = Jsi_FunctionInvoke(interp, cmdPtr->onFilter, vpargs, &ret, NULL); if (rc == JSI_OK && Jsi_ValueIsFalse(interp, ret)) { if (cmdPtr->debug>1) fprintf(stderr, "WS:KILLING CONNECTION: %p\n", pss); killcon = 1; } Jsi_DecrRefCount(interp, vpargs); Jsi_DecrRefCount(interp, ret); if (rc != JSI_OK) { Jsi_LogError("websock bad rcv eval"); return 1; } if (killcon) return 1; } break; case LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED: client_name[0] = 0; client_ip[0] = 0; lws_get_peer_addresses(wsi, lws_get_socket_fd(wsi), client_name, sizeof(client_name), client_ip, sizeof(client_ip)); if (client_name[0]) cmdPtr->clientName = Jsi_KeyAdd(interp, client_name); if (client_ip[0]) cmdPtr->clientIP = Jsi_KeyAdd(interp, client_ip); if (cmdPtr->clientName || cmdPtr->clientIP) { const char *loname = cmdPtr->localhostName; if (!loname) loname = "localhost"; cmdPtr->instCtx = context; if (cmdPtr->debug>1) fprintf(stderr, "Received network connect from %s (%s)\n", cmdPtr->clientName, cmdPtr->clientIP); #ifndef __WIN32 if (cmdPtr->local && (cmdPtr->clientName && Jsi_Strcmp(cmdPtr->clientName, loname))) { if (cmdPtr->debug>1) fprintf(stderr, "Dropping non-localhost connection\n"); return 1; } #endif } if (cmdPtr->maxConnects && cmdPtr->stats.connectCnt>=cmdPtr->maxConnects) { if (cmdPtr->debug>1) fprintf(stderr, "maxConnects exceeded: rejecting connection <%p>\n", user); rc = -1; } /* if we returned non-zero from here, we kill the connection */ break; case LWS_CALLBACK_HTTP: { Jsi_DString dStr; Jsi_DSInit(&dStr); if (cmdPtr->debug) fprintf(stderr, "HTTP GET: %s\n", inPtr); rc = jsi_wsHttp(interp, cmdPtr, wsi, user, context, inPtr, &dStr, pss); Jsi_DSFree(&dStr); if (rc<0) return -1; if (rc==1) { goto try_to_reuse; } break; } #if (LWS_LIBRARY_VERSION_MAJOR>1) case LWS_CALLBACK_HTTP_BODY: { if (!pss) pss = jsi_wsgetPss(cmdPtr, wsi, user, 0, 1); if (!pss) break; callPtr = (pss->onUpload?pss->onUpload:cmdPtr->onUpload); if (cmdPtr->maxUpload<=0 || !callPtr) { if (cmdPtr->noWarn==0) fprintf(stderr, "Upload disabled: maxUpload=%d, onUpload=%p\n", cmdPtr->maxUpload, callPtr); return -1; } if (!pss->spa) { /* create the POST argument parser */ if (!pss->paramv) { if (cmdPtr->formParams && cmdPtr->formParams != jsi_wsparam_str) Jsi_SplitStr(cmdPtr->formParams, &pss->paramc, &pss->paramv, ",", &pss->paramDS); else { pss->paramv = (typeof(pss->paramv))jsi_wsparam_names; pss->paramc = ARRAY_SIZE(jsi_wsparam_names); } } pss->spa = lws_spa_create(wsi, (const char*const*)pss->paramv, pss->paramc, 4096, jsi_wsFileUploadCB, pss); if (!pss->spa) return -1; pss->filename[0] = '\0'; pss->file_length = 0; } cmdPtr->stats.uploadLast = pss->stats.uploadLast = time(NULL); /* let it parse the POST data */ if (lws_spa_process(pss->spa, inPtr, len)) return -1; if (!pss->stats.uploadStart) { cmdPtr->stats.uploadEnd = pss->stats.uploadEnd = 0; cmdPtr->stats.uploadStart = pss->stats.uploadStart = time(NULL); cmdPtr->stats.uploadCnt++; pss->stats.uploadCnt++; } break; } case LWS_CALLBACK_HTTP_BODY_COMPLETION: if (!pss) { pss = jsi_wsgetPss(cmdPtr, wsi, user, 0, 1); callPtr = (pss&&pss->onUpload?pss->onUpload:cmdPtr->onUpload); } if (pss && pss->spa) lws_spa_finalize(pss->spa); res = Jsi_DSValue(&pss->resultStr); if (!res[0]) { if (!pss->resultCode) res = "<html><body>Upload complete</body></html>"; else res = "<html><body>Upload error</body></html>"; } jsi_wsServeString(pss, wsi, res, pss->resultCode==JSI_OK?0:500, NULL, NULL); if (cmdPtr->maxUpload<=0 || !callPtr) { if (cmdPtr->noWarn==0) fprintf(stderr, "Upload disabled: maxUpload=%d, onUpload=%p\n", cmdPtr->maxUpload, callPtr); return -1; } cmdPtr->stats.uploadEnd = pss->stats.uploadEnd = time(NULL); lws_return_http_status(wsi, HTTP_STATUS_OK, NULL); goto try_to_reuse; case LWS_CALLBACK_HTTP_DROP_PROTOCOL: pss = jsi_wsgetPss(cmdPtr, wsi, user, 0, 1); if (pss && pss->spa) { lws_spa_destroy(pss->spa); pss->spa = NULL; } break; #endif case LWS_CALLBACK_HTTP_FILE_COMPLETION: goto try_to_reuse; case LWS_CALLBACK_HTTP_WRITEABLE: { lwsl_info("LWS_CALLBACK_HTTP_WRITEABLE\n"); if (!pss) pss = jsi_wsgetPss(cmdPtr, wsi, user, 0, 1); if (!pss || !pss->fop_fd) goto try_to_reuse; /* * we can send more of whatever it is we were sending */ int sent = 0; unsigned char buffer[JSI_BUFSIZ*10 + LWS_PRE]; do { int n = sizeof(buffer) - LWS_PRE; int m = lws_get_peer_write_allowance(wsi); if (m == 0) goto later; if (m != -1 && m < n) n = m; lws_filepos_t amount = 0; n = lws_vfs_file_read(pss->fop_fd, &amount, buffer + LWS_PRE, n); if (n < 0) { lwsl_err("problem reading file\n"); goto bail; } n = (int)amount; if (n == 0) goto penultimate; /* * To support HTTP2, must take care about preamble space * * identification of when we send the last payload frame * is handled by the library itself if you sent a * content-length header */ m = jsi_wswrite(pss, wsi, buffer + LWS_PRE, n, LWS_WRITE_HTTP); if (m < 0) { lwsl_err("write failed\n"); /* write failed, close conn */ goto bail; } if (m) /* while still active, extend timeout */ lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT, 5); sent += m; } while (!lws_send_pipe_choked(wsi) && (sent < 500 * 1024 * 1024)); later: lws_callback_on_writable(wsi); break; penultimate: lws_vfs_file_close(&pss->fop_fd); goto try_to_reuse; bail: lws_vfs_file_close(&pss->fop_fd); rc = -1; goto doret; } default: break; } goto doret; try_to_reuse: if (lws_http_transaction_completed(wsi)) rc = -1; else rc = 0; goto doret; doret: if (cmdPtr->debug>2) fprintf(stderr, "<---HTTP RET = %d\n", rc); return rc; }
CWE-120
null
520,448
302465734015219008922300798138494537431
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
RebuildTable(Jsi_Hash *tablePtr) { Jsi_HashEntry **bucketPtr, **oldBuckets; Jsi_HashEntry **oldChainPtr, **endPtr; Jsi_HashEntry *hPtr, *nextPtr; size_t hindex; oldBuckets = tablePtr->buckets; endPtr = tablePtr->buckets + tablePtr->numBuckets; tablePtr->numBuckets <<= 2; tablePtr->buckets = (Jsi_HashEntry**)Jsi_Calloc(tablePtr->numBuckets, sizeof(Jsi_HashEntry *)); tablePtr->rebuildSize <<= 2; tablePtr->downShift -= 2; tablePtr->mask = tablePtr->numBuckets - 1; if (tablePtr->keyType == JSI_KEYS_ONEWORD) { for (oldChainPtr = oldBuckets; oldChainPtr < endPtr; oldChainPtr++) { for (hPtr = *oldChainPtr; hPtr != NULL; hPtr = nextPtr) { nextPtr = hPtr->nextPtr; hindex = RANDOM_INDEX(tablePtr, hPtr->key.oneWordValue); bucketPtr = tablePtr->buckets + hindex; hPtr->nextPtr = *bucketPtr; *bucketPtr = hPtr; } } } else { for (oldChainPtr = oldBuckets; oldChainPtr < endPtr; oldChainPtr++) { for (hPtr = *oldChainPtr; hPtr != NULL; hPtr = nextPtr) { nextPtr = hPtr->nextPtr; hindex = hPtr->hval & tablePtr->mask; bucketPtr = tablePtr->buckets + hindex; hPtr->nextPtr = *bucketPtr; *bucketPtr = hPtr; } } } if (oldBuckets != tablePtr->staticBuckets) { Jsi_Free(oldBuckets); } }
CWE-120
null
520,449
330756976485132373981298430915106024684
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
bool Jsi_NumberIsFinite(Jsi_Number value) { Jsi_Number r = INFINITY; return (Jsi_NumberIsNaN(value)==0 && value != r && r != -value); }
CWE-120
null
520,450
154528171306809030288727101843674627751
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
Jsi_RC Jsi_GetLongFromValue(Jsi_Interp* interp, Jsi_Value *value, long *n) { /* TODO: inefficient to convert to double then back. */ if (!value) return JSI_ERROR; if (!interp->strict) jsi_ValueToOInt32(interp, value); if (!Jsi_ValueIsNumber(interp, value)) return Jsi_LogError("invalid number"); *n = (long)(value->vt == JSI_VT_NUMBER ? value->d.num : value->d.obj->d.num); return JSI_OK; }
CWE-120
null
520,451
274943725975081499911915989891922558645
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
const char* Jsi_ValueToString(Jsi_Interp *interp, Jsi_Value *v, int *lenPtr) { Jsi_Number d; const char *ntxt = "undefined"; int kflag = 1; int isKey = 0; char *key = NULL; if (!v) goto done; if (lenPtr) *lenPtr = 0; char unibuf[JSI_MAX_NUMBER_STRING*2]; switch(v->vt) { case JSI_VT_STRING: ntxt = v->d.s.str; goto done; case JSI_VT_UNDEF: break; case JSI_VT_BOOL: ntxt = v->d.val ? "true":"false"; break; case JSI_VT_NULL: ntxt = "null"; break; case JSI_VT_NUMBER: { d = v->d.num; fmtnum: if (Jsi_NumberIsInteger(d)) { Jsi_NumberItoA10((Jsi_Wide)d, unibuf, sizeof(unibuf)); kflag = 0; ntxt = unibuf; } else if (Jsi_NumberIsNormal(d)) { Jsi_NumberDtoA(interp, d, unibuf, sizeof(unibuf), 0); kflag = 0; ntxt = unibuf; } else if (Jsi_NumberIsNaN(v->d.num)) { ntxt = "NaN"; } else { int s = Jsi_NumberIsInfinity(d); if (s > 0) ntxt = "Infinity"; else if (s < 0) ntxt = "-Infinity"; else Jsi_LogBug("Ieee function got problem"); } break; } case JSI_VT_OBJECT: { Jsi_Obj *obj = v->d.obj; switch(obj->ot) { case JSI_OT_STRING: ntxt = obj->d.s.str; goto done; case JSI_OT_BOOL: ntxt = obj->d.val ? "true":"false"; break; case JSI_OT_NUMBER: d = obj->d.num; goto fmtnum; break; default: ntxt = "[object Object]"; break; } break; } default: Jsi_LogBug("Convert a unknown type: 0x%x to string", v->vt); break; } Jsi_ValueReset(interp, &v); if (!kflag) { Jsi_ValueMakeStringDup(interp, &v, ntxt); return Jsi_ValueString(interp, v, lenPtr); } key = jsi_KeyFind(interp, ntxt, 0, &isKey); if (key) Jsi_ValueMakeStringKey(interp, &v, key); else Jsi_ValueMakeString(interp, &v, ntxt); ntxt = v->d.s.str; done: if (lenPtr) *lenPtr = Jsi_Strlen(ntxt); return ntxt; }
CWE-120
null
520,452
159998087570346161231961304067969804051
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static Jsi_RC StringSearchCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this, Jsi_Value **ret, Jsi_Func *funcPtr) { int sLen, bLen; const char *source_str; ChkString(_this, funcPtr, source_str, &sLen, &bLen); char *v = _this->d.obj->d.s.str; Jsi_Value *seq = Jsi_ValueArrayIndex(interp, args, skip); if (Jsi_ValueIsString(interp, seq)) { char *ce, *cp = Jsi_ValueString(interp, seq, NULL); int n = -1; if ((ce = Jsi_Strstr(source_str, cp))) { n = (ce-source_str); } Jsi_ValueMakeNumber(interp, ret, n); return JSI_OK; } if (!seq || seq->vt != JSI_VT_OBJECT || seq->d.obj->ot != JSI_OT_REGEXP) { Jsi_ValueMakeNumber(interp, ret, -1); return JSI_OK; } regex_t *reg = &seq->d.obj->d.robj->reg; regmatch_t pos[MAX_SUBREGEX] = {}; int r; if ((r = regexec(reg, v, MAX_SUBREGEX, pos, 0)) != 0) { if (r == REG_NOMATCH) { Jsi_ValueMakeNumber(interp, ret, -1.0); return JSI_OK; } if (r >= REG_BADPAT) { char buf[JSI_MAX_NUMBER_STRING]; regerror(r, reg, buf, sizeof(buf)); Jsi_LogError("error while matching pattern: %s", buf); return JSI_ERROR; } } Jsi_ValueMakeNumber(interp, ret, (Jsi_Number)pos[0].rm_so); return JSI_OK; }
CWE-120
null
520,453
287381744637863968186883461633479479353
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
Jsi_RC jsi_ArgTypeCheck(Jsi_Interp *interp, int typ, Jsi_Value *arg, const char *p1, const char *p2, int index, Jsi_Func *func, bool isdefault) { Jsi_RC rc = JSI_OK; char idxBuf[JSI_MAX_NUMBER_STRING*2]; idxBuf[0] = 0; if (func && arg->vt == JSI_VT_UNDEF && !interp->typeCheck.noundef && index>0 && !isdefault && !(typ&JSI_TT_UNDEFINED)) { snprintf(idxBuf, sizeof(idxBuf), " arg %d", index); jsi_TypeMismatch(interp); Jsi_DString fStr = {}; rc = Jsi_LogType("call with undefined var %s%s '%s'%s", p1, idxBuf, p2, jsiFuncInfo(interp, &fStr, func, arg)); Jsi_DSFree(&fStr); return rc; } if (typ <= 0) return JSI_OK; //if (typ&JSI_TT_VOID) // return JSI_OK; if (interp->typeCheck.all==0) { if (func ? (interp->typeCheck.run==0) : (interp->typeCheck.parse==0)) return JSI_OK; } if (index == 0 && func && func->type == FC_BUILDIN && interp->typeCheck.all == 0) // Normally do not check return types for builtins. return JSI_OK; if ((typ&JSI_TT_ANY)) return JSI_OK; if (index == 0 && arg->vt == JSI_VT_UNDEF) { if (!(typ&JSI_TT_VOID)) goto done; return JSI_OK; } if (isdefault && index && typ&JSI_TT_VOID && arg->vt == JSI_VT_UNDEF) return JSI_OK; if (typ&JSI_TT_UNDEFINED && Jsi_ValueIsUndef(interp, arg)) return rc; if (typ&JSI_TT_NUMBER && Jsi_ValueIsNumber(interp, arg)) return rc; if (typ&JSI_TT_STRING && Jsi_ValueIsString(interp, arg)) return rc; if (typ&JSI_TT_BOOLEAN && Jsi_ValueIsBoolean(interp, arg)) return rc; if (typ&JSI_TT_ARRAY && Jsi_ValueIsArray(interp, arg)) return rc; if (typ&JSI_TT_FUNCTION && Jsi_ValueIsFunction(interp, arg)) return rc; if (typ&JSI_TT_REGEXP && Jsi_ValueIsObjType(interp, arg, JSI_OT_REGEXP)) return rc; if (typ&JSI_TT_USEROBJ && Jsi_ValueIsObjType(interp, arg, JSI_OT_USEROBJ)) return rc; if (typ&JSI_TT_ITEROBJ && Jsi_ValueIsObjType(interp, arg, JSI_OT_ITER)) return rc; if (typ&JSI_TT_OBJECT && ( Jsi_ValueIsObjType(interp, arg, JSI_OT_OBJECT) && Jsi_ValueIsArray(interp, arg)==0)) return rc; if (typ&JSI_TT_NULL && Jsi_ValueIsNull(interp, arg)) return rc; done: { Jsi_DString dStr = {}; const char *exp = jsi_typeName(interp, typ, &dStr); const char *vtyp = jsi_ValueTypeName(interp, arg); if (index>0) snprintf(idxBuf, sizeof(idxBuf), " arg %d", index); if (interp->typeCheck.error) rc = JSI_ERROR; jsi_TypeMismatch(interp); Jsi_DString fStr = {}; rc = Jsi_LogType("type mismatch %s%s '%s': expected \"%s\" but got \"%s\"%s", p1, idxBuf, p2, exp, vtyp, jsiFuncInfo(interp, &fStr, func, arg)); Jsi_DSFree(&fStr); Jsi_DSFree(&dStr); } return rc; }
CWE-120
null
520,454
112720323101208891290078267307937844997
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static int jsi_wswrite(jsi_wsPss* pss, struct lws *wsi, unsigned char *buf, int len, enum lws_write_protocol proto) { jsi_wsCmdObj *cmdPtr = pss->cmdPtr; int m = lws_write(wsi, buf, len, proto); if (m >= 0) { cmdPtr->stats.sentCnt++; cmdPtr->stats.sentLast = time(NULL); pss->stats.sentCnt++; pss->stats.sentLast = time(NULL); } else { pss->state = PWS_SENDERR; pss->stats.sentErrCnt++; pss->stats.sentErrLast = time(NULL); cmdPtr->stats.sentErrCnt++; cmdPtr->stats.sentErrLast = time(NULL); } return m; }
CWE-120
null
520,455
273336984517766203409372505633181627913
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static Jsi_RC jsi_ValueAssignCheck(Jsi_Interp *interp, Jsi_Value *val, int lop) { if (lop == OP_FCALL || lop == OP_NEWFCALL) return JSI_OK; if (val->f.bits.lookupfailed && val->d.lookupFail) return Jsi_LogType("assign from undef var: %s", val->d.lookupFail); return JSI_OK; }
CWE-120
null
520,456
107291985666001981235813982214067480194
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static Jsi_RC InterpUplevelCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this, Jsi_Value **ret, Jsi_Func *funcPtr) { return InterpEvalCmd_(interp, args, _this, ret, funcPtr, 1); }
CWE-120
null
520,457
242471715497755455267687859183747309377
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static Jsi_RC mdbPrepareStmt(MyDbEvalContext *p) { MySqlObj *jdb = p->jdb; //int namedParams = !jdb->optPtr->noNamedParams; const char *zSql = p->zSql; /* Pointer to first SQL statement in zIn */ MYSQL_STMT *myStmt; /* Prepared statement object */ MysqlPrep *prep = 0; /* Pointer to cached statement */ Jsi_RC rc = JSI_OK; Jsi_Interp *interp = jdb->interp; Jsi_HashEntry *entry = Jsi_HashEntryFind(jdb->stmtHash, zSql); if (entry && ((prep = (MysqlPrep*)Jsi_HashValueGet(entry)))) { if (jdb->debug & mdbTMODE_PREPARE) JSI_DBQUERY_PRINTF( "DEBUG: prepare cache-hit: %s\n", zSql); myStmt = prep->myStmt; /* When a prepared statement is found, unlink it from the ** cache list. It will later be added back to the beginning ** of the cache list in order to implement LRU replacement. */ Jsi_ListPop(jdb->stmtCache, prep->elPtr); jdb->numStmts = Jsi_ListSize(jdb->stmtCache); // Sanity check for schema check: right now we just use number of columns if (prep->numCol != (int)mysql_stmt_field_count(prep->myStmt)) { mdbRelease1Stmt(jdb, prep); prep = NULL; } } /* If no prepared statement was found. Compile the SQL text. Also allocate ** a new MysqlPrep structure. */ if (!prep) { myStmt = mysql_stmt_init(jdb->db); if (!myStmt) return Jsi_LogError("can't get statement: %s", mysql_error(jdb->db)); char **paramNames; int paramCnt; int namedParams = 0; Jsi_DString *naStr = NULL; if (p->namedParams) { Jsi_RC rc = JSI_OK; Jsi_DString nsStr, nnStr; Jsi_DSInit(&nsStr); Jsi_DSInit(&nnStr); if (MySqlExtractParmNames(jdb, zSql, &nsStr, &nnStr) != JSI_OK) rc = Jsi_LogError("parsing names from query: %s", zSql); else if (Jsi_DSLength(&nnStr)) { namedParams = 1; zSql = Jsi_DSFreeDup(&nsStr); naStr = (Jsi_DString*)Jsi_Calloc(1, sizeof(*naStr)); Jsi_SplitStr(Jsi_DSValue(&nnStr), &paramCnt, &paramNames, " ", naStr); } Jsi_DSFree(&nsStr); Jsi_DSFree(&nnStr); if (rc != JSI_OK) return rc; } if (mysql_stmt_prepare(myStmt, zSql, Jsi_Strlen(zSql)) ) { Jsi_LogError("error in sql: %s", mysql_error(jdb->db)); mysql_stmt_close(myStmt); if (namedParams) { Jsi_DSFree(naStr); Jsi_Free(naStr); Jsi_Free((char*)zSql); } return JSI_ERROR; } if (jdb->debug & mdbTMODE_PREPARE) JSI_DBQUERY_PRINTF( "DEBUG: prepare new: %s\n", zSql); assert( prep==0 ); prep = (MysqlPrep*)Jsi_Calloc(1, sizeof(MysqlPrep)); jdb->numStmts++; prep->sig = MYSQL_SIG_STMT; prep->myStmt = myStmt; if (!namedParams) prep->zSql = Jsi_Strdup(zSql); else { prep->zSql = (char*)zSql; prep->origSql = Jsi_Strdup(p->zSql); prep->naStr = naStr; prep->paramCnt = paramCnt; prep->paramNames = paramNames; } prep->paramMetaData = mysql_stmt_param_metadata(myStmt); prep->resultMetaData = mysql_stmt_result_metadata(myStmt); prep->numCol = mysql_stmt_field_count(myStmt); if (prep->numCol>0) prep->bindResult = (MYSQL_BIND *)Jsi_Calloc(prep->numCol, sizeof(MYSQL_BIND)); prep->numParam = mysql_stmt_param_count(myStmt); if (prep->numParam>0 && !prep->bindParam) { prep->bindParam = (MYSQL_BIND *)Jsi_Calloc(prep->numParam, sizeof(MYSQL_BIND)); prep->fieldParam = (SqlFieldResults*)Jsi_Calloc(prep->numParam, sizeof(*prep->fieldParam)); } bool isNew = 0; prep->entry = Jsi_HashEntryNew(jdb->stmtHash, p->zSql, &isNew); if (!isNew) JSI_DBQUERY_PRINTF( "mysql dup stmt entry"); Jsi_HashValueSet(prep->entry, prep); } p->prep = prep; return rc; }
CWE-120
null
520,458
186386803950289673732433170924310046019
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static void jsiVarDeref(Jsi_Interp* interp, int n) { while(interp->framePtr->Sp<n) // Assert and Log may map-out Ops. jsiPush(interp, 1); int i; for (i=1; i<=n; i++) { Jsi_Value *vb = _jsi_STACKIDX(interp->framePtr->Sp - i); if (vb->vt == JSI_VT_VARIABLE) { SIGASSERTV(vb->d.lval, VALUE); Jsi_ValueCopy(interp, vb, vb->d.lval); } } }
CWE-120
null
520,459
71774104416711970669713013539219557516
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
bool Jsi_NumberIsSafeInteger(Jsi_Number n) { Jsi_Number n1 = fabsl(n), n2 = 9007199254740991LL; return (Jsi_NumberIsInteger(n) && n1<=n2); }
CWE-120
null
520,460
198508689822744376619530414122573632229
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static char *FindEndB(char *cp) { if (*cp == '\"'||*cp == '\'') { char endc = *cp; cp++; while (*cp && *cp != endc) { if (*cp == '\\' && cp[1]) cp++; cp++; } if (*cp == endc) cp++; if (*cp != ']') return NULL; return cp; } else return Jsi_Strchr(cp, ']'); }
CWE-120
null
520,461
56962639473270272380343511154845565534
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static Jsi_RC MySqlCompleteCmd(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_Value *s = Jsi_ValueArrayIndex(interp, args, 0); const char *str = Jsi_ValueString(interp, s, NULL); int isComplete = 0; if (str) isComplete = 0; // sqlite3_complete( str ); Jsi_ValueMakeBool(interp, ret, isComplete); return JSI_OK; }
CWE-120
null
520,462
244528391158639107814817697896182170115
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
void jsi_ValueDebugUpdate_(Jsi_Interp *interp, jsi_ValueDebug *vd, void *v, Jsi_Hash* tbl, const char *fname, int line, const char *func) { vd->fname = fname; vd->line = line; vd->func = func; if (!vd->Idx) vd->Idx = interp->dbPtr->memDebugCallIdx; vd->hPtr = Jsi_HashSet(tbl, v, 0); vd->ip = interp->curIp; if (vd->ip) { vd->ipLine = vd->ip->Line; vd->ipOp = vd->ip->op; vd->ipFname = vd->ip->fname; } vd->interp = interp; if (jsi_memDebugBreakIdx && jsi_memDebugBreakIdx == vd->Idx) jsi_memDebugBreak(); }
CWE-120
null
520,463
212526997678165034470673905373524921753
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static void jsi_ParentFuncFree(Jsi_Interp *interp, Jsi_OptionSpec* spec, void *ptr) { Jsi_Value **v = (Jsi_Value **)(((char*)ptr)); if (!interp->parent) return; if (*v) Jsi_DecrRefCount(interp->parent, *v); *v = NULL; }
CWE-120
null
520,464
286444013078037009904540901078731434103
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
char jsi_fromHexChar(char ch) { return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10; }
CWE-120
null
520,465
246465926140283177783843970836217769351
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static void mdbOutputHtmlString(QueryOpts *p, const char *z, Jsi_DString *dStr) { while( *z ) { switch (*z) { case '<': Jsi_DSAppend(dStr, "&lt;", NULL); break; case '>': Jsi_DSAppend(dStr, "&gt;", NULL); break; case '&': Jsi_DSAppend(dStr, "&amp;", NULL); break; case '\"': Jsi_DSAppend(dStr, "&quot;", NULL); break; case '\'': Jsi_DSAppend(dStr, "&#39;", NULL); break; default: Jsi_DSAppendLen(dStr, z, 1); break; } z++; } }
CWE-120
null
520,466
149493267341008908484789661854158728773
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
bool Jsi_ValueIsType(Jsi_Interp *interp, Jsi_Value *pv, Jsi_vtype vtype) { if (!pv) return 0; return pv->vt == vtype; }
CWE-120
null
520,467
154982128819222533787616128216485051792
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
char* Jsi_ValueGetStringLen(Jsi_Interp *interp, Jsi_Value *pv, int *lenPtr) { if (!pv) return NULL; Jsi_String *s = jsi_ValueString(pv); if (!s) return NULL; if (lenPtr) *lenPtr = (s->len<0 ? (int)Jsi_Strlen(s->str) : s->len); return s->str; }
CWE-120
null
520,468
274397401523690373710900209900667632360
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static Jsi_Value *ValueNew(Jsi_Interp *interp) { interp->dbPtr->valueCnt++; interp->dbPtr->valueAllocCnt++; Jsi_Value *v = (Jsi_Value *)Jsi_Calloc(1,sizeof(*v)); SIGINIT(v,VALUE) v->vt = JSI_VT_UNDEF; jsi_DebugValue(v,"New", jsi_DebugValueCallIdx(), interp); return v; }
CWE-120
null
520,469
209224706117467768166375157931500076649
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static Jsi_RC MySqlResetCmd(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; #if (MYSQL_VERSION_ID >= 50703 && !defined(JSI_NO_MYSQL_RESET)) int oldMax = jdb->maxStmts; jdb->maxStmts = 0; mdbStmtLimit(jdb); jdb->maxStmts = oldMax; Jsi_ValueMakeNumber(interp, ret, (Jsi_Number)mysql_reset_connection(jdb->db)); #else Jsi_LogWarn("mysql reset unavailable: requires version 5.7.3+"); #endif return JSI_OK; }
CWE-120
null
520,470
324325079668882400546477014068530486182
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
void Jsi_ListDelete(Jsi_List *list) { Jsi_ListClear(list); free(list); }
CWE-120
null
520,471
40801885678234040498760284748196522913
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
jsi_SetOption(Jsi_Interp *interp, Jsi_OptionSpec *specPtr, const char *string /*UNUSED*/, void* rec, Jsi_Value *argValue, Jsi_Wide flags, bool isSafe) { Jsi_Value *oa = interp->lastParseOpt; interp->lastParseOpt = argValue; Jsi_RC rc = jsi_SetOption_(interp, specPtr, string, rec, argValue, flags, isSafe); interp->lastParseOpt = oa; return rc; }
CWE-120
null
520,472
41364219066638930800250460273672947617
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
Jsi_ScopeStrs *jsi_ArgsOptAdd(jsi_Pstate *pstate, Jsi_ScopeStrs *a) { jsi_PstatePush(pstate); return a; }
CWE-120
null
520,473
332957281436607071517609720973282662619
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
const char* Jsi_DbKeyAdd(Jsi_Db *jdb, const char *str) { #ifndef JSI_LITE_ONLY if (jdb->interp) return Jsi_KeyAdd(jdb->interp, str); #endif Jsi_HashEntry *hPtr; bool isNew; hPtr = Jsi_HashEntryNew(jdb->strKeyTbl, str, &isNew); assert(hPtr) ; return (const char*)Jsi_HashKeyGet(hPtr); }
CWE-120
null
520,474
308287123385573327503428821693054445717
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
int jsi_ValueToOInt32(Jsi_Interp *interp, Jsi_Value *v) { Jsi_Number a = Jsi_ValueToNumberInt(interp, v, 1); Jsi_ValueReset(interp,&v); Jsi_ValueMakeNumber(interp, &v, a); return (int)a; }
CWE-120
null
520,475
19284955760031127969067188541044248964
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
Jsi_Value * jsi_ValueDup(Jsi_Interp *interp, Jsi_Value *ov, const char *fname, int line, const char *func) { Jsi_Value *v = ValueDup(interp, ov); jsi_ValueDebugUpdate(interp, v, valueDebugTbl, fname, line, func); return v; }
CWE-120
null
520,476
306432218351828179681834243767673709164
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static Jsi_OpCodes *code_push_top() { JSI_NEW_CODES(0,OP_PUSHTOP, 0); }
CWE-120
null
520,477
8903632351864243518137664576075254964
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static int jsi_FSFlushProc(Jsi_Channel chan) { return fflush(_JSI_GETFP(chan,0));}
CWE-120
null
520,478
83672005130503349637988261730825697019
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
Jsi_RC jsi_RunFuncCallCheck(Jsi_Interp *interp, Jsi_Func *func, int argc, const char *name, jsi_Pline *line, Jsi_OpCodes *argCodes, bool isParse) { Jsi_RC rc = JSI_OK; if (interp->typeCheck.all==0) { if (!argCodes ? (interp->typeCheck.run==0) : (interp->typeCheck.parse==0)) return JSI_OK; } Jsi_CmdSpec *spec = func->cmdSpec; Jsi_ScopeStrs *ss = func->argnames; if (ss==NULL && spec == NULL) return JSI_OK; int i, minArgs, maxArgs, mis = 0, varargs = 0; char nbuf[JSI_MAX_NUMBER_STRING]; if (func->type == FC_BUILDIN) { varargs = (spec->maxArgs<0); maxArgs = spec->maxArgs + func->callflags.bits.addargs; minArgs = spec->minArgs + func->callflags.bits.addargs; } else { varargs = ss->varargs; minArgs = (ss->firstDef>0 ? ss->firstDef-1 : ss->count); maxArgs = ss->count; mis = (argc != ss->count); if (func->retType == 0 && ss && ss->typeCnt == 0 && interp->typeCheck.all==0) return JSI_OK; } if (varargs) { if (argc >= minArgs) return JSI_OK; mis = (argc<minArgs); } else mis = (argc<minArgs || argc>maxArgs); if (mis) { if (varargs) snprintf(nbuf, sizeof(nbuf), "%d or more", minArgs); else if (maxArgs > minArgs) snprintf(nbuf, sizeof(nbuf), "%d-%d", minArgs, maxArgs); else snprintf(nbuf, sizeof(nbuf), "%d", maxArgs); if (line) interp->parseLine = line; if (interp->typeCheck.error) rc = JSI_ERROR; Jsi_DString dStr = {}; Jsi_FuncObjToString(interp, func, &dStr, 2); if (isParse) Jsi_LogWarn("got %d args, expected %s, calling %s", argc, nbuf, Jsi_DSValue(&dStr)); else rc = Jsi_LogType("got %d args, expected %s, calling %s", argc, nbuf, Jsi_DSValue(&dStr)); jsi_TypeMismatch(interp); Jsi_DSFree(&dStr); if (line) interp->parseLine = NULL; return rc; } if (argCodes && argCodes->code_len>=argc) { int cl = argCodes->code_len; int aind=argc-1; for (i=cl-1; rc == JSI_OK && i>=0 && aind>=0; i--,aind--) { Jsi_ttype atyp = JSI_TT_ANY; switch (argCodes->codes[i].op) { case OP_PUSHSTR: atyp=JSI_TT_STRING; break; case OP_PUSHNUM: atyp=JSI_TT_NUMBER; break; case OP_PUSHBOO: atyp=JSI_TT_BOOLEAN; break; case OP_PUSHFUN: atyp=JSI_TT_FUNCTION; break; case OP_PUSHTHS: atyp=JSI_TT_OBJECT; break; case OP_PUSHREG: atyp=JSI_TT_REGEXP; break; case OP_PUSHUND: atyp=JSI_TT_VOID; break; case OP_PUSHNULL: atyp=JSI_TT_NULL; break; case OP_PUSHARG: atyp=JSI_TT_ARRAY; break; case OP_SUBSCRIPT: i++; break; case OP_ARRAY: atyp=JSI_TT_ARRAY; i=jsiPopArgs(argCodes, i); break; case OP_OBJECT: atyp=JSI_TT_OBJECT; i=jsiPopArgs(argCodes, i); break; default: break; } if (atyp == JSI_TT_ANY) continue; rc = jsi_StaticArgTypeCheck(interp, atyp, "for argument", name, aind+1, func, line); } } return rc; }
CWE-120
null
520,479
145025284338379013388097952500117841917
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static Jsi_RC SqliteExistsCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this, Jsi_Value **ret, Jsi_Func *funcPtr) { Jsi_RC rc; Jsi_Db *jdb; if (!(jdb = dbGetDbHandle(interp, _this, funcPtr))) return JSI_ERROR; Jsi_Value *vSql = Jsi_ValueArrayIndex(interp, args, 0); const char *zSql; Jsi_DString dStr = {}; DbEvalContext sEval = {}; zSql = Jsi_ValueGetDString(interp, vSql, &dStr, 0); Jsi_DString sStr; Jsi_DSInit(&sStr); sEval.nocache = jdb->queryOpts.nocache; if (dbEvalInit(interp, &sEval, jdb, zSql, &sStr, 0, 0) != JSI_OK) return JSI_ERROR; sEval.ret = *ret; int cnt = 0; if( JSI_OK==(rc = dbEvalStep(&sEval)) ) { sqlite3_stmt *pStmt = sEval.pPreStmt->pStmt; int nCol = sqlite3_column_count(pStmt); if (nCol>0) cnt++; } dbEvalFinalize(&sEval); if( rc==JSI_BREAK ) { rc = JSI_OK; } Jsi_DSFree(&dStr); Jsi_ValueMakeBool(interp, ret, cnt); return rc; }
CWE-120
null
520,480
129534265293207774780753706771980283612
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
Jsi_Value* Jsi_ValueMakeUndef(Jsi_Interp *interp, Jsi_Value **vPtr) { Jsi_Value *v = (vPtr?*vPtr:NULL); if (!v) v = Jsi_ValueNew(interp); else { if (v->vt == JSI_VT_UNDEF) return v; Jsi_ValueReset(interp, vPtr); } return v; }
CWE-120
null
520,481
80725869300438381730115626941102544340
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static void jsi_SuboptFree(Jsi_Interp *interp, Jsi_OptionSpec* spec, void *ptr) { Jsi_OptionSpec *subspec = (Jsi_OptionSpec *)spec->data; Jsi_OptionsFree(interp, subspec, ptr, 0); }
CWE-120
null
520,482
121332241911019783977065959001611543958
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static Jsi_RC MutexLock(Jsi_Interp *interp, Jsi_Mutex *mtx) { int timeout = mtx->lockTimeout; if (interp && timeout<0) timeout = interp->lockTimeout; if (timeout<=0) pthread_mutex_lock(&mtx->mtx); else { struct timespec ts; ts.tv_sec = timeout/1000; ts.tv_nsec = 1000 * (timeout%1000); int rc = pthread_mutex_timedlock(&mtx->mtx, &ts); if (rc != 0) { Jsi_LogError("lock timed out"); if (interp) interp->threadErrCnt++; mtx->threadErrCnt++; return JSI_ERROR; } } return JSI_OK; }
CWE-120
null
520,483
41364850643677389129160844659807354290
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
Jsi_Wide Jsi_Seek(Jsi_Interp *interp, Jsi_Channel chan, Jsi_Wide offset, int mode) { if (chan->fsPtr==0 || !chan->fsPtr->seekProc) return -1; return chan->fsPtr->seekProc(chan, offset, mode); }
CWE-120
null
520,484
114543829470923038705559542794401187950
null
null
other
jsish
430ea27accd4d4ffddc946c9402e7c9064835a18
0
static Jsi_RC inline jsi_ValueAssign(Jsi_Interp *interp, Jsi_Value *dst, Jsi_Value* src, int lop) { Jsi_Value *v; if (dst->vt != JSI_VT_VARIABLE) { if (interp->strict) return Jsi_LogError("operand not a left value"); } else { v = dst->d.lval; SIGASSERT(v, VALUE); int strict = interp->strict; if (strict && lop == OP_PUSHFUN && interp->curIp[-1].local) dst->f.bits.local = 1; if (strict && dst->f.bits.local==0) { const char *varname = ""; if (v->f.bits.lookupfailed) varname = v->d.lookupFail; Jsi_RC rc = Jsi_LogType("function created global: \"%s\"", varname); dst->f.bits.local=1; if (rc != JSI_OK) return rc; } if (v == src) return JSI_OK; if (v->f.bits.readonly) { if (interp->strict) return Jsi_LogError("assign to readonly variable"); return JSI_OK; } if (Jsi_ValueIsFunction(interp, src)) Jsi_ValueMove(interp,v, src); else Jsi_ValueCopy(interp,v, src); SIGASSERT(v, VALUE); v->f.bits.readonly = 0; #ifdef JSI_MEM_DEBUG if (!v->VD.label2) v->VD.label2 = "ValueAssign"; #endif } return JSI_OK; }
CWE-120
null
520,485
69435663550151843616623351673940489861
null
null
other