List:General Discussion« Previous MessageNext Message »
From:Michael Widenius Date:November 12 1999 10:27pm
Subject:Problem when using CONCAT and ENCRYPT
View as plain text  
>>>>> "aldrian" == aldrian  <aldrian@stripped>
> writes:

>> Description:
aldrian> The output of the CONCAT of two ENCRYPT commands shows incorrectly.
aldrian> However, giving an "intermediary" solves the problem.

>> How-To-Repeat:

aldrian> Welcome to the MySQL monitor.  Commands end with ; or \g.
aldrian> Your MySQL connection id is 22 to server version: 3.23.5-alpha

aldrian> Type 'help' for help.

mysql> select encrypt('haha','R1');                                     
aldrian> +----------------------+
aldrian> | encrypt('haha','R1') |
aldrian> +----------------------+
aldrian> | R1vEvRpdGm7qY        |
aldrian> +----------------------+
aldrian> 1 row in set (0.02 sec)

mysql> select encrypt('haha','R2');                                     
aldrian> +----------------------+
aldrian> | encrypt('haha','R2') |
aldrian> +----------------------+
aldrian> | R2KQHzAjtn0f2        |
aldrian> +----------------------+
aldrian> 1 row in set (0.02 sec)

mysql> select concat(encrypt('haha','R1'),encrypt('haha','R2'));    
aldrian> +---------------------------------------------------+
aldrian> | concat(encrypt('haha','R1'),encrypt('haha','R2')) |
aldrian> +---------------------------------------------------+
aldrian> | R2KQHzAjtn0f2R2KQHzAjtn0f2                        |
aldrian> +---------------------------------------------------+
aldrian> 1 row in set (0.03 sec)

>>>>>>>> NOTICE the INCORRECT output.



mysql> select concat(encrypt('haha','R1'),'x',encrypt('haha','R2'));                   
>      
aldrian> +-------------------------------------------------------+
aldrian> | concat(encrypt('haha','R1'),'x',encrypt('haha','R2')) |
aldrian> +-------------------------------------------------------+
aldrian> | R1vEvRpdGm7qYxR2KQHzAjtn0f2                           |
aldrian> +-------------------------------------------------------+
aldrian> 1 row in set (0.03 sec)

>>>>>>>> NOTICE the CORRECT output.

Hi!

I assume no one has sent a patch for this problem yet :(

Fix:

*** /my/monty/master/mysql-3.23.6-alpha/sql/mysql_priv.h	Thu Nov 11 13:11:09 1999
--- ./mysql_priv.h	Sat Nov 13 00:23:47 1999
***************
*** 90,95 ****
--- 90,97 ----
  /* Time handling defaults */
  #define TIMESTAMP_MAX_YEAR 2038
  #define YY_PART_YEAR	   70
+ #define PRECISION_FOR_DOUBLE 53
+ #define PRECISION_FOR_FLOAT  24
  
  /* The following can also be changed from the command line */
  #define CONNECT_TIMEOUT		5		// Do not wait long for connect
***************
*** 382,388 ****
  extern pthread_mutex_t LOCK_mysql_create_db,LOCK_Acl,LOCK_open,
         LOCK_thread_count,LOCK_mapped_file,LOCK_user_locks, LOCK_status,
         LOCK_grant, LOCK_log, LOCK_error_log, LOCK_delayed_insert,
!        LOCK_delayed_status, LOCK_delayed_create;
  extern pthread_cond_t COND_refresh,COND_thread_count;
  extern pthread_attr_t connection_attrib;
  extern bool opt_endinfo;
--- 384,390 ----
  extern pthread_mutex_t LOCK_mysql_create_db,LOCK_Acl,LOCK_open,
         LOCK_thread_count,LOCK_mapped_file,LOCK_user_locks, LOCK_status,
         LOCK_grant, LOCK_log, LOCK_error_log, LOCK_delayed_insert,
!        LOCK_delayed_status, LOCK_delayed_create, LOCK_crypt;
  extern pthread_cond_t COND_refresh,COND_thread_count;
  extern pthread_attr_t connection_attrib;
  extern bool opt_endinfo;
*** /my/monty/master/mysql-3.23.6-alpha/sql/item_strfunc.cc	Wed Nov 10 14:38:09 1999
--- ./item_strfunc.cc	Sat Nov 13 00:23:41 1999
***************
*** 666,673 ****
--- 666,676 ----
        return 0;
      salt_ptr= salt_str->c_ptr();
    }
+   pthread_mutex_lock(&LOCK_crypt);
    char *tmp=crypt(res->c_ptr(),salt_ptr);
    str->set(tmp,strlen(tmp));
+   str->copy();
+   pthread_mutex_unlock(&LOCK_crypt);
    return str;
  #else
    null_value=1;
*** /my/monty/master/mysql-3.23.6-alpha/sql/mysqld.cc	Thu Nov 11 13:11:09 1999
--- ./mysqld.cc	Sat Nov 13 00:23:22 1999
***************
*** 160,166 ****
  		LOCK_mapped_file, LOCK_status, LOCK_grant,
  		LOCK_log, LOCK_error_log,
  		LOCK_delayed_insert, LOCK_delayed_status, LOCK_delayed_create,
! 		LOCK_flush;
  
  pthread_cond_t COND_refresh,COND_thread_count,COND_flush;
  pthread_t signal_thread;
--- 160,166 ----
  		LOCK_mapped_file, LOCK_status, LOCK_grant,
  		LOCK_log, LOCK_error_log,
  		LOCK_delayed_insert, LOCK_delayed_status, LOCK_delayed_create,
! 		LOCK_flush, LOCK_crypt;
  
  pthread_cond_t COND_refresh,COND_thread_count,COND_flush;
  pthread_t signal_thread;
***************
*** 1150,1155 ****
--- 1150,1156 ----
    (void) pthread_cond_init(&COND_refresh,NULL);
    (void) pthread_cond_init(&COND_flush,NULL);
    (void) pthread_mutex_init(&LOCK_flush,NULL);
+   (void) pthread_mutex_init(&LOCK_crypt,NULL);
  
  #ifdef SET_RLIMIT_NOFILE
    /* connections and databases neads lots of files */

Regards,
Monty

PS: Sorry for the long delay before replying, but I just come back from
    a 2 weeks vacation trip.
Thread
Problem when using CONCAT and ENCRYPTaldrian22 Oct
  • Re: Problem when using CONCAT and ENCRYPTsinisa22 Oct
  • Problem when using CONCAT and ENCRYPTMichael Widenius13 Nov