ir-ctl: improve scancode validation
PATCH 4/6 ir-ctl: improve scancode validation
Ensure rc6 mce is that just that and that nec32 is not necx or nec.
Signed-off-by Sean Young <[email protected]>
--- utils/ir-ctl/ir-ctl.c | 4 ++-- utils/ir-ctl/ir-encode.c | 18 ++++++++++++++++++ utils/ir-ctl/ir-encode.h | 1 + 3 files changed, 21 insertions(+), 2 deletions(-)
utils/ir-ctl/ir-ctl.c +2 -2
@@ -242,7 +242,7 @@ static struct file *read_file(const char *fname)return NULL ; } -if (scancode & ~protocol_scancode_mask (proto)) { +if (!protocol_scancode_valid (proto, scancode)) {fprintf (stderr,_ ("error: %s:%d: invalid scancode '%s' for protocol '%s'\n" ), fname, lineno, scancodestr,protocol_name (proto));return NULL ; }
@@ -354,7 +354,7 @@ static struct file *read_scancode(const char *name)return NULL ; } -if (scancode & ~protocol_scancode_mask (proto)) { +if (!protocol_scancode_valid (proto, scancode)) {fprintf (stderr,_ ("error: invalid scancode '%s' for protocol '%s'\n" ), p +1 ,protocol_name (proto));return NULL ; }
utils/ir-ctl/ir-encode.c +18 -0
@@ -417,6 +417,24 @@ unsigned protocol_scancode_mask(enum rc_proto proto)return encoders[proto].scancode_mask; } +bool protocol_scancode_valid (enum rc_proto p,unsigned s) +{ +if (s & ~encoders[p].scancode_mask) +return false; + +if (p ==RC_PROTO_NECX ) { +return (((s >>16 ) ^ ~(s >>8 )) &0xff ) !=0 ; + }else if (p ==RC_PROTO_NEC32 ) { +return (((s >>24 ) ^ ~(s >>16 )) &0xff ) !=0 ; + }else if (p ==RC_PROTO_RC6_MCE ) { +return (s &0xffff0000 ) ==0x800f0000 ; + }else if (p ==RC_PROTO_RC6_6A_32 ) { +return (s &0xffff0000 ) !=0x800f0000 ; + } + +return true; +} +unsigned protocol_encode (enum rc_proto proto,unsigned scancode,unsigned *buf) {return encoders[proto].encode (proto, scancode, buf);
utils/ir-ctl/ir-encode.h +1 -0
@@ -28,6 +28,7 @@ enum rc_proto {bool protocol_match (const char *name,enum rc_proto *proto);unsigned protocol_carrier (enum rc_proto proto);unsigned protocol_max_size (enum rc_proto proto); +bool protocol_scancode_valid (enum rc_proto proto,unsigned scancode);unsigned protocol_scancode_mask (enum rc_proto proto);unsigned protocol_encode (enum rc_proto proto,unsigned scancode,unsigned *buf);const char *protocol_name (enum rc_proto proto);
Signature · 1 line
2.9.3