Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
OpenLDAP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dragoș Haiduc
OpenLDAP
Commits
6da27229
Commit
6da27229
authored
26 years ago
by
Kurt Spanier
Browse files
Options
Downloads
Patches
Plain Diff
1. Fix of ldbmcat segmentation fault bug (ITS#85 and #81).
2. Make ldbm_Env a failure-safe entity.
parent
3f76ee7a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/ldbm.h
+0
-3
0 additions, 3 deletions
include/ldbm.h
libraries/libldbm/ldbm.c
+26
-22
26 additions, 22 deletions
libraries/libldbm/ldbm.c
servers/slapd/tools/ldbmcat.c
+11
-7
11 additions, 7 deletions
servers/slapd/tools/ldbmcat.c
with
37 additions
and
32 deletions
include/ldbm.h
+
0
−
3
View file @
6da27229
...
...
@@ -204,9 +204,6 @@ LDAP_BEGIN_DECL
int
ldbm_initialize
(
void
);
int
ldbm_shutdown
(
void
);
#if HAVE_BERKELEY_DB2
extern
DB_ENV
ldbm_Env
;
#endif
int
ldbm_errno
(
LDBM
ldbm
);
LDBM
ldbm_open
(
char
*
name
,
int
rw
,
int
mode
,
int
dbcachesize
);
...
...
This diff is collapsed.
Click to expand it.
libraries/libldbm/ldbm.c
+
26
−
22
View file @
6da27229
...
...
@@ -23,8 +23,11 @@
void
ldbm_datum_free
(
LDBM
ldbm
,
Datum
data
)
{
free
(
data
.
dptr
);
data
.
dptr
=
NULL
;
if
(
data
.
dptr
)
{
free
(
data
.
dptr
);
data
.
dptr
=
NULL
;
data
.
size
=
0
;
}
}
...
...
@@ -33,6 +36,8 @@ ldbm_datum_dup( LDBM ldbm, Datum data )
{
Datum
dup
;
ldbm_datum_init
(
dup
);
if
(
data
.
dsize
==
0
)
{
dup
.
dsize
=
0
;
dup
.
dptr
=
NULL
;
...
...
@@ -96,7 +101,8 @@ ldbm_db_errcall( const char *prefix, char *message )
}
/* a dbEnv for BERKELEYv2 */
DB_ENV
ldbm_Env
;
static
DB_ENV
ldbm_Env_internal
;
DB_ENV
*
ldbm_Env
=
NULL
;
/* Berkeley DB 2.x is reentrant */
#define LDBM_LOCK ((void)0)
...
...
@@ -109,14 +115,15 @@ int ldbm_initialize( void )
if
(
ldbm_initialized
++
)
return
1
;
memset
(
&
ldbm_Env
,
0
,
sizeof
(
ldbm_Env
));
memset
(
&
ldbm_Env_internal
,
0
,
sizeof
(
DB_ENV
));
ldbm_Env
=
&
ldbm_Env_internal
;
ldbm_Env
.
db_errcall
=
ldbm_db_errcall
;
ldbm_Env
.
db_errpfx
=
"==>"
;
ldbm_Env
->
db_errcall
=
ldbm_db_errcall
;
ldbm_Env
->
db_errpfx
=
"==>"
;
envFlags
=
DB_CREATE
|
DB_THREAD
;
if
(
(
err
=
db_appinit
(
NULL
,
NULL
,
&
ldbm_Env
,
envFlags
))
)
{
if
(
(
err
=
db_appinit
(
NULL
,
NULL
,
ldbm_Env
,
envFlags
))
)
{
char
error
[
BUFSIZ
];
if
(
err
<
0
)
{
...
...
@@ -138,7 +145,7 @@ int ldbm_shutdown( void )
{
if
(
!
ldbm_initialized
)
return
1
;
db_appexit
(
&
ldbm_Env
);
db_appexit
(
ldbm_Env
);
return
0
;
}
...
...
@@ -162,13 +169,13 @@ ldbm_open( char *name, int rw, int mode, int dbcachesize )
DB_INFO
dbinfo
;
memset
(
&
dbinfo
,
0
,
sizeof
(
dbinfo
));
if
(
ldbm_Env
.
mp_info
==
NULL
)
if
(
(
ldbm_Env
==
NULL
)
||
(
ldbm_Env
->
mp_info
==
NULL
)
)
dbinfo
.
db_cachesize
=
dbcachesize
;
dbinfo
.
db_pagesize
=
DEFAULT_DB_PAGE_SIZE
;
dbinfo
.
db_malloc
=
ldbm_malloc
;
LDBM_LOCK
;
(
void
)
db_open
(
name
,
DB_TYPE
,
rw
,
mode
,
&
ldbm_Env
,
&
dbinfo
,
&
ret
);
(
void
)
db_open
(
name
,
DB_TYPE
,
rw
,
mode
,
ldbm_Env
,
&
dbinfo
,
&
ret
);
LDBM_UNLOCK
;
#else
...
...
@@ -231,7 +238,7 @@ ldbm_fetch( LDBM ldbm, Datum key )
data
.
flags
=
DB_DBT_MALLOC
;
if
(
(
rc
=
(
*
ldbm
->
get
)(
ldbm
,
NULL
,
&
key
,
&
data
,
0
))
!=
0
)
{
if
(
data
.
dptr
)
free
(
data
.
dptr
);
ldbm_datum_free
(
ldbm
,
data
);
#else
if
(
(
rc
=
(
*
ldbm
->
get
)(
ldbm
,
&
key
,
&
data
,
0
))
==
0
)
{
/* Berkeley DB 1.85 don't malloc the data for us */
...
...
@@ -320,13 +327,13 @@ ldbm_firstkey( LDBM ldbm )
if
(
(
*
ldbm
->
cursor
)(
ldbm
,
NULL
,
&
dbci
,
0
))
# endif
{
key
.
flags
=
0
;
key
.
dptr
=
NULL
;
return
(
key
);
}
else
{
*
dbch
=
dbci
;
if
(
(
*
dbci
->
c_get
)(
dbci
,
&
key
,
&
data
,
DB_NEXT
)
==
0
)
{
if
(
data
.
dptr
)
{
free
(
data
.
dptr
);
}
ldbm_datum_free
(
ldbm
,
data
);
}
#else
int
rc
;
...
...
@@ -338,6 +345,7 @@ ldbm_firstkey( LDBM ldbm )
}
#endif
else
{
key
.
flags
=
0
;
key
.
dptr
=
NULL
;
key
.
dsize
=
0
;
}
...
...
@@ -361,16 +369,15 @@ ldbm_nextkey( LDBM ldbm, Datum key )
Datum
data
;
#ifdef HAVE_BERKELEY_DB2
void
*
oldKey
=
key
.
dptr
;
ldbm_datum_init
(
data
);
data
.
flags
=
DB_DBT_MALLOC
;
ldbm_datum_free
(
ldbm
,
key
);
key
.
flags
=
data
.
flags
=
DB_DBT_MALLOC
;
LDBM_LOCK
;
if
(
(
*
dbcp
->
c_get
)(
dbcp
,
&
key
,
&
data
,
DB_NEXT
)
==
0
)
{
if
(
data
.
dptr
)
free
(
data
.
dptr
);
ldbm_datum_free
(
ldbm
,
data
);
}
#else
int
rc
;
...
...
@@ -382,16 +389,13 @@ ldbm_nextkey( LDBM ldbm, Datum key )
}
#endif
else
{
key
.
flags
=
0
;
key
.
dptr
=
NULL
;
key
.
dsize
=
0
;
}
LDBM_UNLOCK
;
#ifdef HAVE_BERKELEY_DB2
if
(
oldKey
)
free
(
oldKey
);
#endif
return
(
key
);
}
...
...
This diff is collapsed.
Click to expand it.
servers/slapd/tools/ldbmcat.c
+
11
−
7
View file @
6da27229
...
...
@@ -26,6 +26,8 @@ main( int argc, char **argv )
#ifdef HAVE_BERKELEY_DB2
DBC
*
cursorp
;
if
(
ldbm_initialize
()
)
exit
(
1
);
#endif
ldbm_datum_init
(
key
);
...
...
@@ -58,8 +60,8 @@ main( int argc, char **argv )
key
=
ldbm_nextkey
(
dbp
,
last
)
)
#endif
{
if
(
last
.
dptr
!=
NULL
)
ldbm_datum_free
(
dbp
,
last
);
ldbm_datum_free
(
dbp
,
last
)
;
data
=
ldbm_fetch
(
dbp
,
key
);
if
((
s
=
data
.
dptr
)
!=
NULL
)
{
...
...
@@ -73,18 +75,20 @@ main( int argc, char **argv )
puts
(
s
);
}
if
(
data
.
dptr
!=
NULL
)
{
ldbm_datum_free
(
dbp
,
data
);
}
ldbm_datum_free
(
dbp
,
data
);
}
last
=
key
;
}
if
(
last
.
dptr
!=
NULL
)
ldbm_datum_free
(
dbp
,
last
);
ldbm_datum_free
(
dbp
,
last
);
ldbm_close
(
dbp
);
#ifdef HAVE_BERKELEY_DB2
(
void
)
ldbm_shutdown
();
#endif
exit
(
0
);
return
0
;
/* NOT REACHED */
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment