shithub: libdvdcss

Download patch

ref: c5e38a058580410541842b9d1adcaf9d75bf86d3
parent: 665cacf448bfc9f5f3c81e5a37fa2c533071b418
author: Diego Biurrun <diego@biurrun.de>
date: Tue Oct 28 14:39:46 EDT 2014

device: Check return value of snprintf() in win2k_open()

This silences a complaint from the MSVC code analyzer.

--- a/src/device.c
+++ b/src/device.c
@@ -489,7 +489,10 @@
 static int win2k_open ( dvdcss_t dvdcss, char const *psz_device )
 {
     char psz_dvd[7];
-    snprintf( psz_dvd, 7, "\\\\.\\%c:", psz_device[0] );
+    if( snprintf( psz_dvd, sizeof(psz_dvd), "\\\\.\\%c:", psz_device[0] ) < 0)
+    {
+        goto error;
+    }
 
     /* To work around an M$ bug in IOCTL_DVD_READ_STRUCTURE, we need read
      * _and_ write access to the device (so we can make SCSI Pass Through
@@ -513,13 +516,16 @@
 
     if( (HANDLE) dvdcss->i_fd == INVALID_HANDLE_VALUE )
     {
-        print_error( dvdcss, "failed opening device" );
-        return -1;
+        goto error;
     }
 
     dvdcss->i_pos = 0;
 
     return 0;
+
+error:
+    print_error( dvdcss, "failed opening device" );
+    return -1;
 }
 
 static int aspi_open( dvdcss_t dvdcss, char const * psz_device )