Re: [OpenWrt-Devel] [PATCH][netifd] fix error checking of asprintf
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. - Felix ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/mailman/listinfo/openwrt-devel
Re: [OpenWrt-Devel] [PATCH][netifd] fix error checking of asprintf
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
Re: [OpenWrt-Devel] [PATCH][netifd] fix error checking of asprintf
On 2012-12-03 1:21 PM, Frank Meerkötter wrote: 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; Patch does not apply. Please use git-send-email - Felix ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/mailman/listinfo/openwrt-devel
[OpenWrt-Devel] [PATCH][netifd] fix error checking of asprintf
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 000..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