Skip to contentSkip to conversation

libgphoto2: Fix build when security flags are enabled with clang

PATCH New Khem Raj 1 participant 3 messages Aug 15, 2016

lore
Share & tools
lore

Khem Raj

author
#0 lore raw

PATCH 1/3 libgphoto2: Fix build when security flags are enabled with clang

clang is more pedantic and throws below errors

../../libgphoto2-2.5.8/camlibs/ptp2/chdk.c:1131:14: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
sprintf(lua,luascript); /* This expands the %q inside the string too ... do not optimize away. */
^~~~~~~~~

Backport a patch to silence the warnings where it avoids the use of sprintf all the way

---
 .../libgphoto2-2.5.8/avoid_using_sprintf.patch     | 133 +++++++++++++++++++++
 .../recipes-graphics/gphoto2/libgphoto2_2.5.8.bb   |   1 +
 2 files changed, 134 insertions(+)
 create mode 100644 meta-oe/recipes-graphics/gphoto2/libgphoto2-2.5.8/avoid_using_sprintf.patch
meta-oe/recipes-graphics/gphoto2/libgphoto2-2.5.8/avoid_using_sprintf.patch new file +133 -0
new file mode 100644
index 0000000..fba4c69
@@ -0,0 +1,133 @@
+From 4adfe5a6c9db07537df302f3c17713515bf23a2e Mon Sep 17 00:00:00 2001
+From: Marcus Meissner <[email protected]>
+Date: Sat, 11 Jul 2015 09:38:13 +0000
+Subject: [PATCH] avoid use of sprintf to convert %% to %, duplicate the macro
+
+git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@15490 67ed7778-7388-44ab-90cf-0a291f65f57c
+---
+ camlibs/ptp2/chdk.c     |  8 ++---
+ camlibs/ptp2/chdk_ptp.h | 82 +++++++++++++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 84 insertions(+), 6 deletions(-)
+
+diff --git a/camlibs/ptp2/chdk.c b/camlibs/ptp2/chdk.c
+index 5fb84ea..3b8a995 100644
+--- a/camlibs/ptp2/chdk.c
++++ b/camlibs/ptp2/chdk.c
+@@ -1119,18 +1119,14 @@ chdk_camera_capture (Camera *camera, CameraCaptureType type, CameraFilePath *pat
+ 	int		ret, retint;
+ 	char		*table, *s;
+ 	PTPParams	*params = &camera->pl->params;
+-	char		*lua;
+-	const char	*luascript =	PTP_CHDK_LUA_SERIALIZE_MSGS \
++	const char	*luascript = PTP_CHDK_LUA_SERIALIZE_MSGS_SIMPLEQUOTE \
+ 				PTP_CHDK_LUA_RLIB_SHOOT	\
+ 				"return rlib_shoot({info=true});\n";
+ 
+ 	ret =  camera_prepare_chdk_capture(camera, context);
+ 	if (ret != GP_OK) return ret;
+ 
+-	lua = malloc(strlen(luascript)+1);
+-	sprintf(lua,luascript); /* This expands the %q inside the string too ... do not optimize away. */
+-	ret = chdk_generic_script_run (params, lua, &table, &retint, context);
+-	free (lua);
++	ret = chdk_generic_script_run (params, luascript, &table, &retint, context);
+ 	GP_LOG_D("rlib_shoot returned table %s, retint %d\n", table, retint);
+ 	s = strstr(table, "exp=");
+ 	if (s) {
+diff --git a/camlibs/ptp2/chdk_ptp.h b/camlibs/ptp2/chdk_ptp.h
+index d11e0b7..65dcfd7 100644
+--- a/camlibs/ptp2/chdk_ptp.h
++++ b/camlibs/ptp2/chdk_ptp.h
+@@ -198,10 +198,92 @@ function serialize(v,opts)\n\
+ 	return table.concat(r)\n\
+ end\n"
+ 
++#define PTP_CHDK_LUA_SERIALIZE_SIMPLEQUOTE "\n\
++serialize_r = function(v,opts,r,seen,depth)\n\
++	local vt = type(v)\n\
++	if vt == 'nil' or  vt == 'boolean' or vt == 'number' then\n\
++		table.insert(r,tostring(v))\n\
++		return\n\
++	end\n\
++	if vt == 'string' then\n\
++		table.insert(r,string.format('%q',v))\n\
++		return\n\
++	end\n\
++	if vt == 'table' then\n\
++		if not depth then\n\
++			depth = 1\n\
++		end\n\
++		if depth >= opts.maxdepth then\n\
++			error('serialize: max depth')\n\
++		end\n\
++		if not seen then\n\
++			seen={}\n\
++		elseif seen[v] then\n\
++			if opts.err_cycle then\n\
++				error('serialize: cycle')\n\
++			else\n\
++				table.insert(r,'\"cycle:'..tostring(v)..'\"')\n\
++				return\n\
++			end\n\
++		end\n\
++		seen[v] = true;\n\
++		table.insert(r,'{')\n\
++		for k,v1 in pairs(v) do\n\
++			if opts.pretty then\n\
++				table.insert(r,'\\n'..string.rep(' ',depth))\n\
++			end\n\
++			if type(k) == 'string' and string.match(k,'^[_%a][%a%d_]*$') then\n\
++				table.insert(r,k)\n\
++			else\n\
++				table.insert(r,'[')\n\
++				serialize_r(k,opts,r,seen,depth+1)\n\
++				table.insert(r,']')\n\
++			end\n\
++			table.insert(r,'=')\n\
++			serialize_r(v1,opts,r,seen,depth+1)\n\
++			table.insert(r,',')\n\
++		end\n\
++		if opts.pretty then\n\
++			table.insert(r,'\\n'..string.rep(' ',depth-1))\n\
++		end\n\
++		table.insert(r,'}')\n\
++		return\n\
++	end\n\
++	if opts.err_type then\n\
++		error('serialize: unsupported type ' .. vt, 2)\n\
++	else\n\
++		table.insert(r,'\"'..tostring(v)..'\"')\n\
++	end\n\
++end\n\
++serialize_defaults = {\n\
++	maxdepth=10,\n\
++	err_type=true,\n\
++	err_cycle=true,\n\
++	pretty=false,\n\
++}\n\
++function serialize(v,opts)\n\
++	if opts then\n\
++		for k,v in pairs(serialize_defaults) do\n\
++			if not opts[k] then\n\
++				opts[k]=v\n\
++			end\n\
++		end\n\
++	else\n\
++		opts=serialize_defaults\n\
++	end\n\
++	local r={}\n\
++	serialize_r(v,opts,r)\n\
++	return table.concat(r)\n\
++end\n"
++
+ #define PTP_CHDK_LUA_SERIALIZE_MSGS \
+ PTP_CHDK_LUA_SERIALIZE\
+ "usb_msg_table_to_string=serialize\n"
+ 
++#define PTP_CHDK_LUA_SERIALIZE_MSGS_SIMPLEQUOTE \
++PTP_CHDK_LUA_SERIALIZE_SIMPLEQUOTE\
++"usb_msg_table_to_string=serialize\n"
++
+ #define PTP_CHDK_LUA_EXTEND_TABLE \
+ "function extend_table(target,source,deep)\n\
+ 	if type(target) ~= 'table' then\n\
meta-oe/recipes-graphics/gphoto2/libgphoto2_2.5.8.bb +1 -0
index dde14ad..098da79 100644
@@ -15,6 +15,7 @@ SRC_URI = "${SOURCEFORGE_MIRROR}/gphoto/libgphoto2-${PV}.tar.bz2;name=libgphoto2
            file://40-libgphoto2.rules \
            file://0001-configure.ac-remove-AM_PO_SUBDIRS.patch \
            file://0002-correct-jpeg-memsrcdest-support.patch \
+           file://avoid_using_sprintf.patch \
 "
 
 SRC_URI[libgphoto2.md5sum] = "873ab01aced49c6b92a98e515db5dcef"
Signature · 1 line
2.9.3
author
#1 lore raw

PATCH 2/3 udisks2: Update to 2.1.7

Fix below build with musl while here

| ../../udisks-2.1.7/udisks/udisksclient.c:2004:6: warning: '__GNUC_PREREQ' is not defined, evaluates to 0 [-Wundef] | # if __GNUC_PREREQ(4,6) || __clang__

---
 .../udisks/udisks2/non-gnu-libc.patch              | 26 ++++++++++++++++++++++
 .../udisks/{udisks2_2.1.5.bb => udisks2_2.1.7.bb}  |  8 ++++---
 2 files changed, 31 insertions(+), 3 deletions(-)
 create mode 100644 meta-oe/recipes-support/udisks/udisks2/non-gnu-libc.patch
 rename meta-oe/recipes-support/udisks/{udisks2_2.1.5.bb => udisks2_2.1.7.bb} (84%)
meta-oe/recipes-support/udisks/udisks2/non-gnu-libc.patch new file +26 -0
new file mode 100644
index 0000000..98e6c75
@@ -0,0 +1,26 @@
+musl does not define __GNUC_PREREQ therefore check for C library being glibc
+if not then define the macro
+
+Upstream-Status: Pending
+Signed-off-by: Khem Raj <[email protected]>
+Index: udisks-2.1.7/udisks/udisksclient.c
+===================================================================
+--- udisks-2.1.7.orig/udisks/udisksclient.c
++++ udisks-2.1.7/udisks/udisksclient.c
+@@ -27,8 +27,15 @@
+ #include "udisksobjectinfo.h"
+ 
+ /* For __GNUC_PREREQ usage below */
+-#ifdef __GNUC__
++#ifdef __GLIBC__
+ # include <features.h>
++#else
++#if defined(__GNUC__)
++#define	__GNUC_PREREQ(__maj, __min)	\
++	(__GNUC__ > (__maj) || __GNUC__ == (__maj) && __GNUC_MINOR__ >= (__min))
++#else
++#define	__GNUC_PREREQ(__maj, __min) 0
++#endif
+ #endif
+ 
+ /**
meta-oe/recipes-support/udisks/udisks2_2.1.7.bb renamed from meta-oe/recipes-support/udisks/udisks2_2.1.5.bb +5 -3
similarity index 84%
rename from meta-oe/recipes-support/udisks/udisks2_2.1.5.bb
rename to meta-oe/recipes-support/udisks/udisks2_2.1.7.bb
index f365cfa..34762dd 100644
@@ -7,9 +7,11 @@ DEPENDS += "${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'systemd', '', d)
 
 RDEPENDS_${PN} = "acl"
 
-SRC_URI = "http://udisks.freedesktop.org/releases/udisks-${PV}.tar.bz2"
-SRC_URI[md5sum] = "73632501002e6de8244f831e38b2b98e"
-SRC_URI[sha256sum] = "2cfcf560447ea44cba2a683342c7062aaaf35e4eb554bed64ac2dd55a70a5fb6"
+SRC_URI = "http://udisks.freedesktop.org/releases/udisks-${PV}.tar.bz2 \
+           file://non-gnu-libc.patch \
+"
+SRC_URI[md5sum] = "8bccd36573b75286538bd5bd2c424f45"
+SRC_URI[sha256sum] = "abae2bb3bdc691ca13c1e4c244630b8c881c4f3b35c207299f1b39b7bec83785"
 
 inherit autotools systemd gtk-doc gobject-introspection
 
Signature · 1 line
2.9.3
author
#2 lore raw

PATCH 3/3 thunar-volman: Fix build with clang

In reply to Khem Raj

clang poins a void return for a boolean function
| ../../thunar-volman-0.8.1/thunar-volman/tvm-block-device.c:717:3: error: non-void function 'tvm_block_device_mount' should return a value [-Wreturn-type]
| g_return_if_fail (context != NULL);

---
 ...with-no-value-in-function-returning-non-v.patch | 26 ++++++++++++++++++++++
 .../thunar-volman/thunar-volman_0.8.1.bb           |  1 +
 2 files changed, 27 insertions(+)
 create mode 100644 meta-xfce/recipes-xfce/thunar-volman/thunar-volman/0001-Fix-return-with-no-value-in-function-returning-non-v.patch
meta-xfce/recipes-xfce/thunar-volman/thunar-volman/0001-Fix-return-with-no-value-in-function-returning-non-v.patch new file +26 -0
new file mode 100644
index 0000000..7233ea7
@@ -0,0 +1,26 @@
+From 2e295e9ce8f7f60a271adf004588b0d8db88db09 Mon Sep 17 00:00:00 2001
+From: Matt Thirtytwo <[email protected]>
+Date: Sat, 7 Mar 2015 22:50:32 +0100
+Subject: [PATCH] Fix return with no value in function returning non-void (bug
+ #11656)
+
+---
+ thunar-volman/tvm-block-device.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/thunar-volman/tvm-block-device.c b/thunar-volman/tvm-block-device.c
+index da31efa..edb6cad 100644
+--- a/thunar-volman/tvm-block-device.c
++++ b/thunar-volman/tvm-block-device.c
+@@ -714,7 +714,7 @@ tvm_block_device_mount (TvmContext *context)
+   GMountOperation *mount_operation;
+   GVolume         *volume;
+ 
+-  g_return_if_fail (context != NULL);
++  g_return_val_if_fail ((context != NULL), FALSE);
+ 
+   /* determine the GVolume corresponding to the udev device */
+   volume = 
+-- 
+1.9.0
+
meta-xfce/recipes-xfce/thunar-volman/thunar-volman_0.8.1.bb +1 -0
index 08e6f5b..44e3777 100644
@@ -6,6 +6,7 @@ DEPENDS = "exo glib-2.0 gtk+ libxfce4ui libxfce4util xfconf libnotify libgudev"
 
 inherit xfce
 
+SRC_URI += "file://0001-Fix-return-with-no-value-in-function-returning-non-v.patch"
 SRC_URI[md5sum] = "65ab6e05b2e808d1dcc8d36683a59b7e"
 SRC_URI[sha256sum] = "5a08bb5ce32c296a64dfbdb2406d4e45a208b2c91e4efa831dc28f1d6c2ac2bd"
 
Signature · 1 line
2.9.3