Changeset 60fcd71


Ignore:
Timestamp:
Apr 26, 2010, 7:48:51 PM (10 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.6, release-1.7, release-1.8, release-1.9
Children:
0ee43c8
Parents:
3001c11
git-author:
Nelson Elhage <nelhage@mit.edu> (04/25/10 22:35:13)
git-committer:
Nelson Elhage <nelhage@mit.edu> (04/26/10 19:48:51)
Message:
zcrypt: des_ecb_encrypt doesn't NULL-terminate the output block.

Output is a 'unsigned char [8]', so it couldn't even NULL-terminate it
in place if it wanted to. So copy the decrypted buffer into a larger
buffer that's guaranteed to have a NULL on the end.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • zcrypt.c

    r7ba7d66 r60fcd71  
    870870  des_key_schedule schedule;
    871871  unsigned char input[8], output[8];
     872  char tmp[9];
    872873  char *keystring;
    873874
    874   output[0] = '\0';    /* In case no message at all                 */
     875  /*
     876    DES decrypts 8 bytes at a time. We copy those over into the 9-byte
     877    'tmp', which has the final byte zeroed, to ensure that we always
     878    have a NULL-terminated string we can call printf/strlen on.
     879
     880    We don't pass 'tmp' to des_ecb_encrypt directly, because it's
     881    prototyped as taking 'unsigned char[8]', and this avoids a stupid
     882    cast.
     883
     884    We zero 'tmp' entirely, not just the final byte, in case there are
     885    no input blocks.
     886  */
     887  memset(tmp, 0, sizeof tmp);
    875888
    876889  keystring = read_keystring(keyfile);
     
    884897  {
    885898    des_ecb_encrypt(&input, &output, schedule, FALSE);
    886     printf("%s", output);
    887   }
    888 
    889   if (!output[0] || output[strlen((const char*)output) - 1] != '\n')
     899    memcpy(tmp, output, 8);
     900    printf("%s", tmp);
     901  }
     902
     903  if (!tmp[0] || tmp[strlen(tmp) - 1] != '\n')
    890904      printf("\n");
    891905  return TRUE;
Note: See TracChangeset for help on using the changeset viewer.