From 0e3bd6f30084e218c09865aad3a4aa293f25926e Mon Sep 17 00:00:00 2001 From: Xavier Chantry Date: Sat, 2 Apr 2011 20:23:07 +0200 Subject: libalpm/package.c: check return of base64_decode reported by clang analyzer Signed-off-by: Xavier Chantry --- lib/libalpm/package.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index 9e1dbd52..e090e754 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -205,22 +205,30 @@ static int decode_pgpsig(pmpkg_t *pkg) { int len = strlen(pkg->pgpsig.encdata); const unsigned char *usline = (const unsigned char*)pkg->pgpsig.encdata; int destlen = 0; + int ret; + + pkg->pgpsig.rawlen = 0; + pkg->pgpsig.rawdata = 0; + /* get the necessary size for the buffer by passing 0 */ - int ret = base64_decode(NULL, &destlen, usline, len); + ret = base64_decode(NULL, &destlen, usline, len); + if(ret != 0) { + goto error; + } + /* alloc our memory and repeat the call to decode */ MALLOC(pkg->pgpsig.rawdata, (size_t)destlen, goto error); ret = base64_decode(pkg->pgpsig.rawdata, &destlen, usline, len); - pkg->pgpsig.rawlen = destlen; if(ret != 0) { goto error; } + pkg->pgpsig.rawlen = destlen; FREE(pkg->pgpsig.encdata); return 0; error: FREE(pkg->pgpsig.rawdata); - pkg->pgpsig.rawlen = 0; return 1; } -- cgit v1.2.3-55-g3dc8