[PATCH] compositor: Fix buggy snprintf that sets module path

Chad Versace chad.versace at linux.intel.com
Wed May 23 23:39:07 PDT 2012


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Oh, that's very simple. Why didn't I think of that?

v2 coming soon.

On 05/23/2012 11:36 PM, Dima Ryazanov wrote:
> Wouldn't this be simpler?
> 
> snprintf(path, sizeof path, "%s/%s", MODULEDIR, name);
> 
> On Wed, May 23, 2012 at 11:32 PM, Chad Versace <chad.versace at linux.intel.com <mailto:chad.versace at linux.intel.com>> wrote:
> 
>     If the MODULEDIR string contains '%', then
>        snprintf(path, sizeof(path), MODULEDIR "/%s", name);
>     does not do what you want.
> 
>     Fix this by replacing snprintf with stncpy followed by strncat.
> 
>     Signed-off-by: Chad Versace <chad.versace at linux.intel.com <mailto:chad.versace at linux.intel.com>>
>     ---
>      src/compositor.c |    8 +++++---
>      1 file changed, 5 insertions(+), 3 deletions(-)
> 
>     diff --git a/src/compositor.c b/src/compositor.c
>     index 3c1e058..e556e70 100644
>     --- a/src/compositor.c
>     +++ b/src/compositor.c
>     @@ -2773,10 +2773,12 @@ load_module(const char *name, const char *entrypoint, void **handle)
>            char path[PATH_MAX];
>            void *module, *init;
> 
>     -       if (name[0] != '/')
>     -               snprintf(path, sizeof path, MODULEDIR "/%s", name);
>     -       else
>     +       if (name[0] != '/') {
>     +               strncpy(path, MODULEDIR "/", sizeof(path) - 1);
>     +               strncat(path, name, sizeof(path) - sizeof(MODULEDIR "/") - 1);
>     +       } else {
>                    snprintf(path, sizeof path, "%s", name);
>     +       }
> 
>            module = dlopen(path, RTLD_LAZY);
>            if (!module) {
>     --
>     1.7.10.2
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJPvdeJAAoJEAIvNt057x8ijGYP/AhwfQZGlkprabvAnE030XF0
zp6S/h5G4rh2L6i1udZq5XWR4mCdWJXxWhkxOcvjcZ4Y0K+lNIP4l5vkrtrLKCku
RUejmV8bt0j3Wp0c22NtP1qwIDrquQ1CIO/6YFka0474VTDp84AcAM9DwkFvrnVw
UmWerCRno15cfCvNDhpoY1kd5Otr8VYwolO9LA0TZE1LuoPFi3jqeMbUluHvnOa9
Ml9CJibdlMbjm0UonCIwiWpXQ/cdWAG9js0UD0LhPskd0aINc3FlqkM5txxQAoST
7ULus4n9XEJxXiFE1BIoAC6MzZ3OQTdBltEdUeA7MkM1UI+d9znAxmUjwYRltQp4
BlOljTzJkS+aPcLO0jLzgvRhg27WhiOM0KEYapQrm9CsA5Be4IguYX+4E1maRZ2b
VD43n7czOTR7VlIVQiujRhne6URYEzB94wno9zeBc8tdmJR9SlyVMBoHiVXpZBbd
NKTWr2lwuDXgdny4z8x1y47Jmg1oDkwffNvCPyLJa0SgECWy2NyxQOpO+hOFLSeK
iq69HYg+YbbJnueo3f7xTpLNktpklsPdpiXaMj1/k4O1qWt3GHg8toUIRAuvFuQA
eLjX9WgZnMGt+YI+ZYdHiqUD4rF/7Ac5eqNQErRE62Zh02UqQ1wrVKolfM0V0/gs
aXisCja0pfuoXxuEIaSY
=briF
-----END PGP SIGNATURE-----


More information about the wayland-devel mailing list