Hi,

while building with -D_FORTIFY_SOURCE i noticed a small problem in
how netifd is using asprintf(). To check if an allocation by asprintf()
worked or not the return value must be checked. Checking the pointer
argument is undefined.

Please review and apply (for now i have created a patch against the package,
fixing it upstream might be the way to go).

Regards,
Frank

---
commit 626874984862ccb31dd5ccea378113d26acdb218
Author: Frank Meerkötter <fr...@meerkoetter.org>
Date:   Thu Nov 22 14:51:22 2012 +0100

    fix error checking of asprintf
    
    $ man asprintf
    [...]
    RETURN VALUE
           When  successful,  these  functions return the number of bytes 
printed, just like sprintf(3).
           If memory allocation wasn't possible, or some other error occurs, 
these functions will return -1,
           and the contents of strp is undefined.

diff --git 
a/trunk/package/network/config/netifd/patches/020-fix_asprintf_api_usage.patch 
b/trunk/package/network/config/netifd/patches/020-fix_asprintf_api_
new file mode 100644
index 0000000..b31efa7
--- /dev/null
+++ 
b/trunk/package/network/config/netifd/patches/020-fix_asprintf_api_usage.patch
@@ -0,0 +1,12 @@
+--- a/ubus.c
++++ b/ubus.c
+@@ -727,8 +727,7 @@ netifd_ubus_add_interface(struct interfa
+       struct ubus_object *obj = &iface->ubus;
+       char *name = NULL;
+ 
+-      asprintf(&name, "%s.interface.%s", main_object.name, iface->name);
+-      if (!name)
++      if (asprintf(&name, "%s.interface.%s", main_object.name, iface->name) 
== -1)
+               return;
+ 
+       obj->name = name;

_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to