[pve-devel] [PATCH firewall] fix 901: encode unicode characters in sha digest

Dominik Csapak d.csapak at proxmox.com
Mon Feb 29 12:36:19 CET 2016


if we do not do this, Digest::SHA->add croaks when it detects
wide symbols

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/PVE/Firewall.pm | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/PVE/Firewall.pm b/src/PVE/Firewall.pm
index c556be4..70fe788 100644
--- a/src/PVE/Firewall.pm
+++ b/src/PVE/Firewall.pm
@@ -1093,7 +1093,10 @@ sub copy_list_with_digest {
 	    next if !defined($v);
 	    $data->{$k} = $v;
 	    # Note: digest ignores refs ($rule->{errors})
-	    $sha->add($k, ':', $v, "\n") if !ref($v); ;
+	    # since Digest::SHA expects a series of bytes,
+	    #  we have to encode the value here to prevent errors when
+	    #  using utf8 characters (eg. in comments)
+	    $sha->add($k, ':', encode_utf8($v), "\n") if !ref($v); ;
 	}
 	push @$res, $data;
     }
-- 
2.1.4





More information about the pve-devel mailing list