From: Marc Cromme Date: Tue, 10 Apr 2007 11:28:51 +0000 (+0000) Subject: protecting dereferencing of void pointer by if statement X-Git-Tag: METAPROXY.1.0.10~16 X-Git-Url: http://git.indexdata.com/?a=commitdiff_plain;h=2f8cb1e1bda27debbd84f233453d33c8ff0700fc;p=metaproxy-moved-to-github.git protecting dereferencing of void pointer by if statement problem exposed by initresponse from z3950.libris.kb.se:210/libr , where ir->implementationId was not populated --- diff --git a/src/gduutil.cpp b/src/gduutil.cpp index e0b971f..eb7e18c 100644 --- a/src/gduutil.cpp +++ b/src/gduutil.cpp @@ -1,4 +1,4 @@ -/* $Id: gduutil.cpp,v 1.18 2007-03-20 07:57:54 adam Exp $ +/* $Id: gduutil.cpp,v 1.19 2007-04-10 11:28:51 marc Exp $ Copyright (c) 2005-2007, Index Data. See the LICENSE file for details @@ -129,7 +129,8 @@ std::ostream& std::operator<<(std::ostream& os, Z_APDU& zapdu) = zapdu.u.initRequest; Z_IdAuthentication *a = ir->idAuthentication; - if (a && a->which == Z_IdAuthentication_idPass ) + if (a && a->which == Z_IdAuthentication_idPass + && a->u.idPass->userId) os << a->u.idPass->userId << " "; //<< ":" << a->u.idPass->groupId << " "; else @@ -144,10 +145,13 @@ std::ostream& std::operator<<(std::ostream& os, Z_APDU& zapdu) else os << "-" << " " ; - os << (ir->implementationId) << " " - //<< ir->referenceId << " " - << (ir->implementationName) << " " - << (ir->implementationVersion); + if (ir->implementationId) + os << (ir->implementationId) << " "; + //<< ir->referenceId << " " + if (ir->implementationName) + os<< (ir->implementationName) << " "; + if (ir->implementationVersion) + os << (ir->implementationVersion) << " "; } break; case Z_APDU_initResponse: @@ -155,12 +159,16 @@ std::ostream& std::operator<<(std::ostream& os, Z_APDU& zapdu) { Z_InitResponse *ir = zapdu.u.initResponse; - if (ir->result && *(ir->result)) - os << "OK" << " " - << (ir->implementationId) << " " + if (ir->result && *(ir->result)){ + os << "OK" << " "; + if (ir->implementationId) + os << (ir->implementationId) << " "; //<< ir->referenceId << " " - << (ir->implementationName) << " " - << (ir->implementationVersion) << " "; + if (ir->implementationName) + os<< (ir->implementationName) << " "; + if (ir->implementationVersion) + os << (ir->implementationVersion) << " "; + } else os << "DIAG"; }