summaryrefslogtreecommitdiffhomepage
path: root/tests/custom/99_bugs
AgeCommit message (Collapse)Author
2024-12-06lexer: Preserve keyword, regexp flags until processing non-comment tokensJo-Philipp Wich
When the lexer has either the `no_keyword` or `no_regexp` flag set, it should retain these flags until it encounters a non-comment token. Only then should it stop preventing the interpretation of tokens beginning with a letter or forward slash as keywords or regular expression literals, respectively. Previously, these flags were being reset too early when processing comments, which could cause incorrect parsing when comments appeared between relevant tokens. The flags should only be reset after consuming an actual non-comment token to ensure consistent parsing behavior. Fixes: #250 Fixes: 855854f ("lexer: emit comment and template statement block tokens") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-11-29vm: resolve upvalues before pushing them onto the stackJo-Philipp Wich
Commit e5fe6b1 ("treewide: refactor vector usage code") accidentially dropped the upvalue resolving logic from uc_vm_stack_push(), leading to unresolved upvalues leaking into the script execution context. Fixes: e5fe6b1 ("treewide: refactor vector usage code") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-10-17Merge pull request #239 from jow-/safe-insert-during-obj-iterationJo-Philipp Wich
types: fix potential use after free on adding keys during iteration
2024-10-17types: fix potential use after free on adding keys during iterationJo-Philipp Wich
When keys are added to the object currently being iterated by a for loop, the insert operation might cause a hashtable resize with a subsequent memory reallocation and a different table base pointer, clobbering the entry pointers held by iterators pointing to the containing object of the resized table. In order to address this issue while keeping the iteration overhead low, extend the object key insert logic to check whether the insertion will trigger a reallocation and backup and restore the iterator pointers when needed. This slightly increases the size of the iterator states but the overhead for this should be neglectible as there'll only be a low amount of concurrently active iterations at any time. Fixes: #230 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-10-16vallist: more thoroughly check for trailing garbage after numeric stringJo-Philipp Wich
When converting numeric strings into numbers, ensure that only optional trailing whitespace follows and no other characters. Fixes: #231 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-09-23compiler: properly treat property names after spread expressionsJo-Philipp Wich
Ensure that unquoted property names following spread expressions in object declaration literals are not treated as keywords. Prior to this fix, an expression such as `{ ...someobj, default: 1 }` would result in a compile time syntax error. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-09-20lib: test if call to getenv() destroys environMikael Magnusson
Signed-off-by: Mikael Magnusson <mikma@users.sourceforge.net>
2024-02-13compiler: close upvalues on loop control statementsFelix Fietkau
When removing locals from all scopes, upvalues need to be considered like in uc_compiler_leave_scope(). Closing them is required to avoid leaving lingering references to stack values that went out of scope, which would lead to invalid memory accesses in subsequent code when such upvalues are used by closures. Fixes: #187 Signed-off-by: Felix Fietkau <nbd@nbd.name> [add testcase, reword commit message] Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-11-06syntax: don't treat `as` and `from` as reserved keywordsJo-Philipp Wich
ECMAScript allows using `as` and `from` as identifiers so follow suit and don't treat them specially while parsing. Extend the compiler logic instead to check for TK_LABEL tokens with the expected value to properly parse import and export statements. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-10-09types: ensure double serializatiion with decimal placesJo-Philipp Wich
The `%g` printf format used for serializing double values into strings will not include any decimal place if the value happens to be integral, leading to an unwanted double to integer conversion when serializing and subsequently deserializing an integral double value as JSON. Solve this issue by checking the serialized string result for a decimal point or exponential notation and appending `.0` if neither is found. Ref: #173 Suggested-by: Felix Fietkau <nbd@nbd.name> Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-08-22types: improve comparison reliability of binary stringsJo-Philipp Wich
The existing `ucv_compare()` implementation utilized `strcmp()` to compare two ucode string values, which may lead to incorrect results for strings containing null bytes as the comparison prematurely aborts when encountering the first null. Rework the string comparison logic to use `memcmp()` for comparing both ucv strings with each other in order to ensure that expressions such as `"" == "\u0000"` lead to the expected `false` result. Ref: https://github.com/openwrt/luci/issues/6530 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-07-12source: fix source offset accountingJo-Philipp Wich
- When skipping the interpreter line, don't count it's newline twice - Fix reporting byte offsets beyond the end of line Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-10-04compiler: optimize function return opcode generationJo-Philipp Wich
Track last emitted statement type in compiled code and only generate final `return null` opcodes if there is no preceeding `return` statement. Also use this statement tracking to avoid emitting invalid return opcodes for arrow function bodies with trailing empty statements. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-07-30compiler: add support for import/export statementsJo-Philipp Wich
This commit introduces syntax level support for ES6 style module import and export statements. Imports are resolved at compile time and the corresponding module code is compiled into the main program. Also add testcases to cover import and export statement semantics. Signed-off-by: Jo-Philipp Wich <jo@mein.io>