Andre Noll [Mon, 21 Mar 2016 19:51:08 +0000 (19:51 +0000)]
playlist: Do not update score if no playlist is open.
This bug caused the score of the current audio file to be updated
twice in mood mode since both the mood event handler and playlist
event handler honor afs events and update the score.
We fix the bug by moving the check whether a playlist is open to the
top of the playlist event handler, similar to the check in the mood
event handler of mood.c. If no playlist is open, we now return early
from the playlist event handler, ignoring all afs events.
In recv_cred_buffer(), pass_afd() and dispose_fds() the on-stack
ancillary data buffer is not necessarily aligned. The pointer is
cast to struct cmsghdr *, then dereferenced, resulting in undefined
behaviour due to the lack of alignment.
This patch asks the compiler to align the ancillary data buffers.
Andre Noll [Wed, 16 Mar 2016 21:48:54 +0000 (22:48 +0100)]
mood.c: Avoid overflow in update_quadratic_deviation().
The last multiplication of the expression returned can overflow. This
patch replaces the expression by an equivalent one which avoids to
multiply large numbers.
Andre Noll [Tue, 15 Mar 2016 19:48:12 +0000 (20:48 +0100)]
mood.c: Avoid integer underflow.
The three variables x, s, n are all of unsigned type, and the
subtraction x - s / n may underflow, resulting in a very large positive
value. This should not matter since we square the difference, but on
the other hand, the underflow can easily be avoided. This patch uses
a temporary variable to do so.
Andre Noll [Tue, 15 Mar 2016 19:41:37 +0000 (20:41 +0100)]
mood.c: Avoid integer overflow.
The quadratic deviation qd can be very large, causing the
multiplication n * qd to overflow. The new code avoids the
multiplication at the cost of two calls to int_sqrt() instead of one.
Andre Noll [Sun, 7 Feb 2016 16:33:15 +0000 (17:33 +0100)]
attribute: Avoid shifting 32 bit integers.
Doing "1UL << i" is wrong here, because the constant "1UL" is 32 bit
on 32 bit systems and we definitely need 64 bit quantities for the
attribute mask.
Andre Noll [Fri, 4 Sep 2015 07:24:12 +0000 (09:24 +0200)]
rmblob: Generate proper BLOB_REMOVE_EVENT.
com_rmblob_callback() of blob.c is responsible for removing blobs from
any of the four blob tables (images, lyrics, moods, playlists). After
a blob has been removed, the function generates an AFS event to tell
the other tables about the removal.
However, the call to afs_event() passes the event identifier
BLOB_RENAME rather than BLOB_REMOVE to the event handlers, which is
clearly incorrect. Fortunately, this does not matter because the only
event handler which cares about blob events is the one in mood.c,
and this handler treats the two events identically. Nevertheless,
it's is a bug that should be fixed.
This bug was introduced eight years ago when event handling was
introduced: commit 02d818d9 (Complete afs event handling).
Andre Noll [Fri, 28 Aug 2015 20:33:57 +0000 (22:33 +0200)]
lsatt: Fix sort order.
The -i option had the opposite effect of what the documentation
says. That is, lsatt -i sorted the attribute list by name while the
default was to sort by id. This patch reverts the logic in com_lsatt()
to let the implementation match the documentation.
Andre Noll [Sat, 22 Aug 2015 14:21:53 +0000 (16:21 +0200)]
server: Avoid segfault in com_sender().
If exactly one argument is given to the sender command, and this
argument is the name of an existing sender, the sender command
segfaults due to the NULL pointer dereference. The problem is an
off-by-one bug in the check for the number of arguments.
This patch makes sure we never dereference argv[2] if it is NULL.
Andre Noll [Sat, 20 Jun 2015 18:26:33 +0000 (20:26 +0200)]
mood: Clear the score table on attribute changes.
Although the comment in mood.c correctly states that the score table
must be cleared and reloaded if an attribute is added, removed or
renamed, the mood event handler misses to clear the score table.
Therefore, after reload_current_mood() has reloaded the mood object,
insertion of admissible files fails with
afs_event: table moods, event 0: key already exists in rbtree
This results in an unmodified set of admissible files.
The only other caller of reload_current_mood() clears the score table
right before the function call, so the easiest fix is to move the
call to clear_score_table() into reload_current_mood().
Andre Noll [Wed, 18 Feb 2015 15:40:40 +0000 (16:40 +0100)]
gcrypt: Initialize key size of public ASN keys.
This bug could make applications acccept short keys. Not a serious
problem since (a) ASN keys are deprecated in favor of ssh keys and
(b) encrypting a 256 byte buffer fails anyways on short keys. Let's
fix it anyway.
Andre Noll [Wed, 24 Dec 2014 15:10:43 +0000 (15:10 +0000)]
aft: Generate a remove event when adding duplicate files.
Consider the following scenario:
add /foo.mp3
add /bar.mp3 # assume foo and bar differ
cp /foo.mp3 /bar.mp3
add /bar.mp3
In the last add command, the path being added (/bar.mp3) already exists
in the audio file table, and its hash also exists for a different path
(/foo.mp3).
The code in aft.c is smart enough to detect this. It first removes
the existing entry for /bar.mp3 and then considers the addition of
/bar.mp3 as a file rename /foo.mp3 -> /bar.mp3.
Unfortunately, we miss to generate the remove event in this case. This
patch should fix it. It also improves the message a bit.
Andre Noll [Sun, 21 Dec 2014 14:35:19 +0000 (14:35 +0000)]
aft.c: Don't call osl_close_disk_object() on failure.
If osl_open_disk_object() fails, we branch to the "err" label where
osl_close_disk_object() is called although no disk object exists. Fix
this by simply returning the osl error code in this case.
Andre Noll [Sun, 21 Dec 2014 14:28:34 +0000 (14:28 +0000)]
Add missing osl() wrapper calls.
Some calls to osl library functions were missing the osl() wrapper
which transforms the osl error code into a paraslash error code.
This results in an incorrect error message on failure or worse.
print_chunk_table() and open_and_update_audio_file() of aft.c are
affected as well as the xxx_create() functions of blob.c.
Andre Noll [Sun, 11 May 2014 19:47:03 +0000 (21:47 +0200)]
recv: Don't segfault on invalid chunk values.
If recv->open() fails, para_recv segfaults after
==10129== Conditional jump or move depends on uninitialised value(s)
==10129== at 0x41BA18A: vfprintf (vfprintf.c:1634)
==10129== by 0x41BE3D8: buffered_vfprintf (vfprintf.c:2311)
==10129== by 0x41B975C: vfprintf (vfprintf.c:1289)
==10129== by 0x804C6AF: stderr_log (in /home/maan/scm/paraslash/para_recv)
==10129== by 0x804A193: main (recv.c:114)
This happens for example with the afh_receiver if the given start
chunk is bigger than the end chunk, e.g. when para_recv is executed as
./para_recv -r 'afh -b -80 -e -89 -f foo.opus'
The reason for the bug is we zero-out the stdout structure too late.
Fix this by initializing the stdout task structure upfront rather
than using memset().
This bug was introduced a year ago in commit b01605d7 (Avoid unwanted
log messages during startup) which moved down the call to memset().
Andre Noll [Sat, 28 Sep 2013 14:27:56 +0000 (16:27 +0200)]
build: Fix --with-opus-libs.
Due to a silly cut & paste bug this option sets $speex_libs rather
than $opus_libs. Since the assignment comes after speex detection,
the option is effectively a no-op.
Andre Noll [Sun, 22 Sep 2013 14:45:10 +0000 (16:45 +0200)]
play: Fix prev command.
The command handler for com_prev() stores the number of the
previous (valid) file in ->next_file of struct play_task and sets
->rq to CRT_FILE_CHANGE. The real work is supposed to be done in
load_next_file() which is called from the main post_select() function.
However, load_next_file() ignores ->next_file and computes the number
of the next file itself. Hence the "prev" command acts exactly as
"next", i.e. it selects the next rather than the previous file.
Fix this by ignoring ->next_file only if ->rq is CRT_NONE, which
indicates a normal end of file condition.
Andre Noll [Wed, 4 Sep 2013 04:35:38 +0000 (04:35 +0000)]
configure: Print opus audio file handler if opus lib was found.
The variable is called $audio_format_handlers rather than
$server_audio_formats. The value is only used to display the supported
audio formats, so this bug is rather benign.
Andre Noll [Fri, 6 Sep 2013 23:21:44 +0000 (23:21 +0000)]
btr: splice-out fix.
When splicing out a node we set the ->parent pointer of all child
nodes to the parent of the given node, and move each child to the
->children list of the parent.
Except when there is no parent. If the given node was a root node
(or an internal node whose parent vanished), we leave the ->children
list untouched. In this case the assertion a few lines later triggers
and aborts the program. Fix this by removing the nodes from the list.
Such nodes have become root nodes themselves, so they should not be
on any list of children.
Andre Noll [Sun, 1 Sep 2013 17:48:46 +0000 (17:48 +0000)]
fecdec: Avoid fecdec output buffer overruns.
The size of the buffer tree pool of the amp filter is 64K, which
is smaller than BTRN_MAX_PENDING of buffer_tree.c (96K). The latter
value is used in btr_node_status() as follows. If input for a buffer
tree node is available and there is less than BTRN_MAX_PENDING bytes
in the output queue of the node, the function returns 1 to indicate
that the node should continue to process its input.
This can result in a fatal error condition when the buffer tree pool
fills up completely. Avoid this by increasing the pool size to 128K.
Andre Noll [Sun, 1 Sep 2013 15:54:25 +0000 (15:54 +0000)]
vss: Avoid assertion "i == g->num_header_slices - 1".
This fixes a very old bug in the timing code for fec slices. Depending
on the number of bytes to submit and on the number of slices of the
current fec group it may happen that we reserve more slices than
needed for the audio file header. This is not a problem per se, but the
above assertion hits in this case and aborts para_server.
Fix this by removing the assertion, and make sure that all reserved
header slices are properly initialized.
Andre Noll [Thu, 29 Aug 2013 22:20:30 +0000 (22:20 +0000)]
configure: Fix restoring LDFLAGS.
The configure script saves the values of CPPFLAGS, CFLAGS and LDLFAGS
before each check and restores the old values afterwards. However,
for LDLFAGS this was broken at several places, since we used LD_FLAGS
(with an underscore) for saving the value and LDFLAGS for restoring it
(or vice versa).
This bug had the effect that a user-specified value of LDFLAGS was
ignored in some tests because LDFLAGS was restored to the empty
value LD_FLAGS during an earlier test.
This patch changes all occurrences of LD_FLAGS in configure.ac to
LDFLAGS.
Andre Noll [Mon, 29 Jul 2013 22:44:37 +0000 (00:44 +0200)]
server/gcrypt: Fix sending the empty status items.
When para_server enters the "stopped" state, it needs to inform all
clients which are executing the stat command that no audio file is
currently available.
To this aim the stat command handler calls empty_status_items(), which
creates a buffer containing empty values for most status items. This
function tries to be smart by computing the buffer only once. It
saves a reference in a static variable so that on subsequent calls
it can simply return the same buffer.
This works fine when para_server is compiled against the openssl
crypto library. However, it fails when libgcrypt is used because with
libgcrypt the send buffer is encrypted in-place. Hence on subsequent
calls the already encrypted buffer will be encrypted again, resulting
in garbage being sent to the client.
This patch avoids this bug by using a fresh buffer each time the
empty status items are sent.
Andre Noll [Sun, 21 Jul 2013 14:30:23 +0000 (16:30 +0200)]
sched.h: Remove outdated comment.
The term "these functions" is undefined here, and setting t->error
is deprecated. The post_select() functions are supposed to return
an error code instead, but this is already mentioned further down in
the file, so let's just remove the comment.
Andre Noll [Sat, 6 Jul 2013 18:23:04 +0000 (20:23 +0200)]
ggo.c: Document return value of printf_or_die().
Commit b59a3c41 (filter: Wrap lines in the available filter list)
changed the return value of this function from void to int but missed
to update the documentation.
Andre Noll [Sat, 6 Jul 2013 21:00:14 +0000 (23:00 +0200)]
audiod: Close filters in reverse order.
Otherwise, a subsequent filter might refer to a buffer reference of
the previous filter, accessing freed memory. This is not a bug right
now, as audiod only closes filters after the full buffer tree has
become inactive, i.e. after all buffer tree nodes have unregistered
their task. It's cleaner to reverse the loop though, and it has no
additional cost.
Andre Noll [Fri, 12 Jul 2013 14:08:41 +0000 (16:08 +0200)]
opusdec: avoid __STDC_VERSION__ warning.
opusdec_filter.c indirectly includes opus_types.h which checks whether
__STDC_VERSION__ >= 199901L. However, at least some gcc versions
don't define __STDC_VERSION__ which results in
warning: "__STDC_VERSION__" is not defined
For example, this happens on Ubuntu lucid, which ships gcc-4.4.3.
This patch gets rid of the warning by defining __STDC_VERSION__
if necessary prior to including the opus_types header.
Andre Noll [Sun, 7 Jul 2013 11:22:48 +0000 (13:22 +0200)]
afh: Initialize audio format handlers only once.
afc.c calls afh_init() twice. This does not really hurt as this
function is idempotent, but it causes the initialization log messages
to be printed twice.
This gets rid of the additional call to afh_init() which crept in
in commit 042767ce (Use self-made help to avoid recompilations on
version changes).
Andre Noll [Mon, 1 Jul 2013 19:06:48 +0000 (21:06 +0200)]
Merge branch 't/versioning_improvements'
Cooking for ~2 weeks.
15e99a version.c: Mark version_git() as const.
9bdebf Remove CODENAME macro.
be2f6b gui: Use version_single_line().
d60dae Improve man page layout.
5dbc9a afh/play: Include supported audio formats in help output.
042767 Use self-made help to avoid recompilations on version changes.
48f1fc Provide "purpose" texts.
aa74a9 Revamp ggo help.
9f7a49 afh_recv: Replace ggo text section by description.
b59e0e Make gengetopt descriptions work.
06b3e7 Introduce version.c to limit recompilation on version changes.
75feac Make all commands print git version and improve version string.
b01605 Avoid unwanted log messages during startup.
625fdb Don't check return value of command line parsers unnecessarily.
533b03 Build receivers, filters and writers without -h and -V support.
b59a3c filter: Wrap lines in the available filter list.
9e56d3 audioc: Print config file errors.
e5264d doc: Rewrite udp sender description
5ec373 client: Fix typo in comment.
6d5159 client: Remove duplicate include.
Andre Noll [Sat, 22 Jun 2013 15:20:15 +0000 (17:20 +0200)]
i9e: Fix memory leak in clear_bottom_line().
In clear_bottom_line() we call readline's rl_copy_text() which
allocates a buffer for the given range of the current input line. But
we never free this buffer, which results in a memory leak. This patch
plugs the leak.
Andre Noll [Sat, 22 Jun 2013 14:59:04 +0000 (16:59 +0200)]
Handle empty command lines properly.
Both para_client and para_audioc create an argument vector from the
given command line using create_argv(). If the command line contains
only whitespace characters, this vector has length zero, and argv[0]
is NULL.
We missed to check for this at at least three places in audioc.c,
client.c and audiod_command.c, which resulted in crashes due to NULL
pointer dereferences or failed assertions.
These bugs can easily be triggered by starting para_client or
para_audioc in interactive mode, entering a single space character
and hitting return.
This patch adds the missing checks to prevent the crashes.
Andre Noll [Sun, 16 Jun 2013 12:22:06 +0000 (14:22 +0200)]
gui: Fix off-by-one in add_spaces().
Commit e90c6c0a (Speed up add_spaces().) changed add_spaces() to print
space characters in chunks rather than one at a time. It introduced
space[], an array of whitespace characters, which is written entirely
if there are more spaces to print than the size of the array. However,
in the calculation of how much was printed so far, we missed the fact
that sizeof(space) includes the terminating NULL byte, so this number
is in fact the number of space characters *plus one*.
Consequently, we printed too few space characters. This resulted in
parts of the previous string still being visible in the top window
of para_gui.
Andre Noll [Sun, 7 Apr 2013 02:31:51 +0000 (02:31 +0000)]
Provide "purpose" texts.
This text will be printed right after the program name in the --help
output. For para_afh, the inline text becomes redundant, so this text
is removed.
Each executable gets a purpose text, and for receivers, filters,
writers the purpose will be printed as part of the help output of
para_audiod, para_filter. para_recv and para_write.
Andre Noll [Fri, 12 Apr 2013 11:54:37 +0000 (13:54 +0200)]
Revamp ggo help.
This adds usage and description fields to struct ggo_help and
changes ggo_print_help() to optionally print these.
The boolean detailed_help flag of ggo_print_help() is replaced by a
bitmask which lets the caller specify what to print. Four pre-defined
masks are used to print the normal help, the detailed help, the help
for modules (receivers, filters, writers) and the detailed module help.
The new macro DEFINE_GGO_HELP can be employed to create a struct
ggo_help from a gengetopt structure.
Andre Noll [Fri, 12 Apr 2013 11:54:12 +0000 (13:54 +0200)]
Make gengetopt descriptions work.
With gengetopt's text and description options it is not possible to
print a text only when --detailed-help was given, but not when only
--help is given.
Moreover, headers generated with old versions of gengetopt do not
export the description text. However, declaring it unconditionally
causes compiler warnings on new systems.
To circumvent these problems, we introduce a new test for configure
which checks whether the description string is declared. If it is not,
we simply append the declaration to the *.cmdline.h files.
This change allows to move the description string of para_play to
the gengetopt source file.
Andre Noll [Fri, 12 Apr 2013 12:23:45 +0000 (14:23 +0200)]
Introduce version.c to limit recompilation on version changes.
Currently version.h includes git-version.h which changes whenever
a different commit is checked out or the working tree becomes dirty
because a file has been modified. Consequently, all .c files that
include this header must be recompiled in this case.
To limit the number of recompilations, this commit introduces
version.c, which contains functions that return the various types of
the version string. It is now the only file that includes version.h,
so only version.o must be rebuilt if git-version.h changes.
This also adds the build date, OS and CC version to the version output.
This difference comes from the fact that para_afh has its own
->print_help method which uses the VERSION_SINGLE_LINE macro of
version.h while para_audioc relies on gengetopt's help output.
The latter uses the make variable PACKAGE_VERSION which gets
initialized at configure time through the second argument in AC_INIT
of configure.ac. This value is either the version number for or the
string "git".
It's a good thing to have the abbreviated git version encoded in
all executables, so this commit changes the argument of gengetopt's
--set-version to the git version string including the codename. With
the patch applied, the output of all commands looks like this if
--version was given:
para_filter 0.4.12.12.g11d7 (spectral gravity)
To make sure things stay consistent, the patch introduces the
VERSION_SINGLE_LINE macro and changes all commands to use it instead
of open coding the version string.
That's because recv_init() is called before the command line arguments
are parsed, so the loglevel has not been set at this point. Other
programs have similar problems.
Fix these problems by always setting the loglevel right after a parser
has been called so that the init functions run *after* loglevel has
been set.
Andre Noll [Sat, 6 Apr 2013 18:59:12 +0000 (18:59 +0000)]
Don't check return value of command line parsers unnecessarily.
All gengetopt parsers except the one for para_client are generated
without the --no-handle-error option, i.e. these parsers exit on errors.
Hence it is pointless to check return values.
Andre Noll [Tue, 2 Apr 2013 14:30:06 +0000 (14:30 +0000)]
Simplify i9e_line_handler.
The line handlers of all three users of the i9e API (play, client
and audioc) return immediately if the passed line is NULL or the
empty string. Hence we may call the line handler only if there is a
non-empty line to dispatch.
Moving the check for a non-empty line to generic i9e code simplifies
the three line handlers a bit and avoids code duplication.
Andre Noll [Fri, 7 Jun 2013 19:34:51 +0000 (21:34 +0200)]
Merge branch 't/gui_improvements'
Was cooking for more than one month.
bf1831 string: Speed up xvasprintf().
bcc083 string: Add discard feature for for_each_line().
e3868d string: Simplify return value of for_each_line().
d1f0f0 string: Simplify for_each_line().
23b121 string: Clean up for_each_line() and related functions.
6256ed string: Replace the for_each_line_modes enum by a bitmap.
14e689 gui: Don't sleep before executing the status command.
e90c6c gui: Speed up add_spaces().
20e2c6 gui: Rename do_exit().
ef0508 gui: Remove superfluous cmd_died.
d7562b gui: Check stdin for readability.
a44fa6 gui: Discard overlong input lines.
Andre Noll [Sun, 14 Oct 2012 16:44:57 +0000 (18:44 +0200)]
The opus audio format handler.
This fills the dummy files opus_afh.c and opus_common.c which were
introduced in the previous commit with content. One function,
opus_parse_header(), will also be needed by the decoder to
be introduced in the next commit. So this function belongs to
opus_common.c and must be public.
Andre Noll [Sat, 25 May 2013 12:37:41 +0000 (14:37 +0200)]
Merge branch 't/doc'
Simple enough and cooking since 2013-05-05.
e82be0 manual: Add a new paragraph for installing dependencies.
1d6f5f manual: Add missing references of two optional packages.
4a6061 check_wav.c: Fix documentation of check_wav_post_select().
f9c625 Add two missing Copyright headers and file annotations.
16af9d Add documentation of public functions in check_wav.c.
Andre Noll [Sun, 19 May 2013 20:09:52 +0000 (22:09 +0200)]
Fix compilation on Ubuntu precise.
This distro ships glibc-2.15 where clock_gettime() is part of the
realtime library librt. So all executables which call clock_gettime()
must be linked with -lrt. The configure script detects this and adds
-lrt to LDFLAGS. However, -lrt must come *after* the objects to be
linked together, which is currently not the case.
Fix this by moving $(LDFLAGS) to the end of the recipe for the targets
of all executables.
Andre Noll [Wed, 15 May 2013 20:33:24 +0000 (22:33 +0200)]
alsa writer: Do not print uninitialized data.
ALSA's snd_output_buffer_string() returns the current size of valid
data in the returned data buffer, but this buffer is not guaranteed
to be zero-terminated.
Currently alsa_init() ignores this fact and prints the buffer up to
the first NULL byte. Therefore it may print garbage that follows the
valid data in the buffer. If there is no zero byte after the data,
it may even segfault.
Fix this bug by using memchr() instead of strchr() and carefully
tracking the number of bytes processed.