فهرست منبع

linux-v4l2: Replace invocations of sprintf with snprintf

Fixes deprecation warnings in Xcode 14/clang on macOS and reduces
chance of buffer overflows.
PatTheMav 3 سال پیش
والد
کامیت
ecdbab6c7a
1فایلهای تغییر یافته به همراه8 افزوده شده و 2 حذف شده
  1. 8 2
      plugins/linux-v4l2/v4l2-input.c

+ 8 - 2
plugins/linux-v4l2/v4l2-input.c

@@ -416,8 +416,14 @@ static void v4l2_device_list(obs_property_t *prop, obs_data_t *settings)
 
 		/* make sure device names are unique */
 		char unique_device_name[68];
-		sprintf(unique_device_name, "%s (%s)", video_cap.card,
-			video_cap.bus_info);
+		int ret = snprintf(unique_device_name,
+				   sizeof(unique_device_name), "%s (%s)",
+				   video_cap.card, video_cap.bus_info);
+		if (ret >= sizeof(unique_device_name))
+			blog(LOG_DEBUG,
+			     "linux-v4l2: A format truncation may have occurred."
+			     " This can be ignored since it is quite improbable.");
+
 		obs_property_list_add_string(prop, unique_device_name,
 					     device.array);
 		blog(LOG_INFO, "Found device '%s' at %s", video_cap.card,