]> git.sur5r.net Git - openldap/commitdiff
ITS#7834 Fix MDB_MULTIPLE writing multiple keys.
authorHallvard Furuseth <hallvard@openldap.org>
Fri, 30 May 2014 07:06:08 +0000 (09:06 +0200)
committerHallvard Furuseth <hallvard@openldap.org>
Fri, 30 May 2014 07:06:08 +0000 (09:06 +0200)
Update the state before looping, so the key is not duplicated.
Broke in 4c8f57615c5ca7b014c038e59c1045182e74f5ad (mostly).

libraries/liblmdb/mdb.c

index cbf8c0494ecd61223e82fa310b2ea095bc5aa985..c4eaa262a0afb97bcf18119854e9a278d19895f4 100644 (file)
@@ -6138,7 +6138,7 @@ current:
                                        data->mv_data = METADATA(omp);
                                else
                                        memcpy(METADATA(omp), data->mv_data, data->mv_size);
-                               goto done;
+                               return MDB_SUCCESS;
                          }
                        }
                        if ((rc2 = mdb_ovpage_free(mc, omp)) != MDB_SUCCESS)
@@ -6154,7 +6154,7 @@ current:
                                memcpy(olddata.mv_data, data->mv_data, data->mv_size);
                        else
                                memcpy(NODEKEY(leaf), key->mv_data, key->mv_size);
-                       goto done;
+                       return MDB_SUCCESS;
                }
                mdb_node_del(mc, 0);
        }
@@ -6252,6 +6252,12 @@ put_sub:
                /* Increment count unless we just replaced an existing item. */
                if (insert_data)
                        mc->mc_db->md_entries++;
+               if (!rc && insert_key) {
+                       /* If we succeeded and the key didn't exist before,
+                        * make sure the cursor is marked valid.
+                        */
+                       mc->mc_flags |= C_INITIALIZED;
+               }
                if (flags & MDB_MULTIPLE) {
                        if (!rc) {
 next_mult:
@@ -6260,17 +6266,12 @@ next_mult:
                                data[1].mv_size = mcount;
                                if (mcount < dcount) {
                                        data[0].mv_data = (char *)data[0].mv_data + data[0].mv_size;
+                                       insert_key = insert_data = 0;
                                        goto more;
                                }
                        }
                }
        }
-done:
-       /* If we succeeded and the key didn't exist before, make sure
-        * the cursor is marked valid.
-        */
-       if (!rc && insert_key)
-               mc->mc_flags |= C_INITIALIZED;
        return rc;
 }