[AGENT++] Memory corruptions with MibComplexEntry subclass get_next_request

Frank Fock fock at agentpp.com
Wed Aug 18 18:36:41 CEST 2010


You cannot assign an array of unint8 as value (and the wrong length).
Simply assign a valid SnmpSyntax object and all will be fine.

Frank

On 18.08.2010 16:23, Reetesh Ranjan wrote:
> I have done a simple derivation MibComplexEntry and following is the
> derived get_next_request function (as per suggestion by Frank in
> another thread from me).
>
> void SDCFsMibHandler::get_next_request(Request * request, int ind)
> {
>      uint8 lResponse[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
>
>      Vbx vb(request->get_oid(ind));
>
>      vb.set_value(lResponse, sizeof lResponse);
>
>      request->finish(ind, vb);
> }
>
> This code is leading to memory corruption. Dmalloc finds an error 67
> after function exits (but I am not sure whether because of local vars
> destructed or somewhere later in the flow). When I replace the local
> variable vb with an allocated one, then similar error comes for heap.
> I am trying to do a simple operation of providing a value in the
> get-next response.
>
> Here are the class definition and all methods implemented/derived:
>
> class SDCFsMibHandler : public MibComplexEntry
> {
> public:
>      // constructor
>      SDCFsMibHandler();
>
>      // destructor
>      virtual
>      ~SDCFsMibHandler() { }
>
>     // Needed to implement pure virtual functions (but are dummy)
>    virtual MibEntry * clone() { return NULL; }
>
>    virtual OidxPtr max_key(void) { return NULL; }
>
>    virtual void get_request(Request *, int) { /* no-op */ }
>
>    virtual int prepare_set_request(Request*, int&) { return SNMP_ERROR_SUCCESS; }
>
>    virtual int undo_set_request(Request*, int&) { return SNMP_ERROR_SUCCESS; }
>
>    virtual void cleanup_set_request(Request*, int&) { }
>
>    // Important derived functions
>    virtual void
>    get_next_request(Request*, int);
>
>    virtual Oidx find_succ(const Oidx&  a, Request * req=NULL);
>
>    virtual int commit_set_request(Request*, int);
> }
>
> SDCFsMibHandler::SDCFsMibHandler()
>      : MibComplexEntry("1.3.1.4.1.108.1.200.1", READWRITE)
> { }
>
> Oidx SDCFsMibHandler::find_succ(const Oidx&  a, Request * req)
> {
>      Oidx l = a.next_peer();
>      return(l);
> }
>
> My snmp processing code is lifted from the examples. Could you please
> help me with any information on this?
>
> Thanks,
> Reetesh
> _______________________________________________
> AGENTPP mailing list
> AGENTPP at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/agentpp

-- 
AGENT++
http://www.agentpp.com
http://www.snmp4j.com
http://www.mibexplorer.com
http://www.mibdesigner.com




More information about the AGENTPP mailing list