From 5c7ad2a59bb2f1acecaa6826821fde565b978617 Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Sun, 17 Feb 2019 09:24:01 +0000 Subject: [PATCH] fhem.pl: limit reading and attr name length in featurelevel 6.0+ (Forum #97493) git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@18617 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- CHANGED | 1 + FHEM/01_FHEMWEB.pm | 20 ++++++++++++++++++++ FHEM/10_MQTT2_DEVICE.pm | 3 ++- UPGRADE | 4 ++++ fhem.pl | 23 +++++++++++++++-------- 5 files changed, 42 insertions(+), 9 deletions(-) diff --git a/CHANGED b/CHANGED index 65adca5e0..831e5ecbd 100644 --- a/CHANGED +++ b/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - feature: limit reading/attr name length in featurelevel 6.0+ (Forum #97493) - feature: 49_SSCam: send recordings by telegram is integrated as well as sending snapshots - bugfix: 74_XiaomiBTLESens: fix Undefined subroutine diff --git a/FHEM/01_FHEMWEB.pm b/FHEM/01_FHEMWEB.pm index b29313e19..3eaba5cfb 100644 --- a/FHEM/01_FHEMWEB.pm +++ b/FHEM/01_FHEMWEB.pm @@ -4123,6 +4123,16 @@ FW_show($$)
+ + +

show

+ + =end html =begin html_DE @@ -4844,6 +4854,16 @@ FW_show($$) + + +

show

+ =end html_DE diff --git a/FHEM/10_MQTT2_DEVICE.pm b/FHEM/10_MQTT2_DEVICE.pm index e4c567107..7f104a6ae 100644 --- a/FHEM/10_MQTT2_DEVICE.pm +++ b/FHEM/10_MQTT2_DEVICE.pm @@ -391,7 +391,8 @@ MQTT2_DEVICE_Attr($$) "%JSONMAP"=>"")); return $ret if($ret); } else { - return "unsupported character in readingname $par2" + return "bad reading name $par2 ". + "(contains not A-Za-z/\\d_\\.- or is too long)" if(!goodReadingName($par2)); } diff --git a/UPGRADE b/UPGRADE index 37f201bb9..42858cba5 100644 --- a/UPGRADE +++ b/UPGRADE @@ -32,3 +32,7 @@ enable the old feature. fhemSVG:openautomation:default. NOTE: the old version may be needed for FLORRPLAN users - the default fhem.cfg does not contain a telnet definition + +- XXXX-XX-XX (6.0) + - attribute names can only consist of the character A-Za-z/\d_\.- + - the length of attribute and reading names must be 64 or less diff --git a/fhem.pl b/fhem.pl index ce764040f..6de9a13f8 100755 --- a/fhem.pl +++ b/fhem.pl @@ -2392,9 +2392,10 @@ CommandSetReading($$) ($err, @b) = ReplaceSetMagic($hash, 3, @a); delete $hash->{CL}; } - return "WARNING: unsupported character in reading $b[1] ". - "(not A-Za-z/\\d_\\.-)" if(!goodReadingName($b[1])); - readingsSingleUpdate($defs{$sdev}, $b[1], $b[2], 1); + my $b1 = $b[1]; + return "bad reading name $b1 (contains not A-Za-z/\\d_\\.- or is too long)" + if(!goodReadingName($b1)); + readingsSingleUpdate($defs{$sdev}, $b1, $b[2], 1); } return join("\n", @rets); } @@ -2830,12 +2831,15 @@ CommandAttr($$) return "Usage: attr [-a|-r] []\n$namedef" if(@a && @a < 2); + my $a1 = $a[1]; + return "bad attribute name $a1 (contains not A-Za-z/\\d_\\.- or is too long)" + if($featurelevel > 5.9 && !goodReadingName($a1)); my @rets; - foreach my $sdev (devspec2array($a[0], $a[1] && $a[1] eq "?" ? undef : $cl)) { + foreach my $sdev (devspec2array($a[0], $a1 && $a1 eq "?" ? undef : $cl)) { my $hash = $defs{$sdev}; - my $attrName = $a[1]; + my $attrName = $a1; my $attrVal = (defined($a[2]) ? $a[2] : 1); if(!defined($hash)) { push @rets, "Please define $sdev first" if($init_done);#define -ignoreErr @@ -3045,8 +3049,8 @@ CommandSetstate($$) next; } - Log3 $d, 3, "WARNING: unsupported character in reading $sname ". - "(not A-Za-z/\\d_\\.-), notify the $d->{TYPE} module maintainer." + Log3 $d, 3, + "bad reading name $sname (contains not A-Za-z/\\d_\\.- or is too long)" if(!goodReadingName($sname)); if(!defined($d->{READINGS}{$sname}) || @@ -5700,7 +5704,9 @@ sub goodReadingName($) { my ($name) = @_; - return ($name && ($name =~ m/^[a-z0-9._\-\/]+$/i || $name =~ m/^\./)); + return undef if(!$name); + return undef if($featurelevel > 5.9 && length($name) > 64); + return ($name =~ m/^[a-z0-9._\-\/]+$/i || $name =~ m/^\./); } sub @@ -5710,6 +5716,7 @@ makeReadingName($) # Convert non-valid characters to _ $name = "UNDEFINED" if(!defined($name)); return $name if($name =~ m/^\./); $name =~ s/[^a-z0-9._\-\/]/_/gi; + $name = substr($name, 0, 64) if($featurelevel > 5.9 && length($name) > 64); return $name; }