]> git.tuebingen.mpg.de Git - paraslash.git/commit
score: Fix use of uninitialized memory on 64 bit machines.
authorAndre Noll <maan@systemlinux.org>
Thu, 3 Mar 2011 14:51:41 +0000 (15:51 +0100)
committerAndre Noll <maan@systemlinux.org>
Thu, 3 Mar 2011 15:19:00 +0000 (16:19 +0100)
commit02fdd9b000a873262c6abe226ac8c2dc8b616693
treee2ee837da06ea2ec937a2b59727487b68d0474c5
parent1199398188c1a5ee0e8bc147400d8532bc874700
score: Fix use of uninitialized memory on 64 bit machines.

The score of an audio file in the score table is defined as a quantity
which is sizeof(long) bytes large, i.e. 4 bytes on 32bit systems and
8 bytes on 64 bit systems. This is not a problem per se because the
score column lives only in memory, so we do not have to worry about
incompatibilities of the on-disk layout.

However, at several places in score.c we cast the pointer to the osl
object to (int *) rather than (long *). When writing to the object on
a 64 bit machine, this will only set 4 out of the 8 allocated bytes,
the other four bytes stay uninitialized. The "ls" command uses the
correct cast to (long *) and reads the full 8 bytes. This causes
valgrind to complain:

==5433== Conditional jump or move depends on uninitialised value(s)
==5433==    at 0x4164F4: prepare_ls_row (aft.c:1334)
==5433==    by 0x4E2F421: osl_rbtree_loop (osl.c:1457)
==5433==    by 0x418935: admissible_file_loop (score.c:255)
==5433==    by 0x41601A: com_ls_callback (aft.c:1363)
==5433==    by 0x411FDE: command_post_select (afs.c:842)
==5433==    by 0x41B67A: schedule (sched.c:76)
==5433==    by 0x411ACF: afs_init (afs.c:986)
==5433==    by 0x408863: main (server.c:451)
==5433==
==5433== Conditional jump or move depends on uninitialised value(s)
==5433==    at 0x41650A: prepare_ls_row (aft.c:1334)
==5433==    by 0x4E2F421: osl_rbtree_loop (osl.c:1457)
==5433==    by 0x418935: admissible_file_loop (score.c:255)
==5433==    by 0x41601A: com_ls_callback (aft.c:1363)
==5433==    by 0x411FDE: command_post_select (afs.c:842)
==5433==    by 0x41B67A: schedule (sched.c:76)
==5433==    by 0x411ACF: afs_init (afs.c:986)
==5433==    by 0x408863: main (server.c:451)

Fix this bug by always casting to (long *).
score.c