Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 258556

Summary: media-video/motion-3.2.11 segfault when logging errors from libraries
Product: Gentoo Linux Reporter: Robert Trace <bugzilla-gentoo>
Component: Current packagesAssignee: Gentoo Media-video project <media-video>
Status: RESOLVED FIXED    
Severity: normal CC: M4rkusXXL
Priority: High    
Version: unspecified   
Hardware: x86   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---
Bug Depends on:    
Bug Blocks: 247553    
Attachments: Remove glibc special-case code since it's not applicable for newer glibc

Description Robert Trace 2009-02-11 05:36:52 UTC
When motion has an issue with a library (in my case, ffmpeg wasn't built with the right useflag and thus, didn't have the codec motion wanted), it tries to log the error message from the library.  In motion.c:motion_log()

...
   /* If errno_flag is set, add on the library error message */
    if (errno_flag) {
        strcat(buf, ": ");
        n += 2;
        /*
         * this is bad - apparently gcc/libc wants to use the non-standard GNU
         * version of strerror_r, which doesn't actually put the message into
         * my buffer :-(.  I have put in a 'hack' to get around this.
         */
#if (defined(BSD))
        strerror_r(errno_save, buf + n, sizeof(buf) - n);    /* 2 for the ': ' */
#else
        strcat(buf, strerror_r(errno_save, msg_buf, sizeof(msg_buf)));
#endif
    }
...

He's right, glibc provides two distinct implementations of strerror_r().  Unfortunately, it looks like glibc 2.4 changed the one provided by default.  According to 'man 3 strerror':

"If no feature test macros are explicitly defined, then (since glibc 2.4) _POSIX_SOURCE is defined by default with the value 200112L, so that the XSI-compliant version of  strerror_r()  is provided by default."

It doesn't appear as though motion is setting any feature_test macros, so this seems to result in the XSI-flavor being used on newer glibc (as is standard in gentoo).  This variant returns 0 on success, not a string as the code is expecting.  Thus, the code ends up: strcat(buf, 0) and that doesn't work out too well.

The attached patch corrects the problem for gentoo, but it's not generic across all glibc versions.

Reproducible: Always

Steps to Reproduce:
1. Configure motion to use ffmpeg and give it an invalid/unsupported codec (ffmpeg_video_codec mpeg1 works since newer ffmpeg doesn't support mpeg1)
2. run 'motion -n'
3. Make some motion in front of camera.

Actual Results:  
motion will segfault in strcat() called from motion_log().

Expected Results:  
No segfault, just a log message indicating the problem.
Comment 1 Robert Trace 2009-02-11 05:39:27 UTC
Created attachment 181607 [details, diff]
Remove glibc special-case code since it's not applicable for newer glibc

This is not a perfect patch since it won't support versions of glibc <2.4.
Comment 2 Markus 2009-03-13 22:33:40 UTC
*** Bug 262370 has been marked as a duplicate of this bug. ***
Comment 3 Samuli Suominen (RETIRED) gentoo-dev 2009-10-09 09:44:40 UTC
This should be fixed in 3.2.11.1 (added today to Portage, sync in a hour or so if you want.)

There's more conditionals for this part of code now.
Comment 4 Robert Trace 2009-10-09 20:44:27 UTC
(In reply to comment #3)
> This should be fixed in 3.2.11.1 (added today to Portage, sync in a hour or so
> if you want.)

I agree.  The code looks better and it appears to be working properly as well.

Thanks for the update.