how to read a part of native message if its length exeeds ma

Discuss building things with or for the Mozilla Platform.
Post Reply
arkiof
Posts: 2
Joined: April 20th, 2021, 12:53 pm

how to read a part of native message if its length exeeds ma

Post by arkiof »

Hi
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);
      });
  }
[/size]
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);})
Nevetheless it returns Promise(state="pending"); Disregard of asking byte length to read.
What I am doing wrong. And why then method of Promise doesn't work?
How to do it correct way?
Regards, Arkady
User avatar
LIMPET235
Moderator
Posts: 39936
Joined: October 19th, 2007, 1:53 am
Location: The South Coast of N.S.W. Oz.

Re: how to read a part of native message if its length exeed

Post by LIMPET235 »

Moving to Mozilla Dev...
[Ancient Amateur Astronomer.]
Win-10-H/64 bit/500G SSD/16 Gig Ram/450Watt PSU/350WattUPS/Firefox-115.0.2/T-bird-115.3.2./SnagIt-v10.0.1/MWP-7.12.125.

(Always choose the "Custom" Install.)
Post Reply