@@ -190,46 +190,36 @@ bool ccap_provider_get_device_info(const CcapProvider* provider, CcapDeviceInfo*
190190 // Initialize structure
191191 memset (deviceInfo, 0 , sizeof (CcapDeviceInfo));
192192
193- // Copy device name
194- deviceInfo->deviceName = allocate_c_string (info.deviceName );
193+ // Copy device name (with bounds checking)
194+ size_t deviceNameLen = info.deviceName .size ();
195+ if (deviceNameLen >= CCAP_MAX_DEVICE_NAME_LENGTH ) {
196+ deviceNameLen = CCAP_MAX_DEVICE_NAME_LENGTH - 1 ;
197+ }
198+ strncpy (deviceInfo->deviceName , info.deviceName .c_str (), deviceNameLen);
199+ deviceInfo->deviceName [deviceNameLen] = ' \0 ' ;
195200
196- // Copy supported pixel formats
201+ // Copy supported pixel formats (with bounds checking)
197202 deviceInfo->pixelFormatCount = info.supportedPixelFormats .size ();
198- if (deviceInfo->pixelFormatCount > 0 ) {
199- deviceInfo->supportedPixelFormats = static_cast <CcapPixelFormat*>(
200- malloc (deviceInfo-> pixelFormatCount * sizeof (CcapPixelFormat)));
203+ if (deviceInfo->pixelFormatCount > CCAP_MAX_PIXEL_FORMATS ) {
204+ deviceInfo->pixelFormatCount = CCAP_MAX_PIXEL_FORMATS ;
205+ }
201206
202- if (deviceInfo->supportedPixelFormats ) {
203- for (size_t i = 0 ; i < deviceInfo->pixelFormatCount ; ++i) {
204- deviceInfo->supportedPixelFormats [i] = convert_pixel_format_to_c (info.supportedPixelFormats [i]);
205- }
206- }
207+ for (size_t i = 0 ; i < deviceInfo->pixelFormatCount ; ++i) {
208+ deviceInfo->supportedPixelFormats [i] = convert_pixel_format_to_c (info.supportedPixelFormats [i]);
207209 }
208210
209- // Copy supported resolutions
211+ // Copy supported resolutions (with bounds checking)
210212 deviceInfo->resolutionCount = info.supportedResolutions .size ();
211- if (deviceInfo->resolutionCount > 0 ) {
212- deviceInfo->supportedResolutions = static_cast <CcapResolution*>(
213- malloc (deviceInfo->resolutionCount * sizeof (CcapResolution)));
214-
215- if (deviceInfo->supportedResolutions ) {
216- for (size_t i = 0 ; i < deviceInfo->resolutionCount ; ++i) {
217- deviceInfo->supportedResolutions [i].width = info.supportedResolutions [i].width ;
218- deviceInfo->supportedResolutions [i].height = info.supportedResolutions [i].height ;
219- }
220- }
213+ if (deviceInfo->resolutionCount > CCAP_MAX_RESOLUTIONS ) {
214+ deviceInfo->resolutionCount = CCAP_MAX_RESOLUTIONS ;
221215 }
222216
223- return true ;
224- }
225-
226- void ccap_provider_free_device_info (CcapDeviceInfo* deviceInfo) {
227- if (deviceInfo) {
228- free (deviceInfo->deviceName );
229- free (deviceInfo->supportedPixelFormats );
230- free (deviceInfo->supportedResolutions );
231- memset (deviceInfo, 0 , sizeof (CcapDeviceInfo));
217+ for (size_t i = 0 ; i < deviceInfo->resolutionCount ; ++i) {
218+ deviceInfo->supportedResolutions [i].width = info.supportedResolutions [i].width ;
219+ deviceInfo->supportedResolutions [i].height = info.supportedResolutions [i].height ;
232220 }
221+
222+ return true ;
233223}
234224
235225void ccap_provider_close (CcapProvider* provider) {
0 commit comments