Please help to unmask rogue native message.
In the chain of message exchange between webExt and Native messaging host I randomly get a rogue message with the length bigger than max allowed. As NativeMessaging.jsm immediately throws an Exception, I have no clue about source of this weird message.
Thus I decided to debug Firefox upon loading my extension that uses a Native Host from about:debugging page.
Upon loading it, I open NativeMessaging.jsm in Debugger, where in advance I put a breakpoint on the line that suppose to throw an exception.
[from NativeMessaging.jsm]
Code: Select all
[size=85]_startRead() {
if (this.readPromise) {
throw new Error("Entered _startRead() while readPromise is non-null");
}
this.readPromise = this.proc.stdout
.readUint32()
.then(len => {
if (len > NativeApp.maxRead) {
*[breakpoint]* throw new this.context.cloneScope.Error(
`Native application tried to send a message of ${len} bytes, which exceeds the limit of ${
NativeApp.maxRead
} bytes.`
);
}
return this.proc.stdout.readJSON(len);
})
.then(msg => {
this.emit("message", msg);
this.readPromise = null;
this._startRead();
})
.catch(err => {
if (err.errorCode != Subprocess.ERROR_END_OF_FILE) {
Cu.reportError(err instanceof Error ? err : err.message);
}
this._cleanup(err);
});
}
When I get a breakpoint, I use a console to read a pipe partially in order to get some idea of this rogue message origin.
Taking into account that all read methods on InputPipe return Promise(subprocess_common.jsm), I issue the following command in console, while I am on breakpoint:
Code: Select all
this.proc.stdout.readString(256).then(res=>{console.log(res);})
What I am doing wrong. And why then method of Promise doesn't work?
How to do it correct way?
Regards, Arkady