>From a34a6f4be9f02705b646e3089fdc7be02c53ffe6 Mon Sep 17 00:00:00 2001
From: fumiyas <fumiyas@69f2458b-35d4-408a-aa88-7d8d64836e89>
Date: Wed, 24 Oct 2012 02:03:56 +0000
Subject: [PATCH] Protect attribute values from Encode::decode_utf8() with
 Encode::FB_CROAK

diff --git a/smbldap_tools.pl b/smbldap_tools.pl
index 9111c5a..ec4dfbd 100644
--- a/smbldap_tools.pl
+++ b/smbldap_tools.pl
@@ -808,7 +808,10 @@ sub read_user {
         foreach my $attr ( $entry->attributes ) {
             my @vals = $entry->get_value($attr);
 #	    my $val_utf8 = eval {
-#		Encode::decode_utf8($val, Encode::FB_CROAK);
+#               ## Use $tmp because Encode::FB_CROAK may change the input
+#               ## string. See Encode::FB_QUIET description in
+#               ## `perldoc Encode` for details.
+#		Encode::decode_utf8(my $tmp=$val, Encode::FB_CROAK);
 #	    };
 #	    $val = "**UNPRINTABLE**" if ($@ || $val_utf8 =~ /\P{IsPrint}/);
             $lines .= $attr . ": " . join( ',', @vals ) . "\n";
@@ -838,7 +841,10 @@ sub read_user_human_readable {
             my @vals = $entry->get_value($attr);
             foreach my $val (@vals) {
 		my $val_utf8 = eval {
-		    Encode::decode_utf8($val, Encode::FB_CROAK);
+                    ## Use $tmp because Encode::FB_CROAK may change the input
+                    ## string. See Encode::FB_QUIET description in
+                    ## `perldoc Encode` for details.
+		    Encode::decode_utf8(my $tmp=$val, Encode::FB_CROAK);
 		};
 		$val = "**UNPRINTABLE**" if ($@ || $val_utf8 =~ /\P{IsPrint}/);
             }
-- 
1.7.10.4

