]> git.sur5r.net Git - openldap/blob - servers/slapd/operation.c
benign buffer overflow fix (ITS#1964)
[openldap] / servers / slapd / operation.c
1 /* operation.c - routines to deal with pending ldap operations */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11
12 #include <ac/string.h>
13 #include <ac/socket.h>
14
15 #include "slap.h"
16
17
18 void
19 slap_op_free( Operation *op )
20 {
21         assert( LDAP_STAILQ_NEXT(op, o_next) == NULL );
22
23         if ( op->o_ber != NULL ) {
24                 ber_free( op->o_ber, 1 );
25         }
26         if ( op->o_dn.bv_val != NULL ) {
27                 free( op->o_dn.bv_val );
28         }
29         if ( op->o_ndn.bv_val != NULL ) {
30                 free( op->o_ndn.bv_val );
31         }
32         if ( op->o_authmech.bv_val != NULL ) {
33                 free( op->o_authmech.bv_val );
34         }
35         if ( op->o_ctrls != NULL ) {
36                 ldap_controls_free( op->o_ctrls );
37         }
38
39 #ifdef LDAP_CLIENT_UPDATE
40         if ( op->o_clientupdate_state.bv_val != NULL ) {
41                 free( op->o_clientupdate_state.bv_val );
42         }
43 #endif /* LDAP_CLIENT_UPDATE */
44
45         free( (char *) op );
46 }
47
48 Operation *
49 slap_op_alloc(
50     BerElement          *ber,
51     ber_int_t   msgid,
52     ber_tag_t   tag,
53     ber_int_t   id
54 )
55 {
56         Operation       *op;
57
58         op = (Operation *) ch_calloc( 1, sizeof(Operation) );
59
60         op->o_ber = ber;
61         op->o_msgid = msgid;
62         op->o_tag = tag;
63
64         op->o_time = slap_get_time();
65         op->o_opid = id;
66
67         return( op );
68 }