diff options
author | Michael Adam <obnox@samba.org> | 2008-08-05 22:38:44 +0200 |
---|---|---|
committer | Karolin Seeger <kseeger@samba.org> | 2008-08-11 16:15:29 +0200 |
commit | f0bcef0aaa87ad14cf071acfa7984ddfa6302959 (patch) | |
tree | b4d9c3d418df89db11fdb9bec03c341e5e654239 /source/lib | |
parent | b63ddc53f2ee74ca2295554838ca7a40272dcf2f (diff) | |
download | samba-f0bcef0aaa87ad14cf071acfa7984ddfa6302959.tar.gz |
idmap_tdb2: fix a race condition in idmap_tdb2_allocate_id().
The race is a regression introduced by the change to dbwrap.
It might have led to two concurrent processes returning the same id.
This fix is achieved by changing dbwrap_change_uint32_atomic() to
match the original behaviour of tdb_change_uint32_atomic(), which
is the following: *oldval is used as initial value when
the value does not yet exist and that the old value should be
returned in *oldval.
dbwrap_change_uint32_atomic() is used (only) in idmap_tdb2.c,
to get new ids.
Michael
(cherry picked from commit 72bd83fea7572a6202027b200d192c05023aa633)
(cherry picked from commit f3cdf9e646180837a470e90f8a17d933f07b60c3)
Diffstat (limited to 'source/lib')
-rw-r--r-- | source/lib/dbwrap_util.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/source/lib/dbwrap_util.c b/source/lib/dbwrap_util.c index 07e50827d44..14baec11a3c 100644 --- a/source/lib/dbwrap_util.c +++ b/source/lib/dbwrap_util.c @@ -110,9 +110,13 @@ uint32_t dbwrap_change_uint32_atomic(struct db_context *db, const char *keystr, return -1; } - if ((rec->value.dptr != NULL) - && (rec->value.dsize == sizeof(val))) { + if (rec->value.dptr == NULL) { + val = *oldval; + } else if (rec->value.dsize == sizeof(val)) { val = IVAL(rec->value.dptr, 0); + *oldval = val; + } else { + return -1; } val += change_val; |