diff --git a/configure.ac b/configure.ac index 65e6d4f..3bff474 100644 --- a/configure.ac +++ b/configure.ac @@ -225,6 +225,33 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([ ], [ ])], [ ], [ AC_MSG_RESULT([no]) ]) +CFLAGS="$save_CFLAGS" + +AC_DEFUN([AC_CHECK_FORTIFY_SOURCE], [ + AC_MSG_CHECKING([for _FORTIFY_SOURCE value with -O2]) + old_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -O2" + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ + #include + #ifndef _FORTIFY_SOURCE + #error + #endif + int main() { printf("%d\n", _FORTIFY_SOURCE); return 0; } + ]])], + [ + fortify_source_value=`./conftest$EXEEXT` + ], + [ + AC_MSG_RESULT([no]) + fortify_source_value=0 + ] + ) + CFLAGS="$old_CFLAGS" + AC_SUBST([fortify_source_value]) +]) +AC_CHECK_FORTIFY_SOURCE +AM_CONDITIONAL([NO_FORTIFY_SOURCE], [test "x$fortify_source_value" = "x0"]) dnl set the plugindir where plugins should be installed (for src/Makefile.am) if test "x${prefix}" = "x$HOME"; then diff --git a/src/Makefile.am b/src/Makefile.am index 9ee9e90..8dfd846 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -87,7 +87,7 @@ libgsticamerasrc_la_CPPFLAGS += -DCHROME_SLIM_CAMHAL endif # for hardening-check -libgsticamerasrc_la_CPPFLAGS+= -fstack-protector -fPIE -fPIC -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security +libgsticamerasrc_la_CPPFLAGS+= -fstack-protector -fPIE -fPIC -Wformat -Wformat-security libgsticamerasrc_la_LIBADD = $(GST_LIBS) \ -lgstallocators-$(GST_API_VERSION) \ @@ -101,7 +101,13 @@ libgsticamerasrc_la_LIBADD = $(GST_LIBS) \ libgsticamerasrc_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) # for hardening-check -libgsticamerasrc_la_LDFLAGS += -fPIE -fPIC -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Wl,-z,relro -Wl,-z,now +libgsticamerasrc_la_LDFLAGS += -fPIE -fPIC -Wformat -Wformat-security -Wl,-z,relro -Wl,-z,now + +# test default fortify level +if NO_FORTIFY_SOURCE +libgsticamerasrc_la_CPPFLAGS+= -D_FORTIFY_SOURCE=2 +libgsticamerasrc_la_LDFLAGS+= -D_FORTIFY_SOURCE=2 +endif # headers we need but don't want installed noinst_HEADERS = gstcamerasrc.h \ diff --git a/src/gstcameraformat.cpp b/src/gstcameraformat.cpp index 374ee9c..891d9c5 100644 --- a/src/gstcameraformat.cpp +++ b/src/gstcameraformat.cpp @@ -385,15 +385,14 @@ GstCaps *gst_camerasrc_get_all_caps () vector main_res_range; static GstCaps *caps = NULL; - if (caps != NULL) { - return gst_caps_simplify(caps); + if (caps != NULL && GST_IS_CAPS(caps)) { + return caps; } - caps = gst_caps_new_empty(); #if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23 GstVaDisplay *display_drm = NULL; display_drm = gst_va_display_drm_new_from_path("/dev/dri/renderD128"); if (NULL == display_drm) { - GST_ERROR("Couldn't create a VA DRM display"); + g_printerr("Couldn't create a VA DRM display"); return NULL; } #endif @@ -406,8 +405,7 @@ GstCaps *gst_camerasrc_get_all_caps () //get configuration of camera int ret = get_camera_info(i, info); if (ret != 0) { - GST_ERROR("failed to get camera info from libcamhal"); - gst_caps_unref(caps); + g_printerr("failed to get camera info from libcamhal"); #if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23 if (display_drm) { gst_object_unref(display_drm); @@ -420,8 +418,7 @@ GstCaps *gst_camerasrc_get_all_caps () ret = register_format_and_resolution(configs, fmt_res, main_res_range); if (ret != 0) { - GST_ERROR("failed to get format info from libcamhal"); - gst_caps_unref(caps); + g_printerr("failed to get format info from libcamhal"); #if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23 if (display_drm) { gst_object_unref(display_drm); @@ -432,11 +429,13 @@ GstCaps *gst_camerasrc_get_all_caps () } } + caps = gst_caps_new_empty(); #if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23 set_structure_to_caps(main_res_range, &caps, display_drm); #else set_structure_to_caps(main_res_range, &caps); #endif + caps = gst_caps_simplify(caps); main_res_range.clear(); #if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23 if (display_drm) { @@ -445,5 +444,5 @@ GstCaps *gst_camerasrc_get_all_caps () } #endif - return gst_caps_simplify(caps); + return caps; } diff --git a/src/gstcameraformat.h b/src/gstcameraformat.h index ed55bf3..949af15 100644 --- a/src/gstcameraformat.h +++ b/src/gstcameraformat.h @@ -44,9 +44,6 @@ #ifndef __GST_CAMERAFORMAT_H__ #define __GST_CAMERAFORMAT_H__ -GST_DEBUG_CATEGORY_EXTERN(gst_camerasrc_debug); -#define GST_CAT_DEFAULT gst_camerasrc_debug - GstCaps *gst_camerasrc_get_all_caps (); #endif /* __GST_CAMERAFORMAT_H__ */ diff --git a/src/gstcamerasrc.cpp b/src/gstcamerasrc.cpp index e068bcd..e46379b 100644 --- a/src/gstcamerasrc.cpp +++ b/src/gstcamerasrc.cpp @@ -177,7 +177,7 @@ G_DEFINE_TYPE_WITH_CODE (Gstcamerasrc, gst_camerasrc, GST_TYPE_CAM_PUSH_SRC, G_DEFINE_TYPE_WITH_CODE (Gstcamerasrc, gst_camerasrc, GST_TYPE_CAM_PUSH_SRC, G_IMPLEMENT_INTERFACE(GST_TYPE_CAMERASRC_3A_IF, gst_camerasrc_3a_interface_init); G_IMPLEMENT_INTERFACE(GST_TYPE_CAMERASRC_ISP_IF, gst_camerasrc_isp_interface_init); - G_IMPLEMENT_INTERFACE(GST_TYPE_CAMERASRC_DEWARPING_IF, gst_camerasrc_dewarping_interface_init) ); + G_IMPLEMENT_INTERFACE(GST_TYPE_CAMERASRC_DEWARPING_IF, gst_camerasrc_dewarping_interface_init)); #endif static void gst_camerasrc_set_property (GObject * object, guint prop_id, @@ -922,13 +922,13 @@ static GstStaticPadTemplate video_pad_template = GST_STATIC_PAD_TEMPLATE( GST_CAM_BASE_VIDEO_PAD_NAMES, GST_PAD_SRC, GST_PAD_REQUEST, - gst_camerasrc_get_all_caps()); + {gst_camerasrc_get_all_caps()}); static GstStaticPadTemplate still_pad_template = GST_STATIC_PAD_TEMPLATE( GST_CAM_BASE_STILL_PAD_NAMES, GST_PAD_SRC, GST_PAD_REQUEST, - gst_camerasrc_get_all_caps()); + {gst_camerasrc_get_all_caps()}); static void gst_camerasrc_class_init (GstcamerasrcClass * klass) @@ -953,6 +953,8 @@ gst_camerasrc_class_init (GstcamerasrcClass * klass) gstelement_class->request_new_pad = GST_DEBUG_FUNCPTR(gst_camerasrc_request_new_pad); gstelement_class->release_pad = GST_DEBUG_FUNCPTR(gst_camerasrc_release_pad); + GST_DEBUG_CATEGORY_INIT(gst_camerasrc_debug, "icamerasrc", 0, "camerasrc source element"); + g_object_class_install_property(gobject_class,PROP_BUFFERCOUNT, g_param_spec_int("buffer-count","buffer count","The number of buffer to allocate when do the streaming", MIN_PROP_BUFFERCOUNT,MAX_PROP_BUFFERCOUNT,DEFAULT_PROP_BUFFERCOUNT, @@ -1227,8 +1229,6 @@ gst_camerasrc_class_init (GstcamerasrcClass * klass) basesrc_class->negotiate = GST_DEBUG_FUNCPTR(gst_camerasrc_negotiate); basesrc_class->decide_allocation = GST_DEBUG_FUNCPTR(gst_camerasrc_decide_allocation); pushsrc_class->fill = GST_DEBUG_FUNCPTR(gst_camerasrc_fill); - - GST_DEBUG_CATEGORY_INIT (gst_camerasrc_debug, "icamerasrc", 0, "camerasrc source element"); } static void diff --git a/src/gstcamerasrcbufferpool.cpp b/src/gstcamerasrcbufferpool.cpp index 8fa999a..2d253c9 100644 --- a/src/gstcamerasrcbufferpool.cpp +++ b/src/gstcamerasrcbufferpool.cpp @@ -89,6 +89,19 @@ gst_camerasrc_meta_api_get_type (void) return type; } +static gboolean +gst_camerasrc_meta_init (GstMeta * meta, gpointer params, GstBuffer * buffer) +{ + GstCamerasrcMeta *emeta = (GstCamerasrcMeta *) meta; + + emeta->index = 0; + emeta->mem = NULL; + emeta->buffer = NULL; + + return TRUE; +} + + const GstMetaInfo * gst_camerasrc_meta_get_info (void) { @@ -98,7 +111,7 @@ gst_camerasrc_meta_get_info (void) if (g_once_init_enter (&meta_info)) { const GstMetaInfo *meta = gst_meta_register (gst_camerasrc_meta_api_get_type (), "GstCamerasrcMeta", - sizeof (GstCamerasrcMeta), (GstMetaInitFunction) NULL, + sizeof (GstCamerasrcMeta), gst_camerasrc_meta_init, (GstMetaFreeFunction) NULL, (GstMetaTransformFunction) NULL); g_once_init_leave (&meta_info, meta); } diff --git a/src/interfaces/Makefile.am b/src/interfaces/Makefile.am index afdcc25..4d9d77e 100644 --- a/src/interfaces/Makefile.am +++ b/src/interfaces/Makefile.am @@ -59,12 +59,18 @@ libgsticamerainterface_@GST_API_VERSION@_la_CPPFLAGS += -DCHROME_SLIM_CAMHAL endif # for hardening-check -libgsticamerainterface_@GST_API_VERSION@_la_CPPFLAGS += -fstack-protector-all -fPIE -fPIC -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security +libgsticamerainterface_@GST_API_VERSION@_la_CPPFLAGS += -fstack-protector-all -fPIE -fPIC -Wformat -Wformat-security libgsticamerainterface_@GST_API_VERSION@_la_LIBADD = $(GST_LIBS) $(CAMHAL_LIBS) # for hardening-check -libgsticamerainterface_@GST_API_VERSION@_la_LDFLAGS = -fPIE -fPIC -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Wl,-z,relro -Wl,-z,now -version-info $(LT_VERSION_INFO) +libgsticamerainterface_@GST_API_VERSION@_la_LDFLAGS = -fPIE -fPIC -Wformat -Wformat-security -Wl,-z,relro -Wl,-z,now -version-info $(LT_VERSION_INFO) + +# test default fortify level +if NO_FORTIFY_SOURCE +libgsticamerainterface_@GST_API_VERSION@_la_CPPFLAGS+= -D_FORTIFY_SOURCE=2 +libgsticamerainterface_@GST_API_VERSION@_la_LDFLAGS+= -D_FORTIFY_SOURCE=2 +endif libgsticamerainterfaceincludedir = $(includedir)/gstreamer-@GST_API_VERSION@/gst/icamera