Fix length return for SCARD_ATTR_VENDOR_NAME
authorakallabeth <akallabeth@posteo.net>
Wed, 27 Jan 2021 22:25:57 +0000 (23:25 +0100)
committerakallabeth <akallabeth@users.noreply.github.com>
Thu, 25 Feb 2021 08:51:41 +0000 (09:51 +0100)
(cherry picked from commit cf2d26dbbd7491d2039c6bb13cd4cc0130f50cd6)

winpr/libwinpr/smartcard/smartcard_pcsc.c

index 199cfc5..745bba5 100644 (file)
@@ -2457,22 +2457,25 @@ static LONG WINAPI PCSC_SCardGetAttrib(SCARDHANDLE hCard, DWORD dwAttrId, LPBYTE
        {
                if (dwAttrId == SCARD_ATTR_VENDOR_NAME)
                {
-                       const char* vendorName;
-
-                       /**
-                        * pcsc-lite adds a null terminator to the vendor name,
-                        * while WinSCard doesn't. Strip the null terminator.
-                        */
-
-                       if (pcbAttrLenAlloc)
-                               vendorName = (char*)*conv.ppb;
-                       else
-                               vendorName = (char*)pbAttr;
-
-                       if (vendorName)
-                               *pcbAttrLen = strlen(vendorName);
-                       else
-                               *pcbAttrLen = 0;
+                       if (pbAttr)
+                       {
+                               const char* vendorName;
+
+                               /**
+                                * pcsc-lite adds a null terminator to the vendor name,
+                                * while WinSCard doesn't. Strip the null terminator.
+                                */
+
+                               if (pcbAttrLenAlloc)
+                                       vendorName = (char*)*conv.ppb;
+                               else
+                                       vendorName = (char*)pbAttr;
+
+                               if (vendorName)
+                                       *pcbAttrLen = strnlen(vendorName, *pcbAttrLen);
+                               else
+                                       *pcbAttrLen = 0;
+                       }
                }
        }
        else