Gentoo Archives: gentoo-user

From: William Kenworthy <billk@×××××××××.au>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Re: realloc() failure in motion
Date: Wed, 21 Sep 2022 03:28:36
Message-Id: 444d3331-af21-6894-a98b-81c3a438bfc0@iinet.net.au
In Reply to: [gentoo-user] Re: realloc() failure in motion by Nuno Silva
1 On 21/9/22 00:40, Nuno Silva wrote:
2 > On 2022-09-18, William Kenworthy wrote:
3 >
4 >> Hi, I am setting up some  cameras (esp32cam) and intended to use
5 >> motion for them but it crashes on startup with a realloc() error. The
6 >> system is an up to date arm64 (odroid N2+), mostly stable. Has anyone
7 >> seen this before?
8 >>
9 >> BillK
10 >>
11 >>
12 >> ha /etc/motion # /usr/bin/motion -c /etc/motion/motion.conf -k 9 -d 9
13 >> [0:motion] [NTC] [ALL] conf_load: Processing thread 0 - config file
14 >> /etc/motion/motion.conf
15 >> [0:motion] [NTC] [ALL] config_camera: Processing camera config file
16 >> /etc/motion/camera0.conf
17 >> [0:motion] [NTC] [ALL] read_camera_dir: Processing config file
18 >> /etc/motion/motion.conf
19 >> [0:motion] [NTC] [ALL] config_camera: Processing camera config file
20 >> /etc/motion/motion.conf
21 >> realloc(): invalid old size
22 >> Aborted
23 > Could you try to get a stack trace from that?
24 >
25 >
26 > I've never used "motion" and I don't know its source code, but [1] makes
27 > me wonder if the failure could be happening in [2].
28 >
29 > OTOH, from the output, "motion" has entered config_camera() and gone
30 > beyond [2] a second time before the realloc() abort - but could these
31 > two calls have received the same cnt?
32 >
33 > From my very little understanding of the code and from your output, it
34 > looks like "motion" might be processing motion.conf twice (the
35 > "Processing thread 0 [...]" line precedes a call to conf_process(), as
36 > does "Processing camera config file"). Is this intended?
37 >
38 > [1] https://github.com/Motion-Project/motion/blob/HEAD/src/conf.c#L3204
39 > [2] https://github.com/Motion-Project/motion/blob/HEAD/src/conf.c#L3180
40 >
41 > (Links are to HEAD, as that's what I started reading.)
42 >
43 Yep, that was the problem - it was when looking the output from strace
44 thst it hit me.  Its self caused in that I had a camera description file
45 and also set a config variable to read the directory that the files are
46 stored in.  From google hits on reallocate failures like this, its
47 likely a lack of protection in the code for reading the config files
48 multiple times at the root of the problem.  The documentation could be
49 clearer about this, but thats on me.
50
51 BillK