Yelp / send_nsca

Pure-python NSCA client
GNU Lesser General Public License v2.1
26 stars 26 forks source link

send_service api throws divide by zero error when password is empty and encryption_method=1 #5

Open mmohite opened 8 years ago

mmohite commented 8 years ago

stack trace -

  6         sender = NscaSender(**sender_args)

----> 7 sender.send_service(hostname, service_name,status, message)

/usr/lib/python2.6/site-packages/send_nsca/nsca.pyc in send_service(self, host, service, state, description) 355 crypter = self._cached_crypters[conn] 356 packet = _pack_packet(host, service, state, description, timestamp) --> 357 packet = crypter.encrypt(packet) 358 conn.sendall(packet) 359

/usr/lib/python2.6/site-packages/send_nsca/nsca.pyc in encrypt(self, value) 99 value_s = map(ord, list(value)) 100 repeated_iv = map(ord, list(int(math.ceil(float(len(value)) / len(self.iv))) * self.iv)) --> 101 repeated_password = map(ord, list(int(math.ceil(float(len(value)) / len(self.password))) * self.password)) 102 xorer = functools.partial(apply, int.xor) 103 xor1 = map(xorer, zip(value_s, repeated_iv))

ZeroDivisionError: float division

Swicegood commented 1 year ago

This works:

def encrypt(self, value): value_s = six.iterbytes(value) repeated_iv = six.iterbytes(list(int(math.ceil(float(len(value)) / len(self.iv))) self.iv)) if len(self.password) == 0: xor2 = [a ^ b for a, b in zip(value_s, repeated_iv)] else: repeated_password = six.iterbytes(list(int(math.ceil(float(len(value)) / len(self.password))) self.password)) xor1 = [a ^ b for a, b in zip(value_s, repeated_iv)] xor2 = [a ^ b for a, b in zip(xor1, repeated_password)] return b''.join(map(six.int2byte, xor2))