diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2013-07-02 17:13:47 +0200 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2013-07-02 17:13:47 +0200 |
commit | f6df7d7e510f2d8879ec54dce32fee2b691dc32d (patch) | |
tree | 8a68d1586c3290093e9a6002ac8f071dbaf749e3 /src/libpiano/piano.c | |
parent | a1e73fc8d72a5253cae29c9bab5b260ad297c5e2 (diff) | |
download | pianobar-f6df7d7e510f2d8879ec54dce32fee2b691dc32d.tar.gz pianobar-f6df7d7e510f2d8879ec54dce32fee2b691dc32d.tar.bz2 pianobar-f6df7d7e510f2d8879ec54dce32fee2b691dc32d.zip |
piano: Check for libgcrypt errors
Fixes mysterious segfaults from issue #369 and #293.
Diffstat (limited to 'src/libpiano/piano.c')
-rw-r--r-- | src/libpiano/piano.c | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/src/libpiano/piano.c b/src/libpiano/piano.c index fac5da5..9020a6a 100644 --- a/src/libpiano/piano.c +++ b/src/libpiano/piano.c @@ -40,7 +40,7 @@ THE SOFTWARE. * @param piano handle * @return nothing */ -void PianoInit (PianoHandle_t *ph, const char *partnerUser, +PianoReturn_t PianoInit (PianoHandle_t *ph, const char *partnerUser, const char *partnerPassword, const char *device, const char *inkey, const char *outkey) { memset (ph, 0, sizeof (*ph)); @@ -48,15 +48,25 @@ void PianoInit (PianoHandle_t *ph, const char *partnerUser, ph->partner.password = strdup (partnerPassword); ph->partner.device = strdup (device); - gcry_cipher_open (&ph->partner.in, GCRY_CIPHER_BLOWFISH, - GCRY_CIPHER_MODE_ECB, 0); - gcry_cipher_setkey (ph->partner.in, (const unsigned char *) inkey, - strlen (inkey)); + if (gcry_cipher_open (&ph->partner.in, GCRY_CIPHER_BLOWFISH, + GCRY_CIPHER_MODE_ECB, 0) != GPG_ERR_NO_ERROR) { + return PIANO_RET_GCRY_ERR; + } + if (gcry_cipher_setkey (ph->partner.in, (const unsigned char *) inkey, + strlen (inkey)) != GPG_ERR_NO_ERROR) { + return PIANO_RET_GCRY_ERR; + } - gcry_cipher_open (&ph->partner.out, GCRY_CIPHER_BLOWFISH, - GCRY_CIPHER_MODE_ECB, 0); - gcry_cipher_setkey (ph->partner.out, (const unsigned char *) outkey, - strlen (outkey)); + if (gcry_cipher_open (&ph->partner.out, GCRY_CIPHER_BLOWFISH, + GCRY_CIPHER_MODE_ECB, 0) != GPG_ERR_NO_ERROR) { + return PIANO_RET_GCRY_ERR; + } + if (gcry_cipher_setkey (ph->partner.out, (const unsigned char *) outkey, + strlen (outkey)) != GPG_ERR_NO_ERROR) { + return PIANO_RET_GCRY_ERR; + } + + return PIANO_RET_OK; } /* destroy artist linked list @@ -258,6 +268,10 @@ const char *PianoErrorToStr (PianoReturn_t ret) { return "Selected audio quality is not available."; break; + case PIANO_RET_GCRY_ERR: + return "libgcrypt initialization failed."; + break; + /* pandora error messages */ case PIANO_RET_P_INTERNAL: return "Internal error."; |