From d44f61b583a112e23a9af405968b11514979fedf Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Sun, 15 Jan 2012 20:21:50 +0100 Subject: piano: Make sync response parser NUL-byte aware Fixes #207 --- src/libpiano/crypt.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/libpiano/crypt.c') diff --git a/src/libpiano/crypt.c b/src/libpiano/crypt.c index e833868..3f98f42 100644 --- a/src/libpiano/crypt.c +++ b/src/libpiano/crypt.c @@ -1,5 +1,5 @@ /* -Copyright (c) 2008-2010 +Copyright (c) 2008-2011 Lars-Dominik Braun Permission is hereby granted, free of charge, to any person obtaining a copy @@ -43,20 +43,23 @@ THE SOFTWARE. /* decrypt hex-encoded, blowfish-crypted string: decode 2 hex-encoded blocks, * decrypt, byteswap * @param hex string + * @param decrypted string length (without trailing NUL) * @return decrypted string or NULL */ #define INITIAL_SHIFT 28 #define SHIFT_DEC 4 -char *PianoDecryptString (const char * const s) { +char *PianoDecryptString (const char * const s, size_t * const retSize) { const unsigned char *strInput = (const unsigned char *) s; /* hex-decode => strlen/2 + null-byte */ uint32_t *iDecrypt; + size_t decryptedSize; char *strDecrypted; unsigned char shift = INITIAL_SHIFT, intsDecoded = 0, j; /* blowfish blocks, 32-bit */ uint32_t f, l, r, lrExchange; - if ((iDecrypt = calloc (strlen ((const char *) strInput)/2/sizeof (*iDecrypt)+1, + decryptedSize = strlen ((const char *) strInput)/2; + if ((iDecrypt = calloc (decryptedSize/sizeof (*iDecrypt)+1, sizeof (*iDecrypt))) == NULL) { return NULL; } @@ -112,6 +115,10 @@ char *PianoDecryptString (const char * const s) { ++strInput; } + if (retSize != NULL) { + *retSize = decryptedSize; + } + return strDecrypted; } #undef INITIAL_SHIFT -- cgit v1.2.3