patches/glibc/2.1.3/rh62-03-glibc-2.1.3-crypt.patch
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sat Feb 24 11:00:05 2007 +0000 (2007-02-24)
changeset 1 eeea35fbf182
permissions -rw-r--r--
Add the full crosstool-NG sources to the new repository of its own.
You might just say: 'Yeah! crosstool-NG's got its own repo!".
Unfortunately, that's because the previous repo got damaged beyond repair and I had no backup.
That means I'm putting backups in place in the afternoon.
That also means we've lost history... :-(
     1 --- glibc-2.1.3/md5-crypt/md5-crypt.c	2000/03/04 00:47:30	1.1
     2 +++ glibc-2.1.3/md5-crypt/md5-crypt.c	2000/08/24 06:10:02	1.8
     3 @@ -1,5 +1,5 @@
     4  /* One way encryption based on MD5 sum.
     5 -   Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc.
     6 +   Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
     7     This file is part of the GNU C Library.
     8     Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
     9  
    10 @@ -18,6 +18,7 @@
    11     write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    12     Boston, MA 02111-1307, USA.  */
    13  
    14 +#include <assert.h>
    15  #include <errno.h>
    16  #include <stdlib.h>
    17  #include <string.h>
    18 @@ -37,9 +38,9 @@
    19  
    20  
    21  /* Prototypes for local functions.  */
    22 -extern char *__md5_crypt_r __P ((const char *key, const char *salt,
    23 -				 char *buffer, int buflen));
    24 -extern char *__md5_crypt __P ((const char *key, const char *salt));
    25 +extern char *__md5_crypt_r (const char *key, const char *salt,
    26 +			    char *buffer, int buflen);
    27 +extern char *__md5_crypt (const char *key, const char *salt);
    28  
    29  
    30  /* This entry point is equivalent to the `crypt' function in Unix
    31 @@ -51,13 +52,16 @@
    32       char *buffer;
    33       int buflen;
    34  {
    35 -  unsigned char alt_result[16];
    36 +  unsigned char alt_result[16]
    37 +    __attribute__ ((__aligned__ (__alignof__ (md5_uint32))));
    38    struct md5_ctx ctx;
    39    struct md5_ctx alt_ctx;
    40    size_t salt_len;
    41    size_t key_len;
    42    size_t cnt;
    43    char *cp;
    44 +  char *copied_key = NULL;
    45 +  char *copied_salt = NULL;
    46  
    47    /* Find beginning of salt string.  The prefix should normally always
    48       be present.  Just in case it is not.  */
    49 @@ -68,6 +72,26 @@
    50    salt_len = MIN (strcspn (salt, "$"), 8);
    51    key_len = strlen (key);
    52  
    53 +  if ((key - (char *) 0) % __alignof__ (md5_uint32) != 0)
    54 +    {
    55 +      char *tmp = (char *) alloca (key_len + __alignof__ (md5_uint32));
    56 +      key = copied_key =
    57 +	memcpy (tmp + __alignof__ (md5_uint32)
    58 +		- (tmp - (char *) 0) % __alignof__ (md5_uint32),
    59 +		key, key_len);
    60 +      assert ((key - (char *) 0) % __alignof__ (md5_uint32) == 0);
    61 +    }
    62 +
    63 +  if ((salt - (char *) 0) % __alignof__ (md5_uint32) != 0)
    64 +    {
    65 +      char *tmp = (char *) alloca (salt_len + __alignof__ (md5_uint32));
    66 +      salt = copied_salt =
    67 +	memcpy (tmp + __alignof__ (md5_uint32)
    68 +		- (tmp - (char *) 0) % __alignof__ (md5_uint32),
    69 +		salt, salt_len);
    70 +      assert ((salt - (char *) 0) % __alignof__ (md5_uint32) == 0);
    71 +    }
    72 +
    73    /* Prepare for the real work.  */
    74    __md5_init_ctx (&ctx);
    75  
    76 @@ -195,21 +219,30 @@
    77  
    78    /* Clear the buffer for the intermediate result so that people
    79       attaching to processes or reading core dumps cannot get any
    80 -     information.  */
    81 -  memset (alt_result, '\0', sizeof (alt_result));
    82 +     information.  We do it in this way to clear correct_words[]
    83 +     inside the MD5 implementation as well.  */
    84 +  __md5_init_ctx (&ctx);
    85 +  __md5_finish_ctx (&ctx, alt_result);
    86 +  memset (&ctx, '\0', sizeof (ctx));
    87 +  memset (&alt_ctx, '\0', sizeof (alt_ctx));
    88 +  if (copied_key != NULL)
    89 +    memset (copied_key, '\0', key_len);
    90 +  if (copied_salt != NULL)
    91 +    memset (copied_salt, '\0', salt_len);
    92  
    93    return buffer;
    94  }
    95  
    96  
    97 +static char *buffer;
    98 +
    99  char *
   100  __md5_crypt (const char *key, const char *salt)
   101  {
   102    /* We don't want to have an arbitrary limit in the size of the
   103       password.  We can compute the size of the result in advance and
   104       so we can prepare the buffer we pass to `md5_crypt_r'.  */
   105 -  static char *buffer = NULL;
   106 -  static int buflen = 0;
   107 +  static int buflen;
   108    int needed = 3 + strlen (salt) + 1 + 26 + 1;
   109  
   110    if (buflen < needed)
   111 @@ -220,4 +253,12 @@
   112      }
   113  
   114    return __md5_crypt_r (key, salt, buffer, buflen);
   115 +}
   116 +
   117 +
   118 +static void
   119 +__attribute__ ((__destructor__))
   120 +free_mem (void)
   121 +{
   122 +  free (buffer);
   123  }
   124 --- glibc-2.1.3/md5-crypt/md5.c	2000/03/04 00:47:30	1.1
   125 +++ glibc-2.1.3/md5-crypt/md5.c	2000/07/04 18:22:44	1.2
   126 @@ -1,6 +1,6 @@
   127 -/* md5.c - Functions to compute MD5 message digest of files or memory blocks
   128 +/* Functions to compute MD5 message digest of files or memory blocks.
   129     according to the definition of MD5 in RFC 1321 from April 1992.
   130 -   Copyright (C) 1995, 1996, 1997, 1999 Free Software Foundation, Inc.
   131 +   Copyright (C) 1995, 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
   132     This file is part of the GNU C Library.
   133  
   134     The GNU C Library is free software; you can redistribute it and/or
   135 @@ -217,6 +217,8 @@
   136       size_t len;
   137       struct md5_ctx *ctx;
   138  {
   139 +  //const void aligned_buffer = buffer;
   140 +
   141    /* When we already have some bits in our internal buffer concatenate
   142       both inputs first.  */
   143    if (ctx->buflen != 0)
   144 @@ -224,16 +226,20 @@
   145        size_t left_over = ctx->buflen;
   146        size_t add = 128 - left_over > len ? len : 128 - left_over;
   147  
   148 +      /* Only put full words in the buffer.  */
   149 +      add -= add % __alignof__ (md5_uint32);
   150 +
   151        memcpy (&ctx->buffer[left_over], buffer, add);
   152        ctx->buflen += add;
   153  
   154 -      if (left_over + add > 64)
   155 +      if (ctx->buflen > 64)
   156  	{
   157 -	  md5_process_block (ctx->buffer, (left_over + add) & ~63, ctx);
   158 +	  md5_process_block (ctx->buffer, ctx->buflen & ~63, ctx);
   159 +
   160 +	  ctx->buflen &= 63;
   161  	  /* The regions in the following copy operation cannot overlap.  */
   162  	  memcpy (ctx->buffer, &ctx->buffer[(left_over + add) & ~63],
   163 -		  (left_over + add) & 63);
   164 -	  ctx->buflen = (left_over + add) & 63;
   165 +		  ctx->buflen);
   166  	}
   167  
   168        buffer = (const char *) buffer + add;
   169 @@ -251,8 +257,17 @@
   170    /* Move remaining bytes in internal buffer.  */
   171    if (len > 0)
   172      {
   173 -      memcpy (ctx->buffer, buffer, len);
   174 -      ctx->buflen = len;
   175 +      size_t left_over = ctx->buflen;
   176 +
   177 +      memcpy (&ctx->buffer[left_over], buffer, len);
   178 +      left_over += len;
   179 +      if (left_over >= 64)
   180 +	{
   181 +	  md5_process_block (ctx->buffer, 64, ctx);
   182 +	  left_over -= 64;
   183 +	  memcpy (ctx->buffer, &ctx->buffer[64], left_over);
   184 +	}
   185 +      ctx->buflen = left_over;
   186      }
   187  }
   188  
   189 --- glibc-2.1.3/md5-crypt/md5.h	2000/03/04 00:47:30	1.1
   190 +++ glibc-2.1.3/md5-crypt/md5.h	2000/07/04 18:22:44	1.2
   191 @@ -1,6 +1,6 @@
   192  /* Declaration of functions and data types used for MD5 sum computing
   193     library functions.
   194 -   Copyright (C) 1995, 1996, 1997, 1999 Free Software Foundation, Inc.
   195 +   Copyright (C) 1995, 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
   196     This file is part of the GNU C Library.
   197  
   198     The GNU C Library is free software; you can redistribute it and/or
   199 @@ -87,7 +87,7 @@
   200  
   201    md5_uint32 total[2];
   202    md5_uint32 buflen;
   203 -  char buffer[128];
   204 +  char buffer[128] __attribute__ ((__aligned__ (__alignof__ (md5_uint32))));
   205  };
   206  
   207  /*