[Bug crypt/22765] New: (struct crypt_data *data)->initialized is not set to zero before the first call to crypt_r () in crypt/badsalttest.c

ilmalakhov at yandex dot ru sourceware-bugzilla@sourceware.org
Wed Jan 31 15:35:00 GMT 2018


https://sourceware.org/bugzilla/show_bug.cgi?id=22765

            Bug ID: 22765
           Summary: (struct crypt_data *data)->initialized is not set to
                    zero before the first call to crypt_r () in
                    crypt/badsalttest.c
           Product: glibc
           Version: 2.27
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: crypt
          Assignee: unassigned at sourceware dot org
          Reporter: ilmalakhov at yandex dot ru
  Target Milestone: ---

Hi.

$ cat ./crypt/badsalttest.c
. . .
static int
do_test (void)
{
. . .
  struct crypt_data cd;
. . .
  for (size_t i = 0; i < n; i++)
    {
. . .
      if (crypt_r (tests[i][0], tests[i][1], &cd))
. . .


 `cd.initialized' is left uninitialized before the first invocation of `crypt_r
()' in this test despite the fact that it should be set to zero according to

$ man crypt_r
. . .
       crypt_r()  is  a  reentrant  version  of  crypt().  The structure
       pointed to by data is used to store result data and bookkeeping
       information.  Other than allocating it, the only thing that the caller
       should do with this structure is to set  data->initialized
       to zero before the first call to crypt_r().
. . .


 This may lead to an unexpected result below during the first call to `crypt_r
()':

. . .
bool
_ufc_setup_salt_r (const char *s, struct crypt_data * __restrict __data)
{
. . .
  if(__data->initialized == 0)
    __init_des_r(__data);
. . .


 The following patch resolves this issue:

diff --git a/crypt/badsalttest.c b/crypt/badsalttest.c
index 6c5230c..8077835 100644
--- a/crypt/badsalttest.c
+++ b/crypt/badsalttest.c
@@ -61,6 +61,10 @@ do_test (void)
       tests[n - 1][1] = &page[pagesize - 1];
     }

+  /* This field should be set to zero before the first call to
+     crypt_r ().  */
+  cd.initialized = 0;
+
   for (size_t i = 0; i < n; i++)
     { 
       if (crypt (tests[i][0], tests[i][1]))

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Glibc-bugs mailing list