Jelajahi Sumber

linux-capture: Replace invocations of sprintf with snprintf

Fixes deprecation warnings in Xcode 14/clang on macOS and reduces
chance of buffer overflows.
PatTheMav 3 tahun lalu
induk
melakukan
ae01a626b6
1 mengubah file dengan 7 tambahan dan 1 penghapusan
  1. 7 1
      plugins/linux-capture/xshm-input.c

+ 7 - 1
plugins/linux-capture/xshm-input.c

@@ -365,7 +365,13 @@ static bool xshm_server_changed(obs_properties_t *props, obs_property_t *p,
 			x11_screen_geo(xcb, i, &w, &h);
 
 		if (name == NULL) {
-			sprintf(name_tmp, "%" PRIuFAST32, i);
+			int ret = snprintf(name_tmp, sizeof(name_tmp),
+					   "%" PRIuFAST32, i);
+			if (ret >= sizeof(name_tmp))
+				blog(LOG_DEBUG,
+				     "linux-capture: A format truncation may have occurred."
+				     " This can be ignored since it is quite improbable.");
+
 			name = name_tmp;
 		}