afs: Fix long-standing bug in add command.
authorAndre Noll <maan@systemlinux.org>
Sun, 31 Jul 2011 12:40:10 +0000 (14:40 +0200)
committerAndre Noll <maan@systemlinux.org>
Sun, 31 Jul 2011 12:40:10 +0000 (14:40 +0200)
Before the add command handler adds a given audio file to the database
it asks the afs process to check whether the file already exists.

The afs process looks for rows in the audio file table with path
and/or hash identical to the given file. If a match is found a
pointer to the matching row is passed from afs to the command handler.
The get_row_pointer_from_result() helper is then called by the command
handler to extract the row pointer from the result returned by afs.

However, this helper incorrectly dereferenced the pointer which caused
the command handler to examine an address rather than the content of
the address to tell whether the file already exists and whether path
or content has changed. This could lead to changed/moved files being
ignored as well as existing files being added again.

This bug was introduced in commit 0a3b9b83, back in 2008.

aft.c

diff --git a/aft.c b/aft.c
index a27e67eeb7b438546573c254d76c4ed15cdf3750..f4080233855009be5423b3bc9325b861d5f20b0c 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -1823,7 +1823,7 @@ static void hash_sister_callback(int fd, const struct osl_object *query)
 static int get_row_pointer_from_result(struct osl_object *result, void *private)
 {
        struct osl_row **row = private;
 static int get_row_pointer_from_result(struct osl_object *result, void *private)
 {
        struct osl_row **row = private;
-       *row = result->data;
+       *row = *(struct osl_row **)(result->data);
        return 1;
 }
 
        return 1;
 }