]> git.tuebingen.mpg.de Git - paraslash.git/commit
server: Fix NULL pointer dereference in com_ls().
authorAndre Noll <maan@tuebingen.mpg.de>
Mon, 12 Jun 2023 16:06:10 +0000 (18:06 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 18 Jun 2023 13:16:17 +0000 (15:16 +0200)
commit72182df7af74e974af4d85a2f4143ea66a318844
tree3c6e7a03bf23f697503e1929cde835719e6c2155
parent2d2637cb4c9ab76fea6bc336b9af88fd00bf5e08
server: Fix NULL pointer dereference in com_ls().

The previous commit which extended the -a option of the ls command
to accept an optional argument introduced the following flaw: If the
argument of -a corresponds to the name of a mood for which no files
are admissible, the server crashes due to a NULL pointer dereference
because mood_load() leaves the mood instance pointer uninitialized
although it returns zero, indicating success.

This behaviour of mood_load() contradicts the promises made in
its documentation. Fix mood_load() by not special-casing the "zero
admissible files" case, which even simplifies the code a bit. If all
goes well but no files turn out to be admissible, we now open the
score table anyway and set the mood pointer to the allocated mood as
usual. Since get_statistics() may now be called with zero admissible
files, we have to add a check there before dividing by the number of
admissible files,

Fixes: 2d2637cb4c9ab76fea6bc336b9af88fd00bf5e08
mood.c