jjhoughton / napi-ldap

MIT License
7 stars 5 forks source link

Calling this.ld.errorstring() when this.ld === undefined… #11

Open dilyanpalauzov opened 3 years ago

dilyanpalauzov commented 3 years ago

https://github.com/jjhoughton/napi-ldap/blob/master/main.js#L310 has this code:

LDAP.prototype.enqueue = function(msgid, fn) {
   if (msgid == -1 || this.ld === undefined) {
    if (this.ld.errorstring() === "Can't contact LDAP server") {
      Object.keys(this.queue).forEach(
        function fireTimeout(msgid) {
          this.queue[msgid](new LDAPError("Timeout"));
          delete this.queue[msgid];
          this.ld.abandon(+msgid);
        }.bind(this)
      );
    }
    process.nextTick(
      function emitError() {
        fn(new LDAPError(this.ld.errorstring()));
      }.bind(this)
    );
    this.stats.errors++;
    return this;
  }
}

When this.ld is undefined, this.ld.errorstring() cannot be called (twice - https://github.com/jjhoughton/napi-ldap/blob/master/main.js#L311 and https://github.com/jjhoughton/napi-ldap/blob/master/main.js#L329)