You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by he...@apache.org on 2018/09/27 18:30:41 UTC

svn commit: r1842138 - /spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm

Author: hege
Date: Thu Sep 27 18:30:41 2018
New Revision: 1842138

URL: http://svn.apache.org/viewvc?rev=1842138&view=rev
Log:
Split pseudo_random_string for generic use

Modified:
    spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm?rev=1842138&r1=1842137&r2=1842138&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm Thu Sep 27 18:30:41 2018
@@ -1267,6 +1267,15 @@ sub touch_file {
 
 ###########################################################################
 
+sub pseudo_random_string {
+  my $len = shift || 6;
+  my $str = '';
+  $str .= (0..9,'A'..'Z','a'..'z')[rand 62] for (1 .. $len);
+  return $str;
+}
+
+###########################################################################
+
 =item my ($filepath, $filehandle) = secure_tmpfile();
 
 Generates a filename for a temporary file, opens it exclusively and
@@ -1290,8 +1299,7 @@ sub secure_tmpfile {
   for (my $retries = 20; $retries > 0; $retries--) {
     # we do not rely on the obscurity of this name for security,
     # we use a average-quality PRG since this is all we need
-    my $suffix = join('', (0..9,'A'..'Z','a'..'z')[rand 62, rand 62, rand 62,
-						   rand 62, rand 62, rand 62]);
+    my $suffix = pseudo_random_string(6);
     $reportfile = File::Spec->catfile($tmpdir,".spamassassin${$}${suffix}tmp");
 
     # instead, we require O_EXCL|O_CREAT to guarantee us proper