Skip to content

Commit f2a8620

Browse files
fix: possible infinite loop when parsing option (#1923)
1 parent 42e5a9c commit f2a8620

File tree

6 files changed

+15
-9
lines changed

6 files changed

+15
-9
lines changed

bench/prof.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ function setupBrowser() {
8686
switch (process.argv[2]) {
8787
case "encode-browser":
8888
setupBrowser();
89-
// eslint-disable-line no-fallthrough
89+
// eslint-disable-next-line no-fallthrough
9090
case "encode":
9191
for (var i = 0; i < count; ++i)
9292
Test.encode(data).finish();
9393
break;
9494
case "decode-browser":
9595
setupBrowser();
96-
// eslint-disable-line no-fallthrough
96+
// eslint-disable-next-line no-fallthrough
9797
case "decode":
9898
var buf = Test.encode(data).finish();
9999
for (var j = 0; j < count; ++j)

cli/lib/tsd-jsdoc/publish.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ function handleElement(element, parent) {
438438
handleEnum(element, parent);
439439
break;
440440
}
441-
// eslint-disable-line no-fallthrough
441+
// eslint-disable-next-line no-fallthrough
442442
case "namespace":
443443
handleNamespace(element, parent);
444444
break;

src/converter.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
6262
break;
6363
case "uint64":
6464
isUnsigned = true;
65-
// eslint-disable-line no-fallthrough
65+
// eslint-disable-next-line no-fallthrough
6666
case "int64":
6767
case "sint64":
6868
case "fixed64":
@@ -176,7 +176,7 @@ function genValuePartial_toObject(gen, field, fieldIndex, prop) {
176176
break;
177177
case "uint64":
178178
isUnsigned = true;
179-
// eslint-disable-line no-fallthrough
179+
// eslint-disable-next-line no-fallthrough
180180
case "int64":
181181
case "sint64":
182182
case "fixed64":

src/parse.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ function parse(source, root, options) {
227227
break;
228228
case "public":
229229
next();
230-
// eslint-disable-line no-fallthrough
230+
// eslint-disable-next-line no-fallthrough
231231
default:
232232
whichImports = imports || (imports = []);
233233
break;
@@ -621,6 +621,9 @@ function parse(source, root, options) {
621621
if (!nameRe.test(token = next())) {
622622
throw illegal(token, "name");
623623
}
624+
if (token === null) {
625+
throw illegal(token, "end of input");
626+
}
624627

625628
var value;
626629
var propName = token;

tests/cli.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,14 @@ tape.test("pbjs generates static code with message filter", function (test) {
192192
var $protobuf = protobuf;
193193
eval(jsCode);
194194

195-
console.log(protobuf.roots);
196-
197195
var NeedMessage1 = protobuf.roots.default.filtertest.NeedMessage1;
198196
var NeedMessage2 = protobuf.roots.default.filtertest.NeedMessage2;
199197
var DependentMessage1 = protobuf.roots.default.filtertest.DependentMessage1;
200198
var DependentMessageFromImport = protobuf.roots.default.DependentMessageFromImport;
201199

202200
var NotNeedMessageInRootFile = protobuf.roots.default.filtertest.NotNeedMessageInRootFile;
203201
var NotNeedMessageInImportFile = protobuf.roots.default.NotNeedMessageInImportFile;
204-
202+
205203
test.ok(NeedMessage1, "NeedMessage1 is loaded");
206204
test.ok(NeedMessage2, "NeedMessage2 is loaded");
207205
test.ok(DependentMessage1, "DependentMessage1 is loaded");

tests/comp_options-parse.js

+5
Original file line numberDiff line numberDiff line change
@@ -157,5 +157,10 @@ tape.test("Options", function (test) {
157157
test.end();
158158
});
159159

160+
test.test(test.name + " - invalid option", function (test) {
161+
test.throws(() => { protobuf.parse("option (foo).whatever = {")});
162+
test.end();
163+
});
164+
160165
test.end();
161166
});

0 commit comments

Comments
 (0)