From 4a5a5a037d19562a221f85a8d6ced8b224a3de00 Mon Sep 17 00:00:00 2001 From: Supereg Date: Thu, 8 Oct 2020 18:28:10 +0200 Subject: [PATCH] Prevent that SerialNumber or Model gets a value assigned with length less or equal to 1 character (fixes #824) Otherwise HomeKit will reject the whole accessory! --- src/lib/Characteristic.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lib/Characteristic.ts b/src/lib/Characteristic.ts index 6f03ff50b..5817eba65 100644 --- a/src/lib/Characteristic.ts +++ b/src/lib/Characteristic.ts @@ -1151,6 +1151,11 @@ export class Characteristic extends EventEmitter { throw new Error("characteristic value expected string and received " + (typeof value)); } + if (value.length <= 1 && (this.UUID === Characteristic.Model.UUID || this.UUID === Characteristic.SerialNumber.UUID)) { + console.error(new Error(`[${this.displayName}] characteristic must have a length of more than 1 character otherwise HomeKit will reject this accessory. Ignoring it.`).stack); + return this.value; // just return the current value + } + const maxLength = this.props.maxLen != null? this.props.maxLen: 64; // default is 64 (max is 256 which is set in setProps) if (value.length > maxLength) { console.warn(`[${this.displayName}] characteristic was supplied illegal value: string '${value}' exceeded max length of ${maxLength}. Supplying illegal values will throw errors in the future!`);