On 03/12/12 10:43, Felix Fietkau wrote:
> On 2012-11-22 3:03 PM, Frank Meerkötter wrote:
>> 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).
> Please send a patch that I can 'git am' in the netifd git tree. I don't
> want to have any files in netifd/patches in trunk.
>

Patch follows:

see 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.

Signed-off-by: Frank Meerkötter <fr...@meerkoetter.org>
---
 ubus.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/ubus.c b/ubus.c
index 7b85930..d6d4188 100644
--- a/ubus.c
+++ b/ubus.c
@@ -727,8 +727,7 @@ netifd_ubus_add_interface(struct interface *iface)
        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;
-- 
1.7.10.4

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

Reply via email to