libusbgx: Fix readlink/buffer overrun issue. CID#56130, CID#56129
authorPhilippe De Swert <philippe.deswert@jollamobile.com>
Tue, 13 May 2014 12:55:57 +0000 (15:55 +0300)
committerKrzysztof Opasiak <k.opasiak@samsung.com>
Tue, 22 Dec 2015 19:38:54 +0000 (20:38 +0100)
Readlink() can return the total length of the buffer (here 4096/USBG_MAX_PATH_LENGTH),
so we do not want to dereference target[4096] as that would give an off by one error.

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
src/usbg.c

index d73943c..5d9c083 100644 (file)
@@ -850,7 +850,7 @@ static int usbg_parse_config_binding(usbg_config *c, char *bpath,
        usbg_function *f;
        usbg_binding *b;
 
-       nmb = readlink(bpath, target, sizeof(target));
+       nmb = readlink(bpath, target, sizeof(target) - 1 );
        if (nmb < 0) {
                ret = usbg_translate_error(errno);
                goto out;