Relax parameter check for pointer of {pointer, size} 06/316706/4
authorYonggoo Kang <ygace.kang@samsung.com>
Tue, 27 Aug 2024 06:20:50 +0000 (15:20 +0900)
committerYonggoo Kang <ygace.kang@samsung.com>
Tue, 27 Aug 2024 11:26:56 +0000 (20:26 +0900)
If a pointer of {pointer, size} is not NULL,
webauthn expects the pointer->pointer is not NULL and the pointer->size is not 0.
But webauthn allows the pointer is NULL and size is 0.

Change-Id: I732f550cec586d11f38d22ef4cd6fad830956000

srcs/common/utils.cpp

index 1066d3b11d8acbe218e776fcce57e4338194c37e..fb796c53e187e35f4808ac61ff7e3c34eef54625 100644 (file)
@@ -37,10 +37,12 @@ void CheckParameters(const char *str, const char *name, const bool checkBlank)
 
 void CheckParameters(const wauthn_const_buffer_s &buf, const char *name)
 {
-    if (!buf.data)
-        ThrowMsg(ClientException::InvalidParameter, name << "->data is NULL");
-    if (buf.size == 0)
-        ThrowMsg(ClientException::InvalidParameter, name << "->size is 0");
+    if (!buf.data && (buf.size != 0))
+        ThrowMsg(ClientException::InvalidParameter,
+                 name << "->data is NULL and size is not 0");
+    if (buf.data && (buf.size == 0))
+        ThrowMsg(ClientException::InvalidParameter,
+                 name << "->data is not NULL and size is 0");
 }
 
 void CheckParameters(const wauthn_const_buffer_s *buf, const char *name)
@@ -139,10 +141,12 @@ void CheckParameters(const wauthn_pubkey_cred_descriptors_s *cred_descriptors)
 {
     if (!cred_descriptors)
         return;
-    if (!cred_descriptors->descriptors)
-        ThrowMsg(ClientException::InvalidParameter, "cred_descriptors->descriptors is NULL");
-    if (cred_descriptors->size == 0)
-        ThrowMsg(ClientException::InvalidParameter, "cred_descriptors->size is 0");
+    if (!cred_descriptors->descriptors && (cred_descriptors->size != 0))
+        ThrowMsg(ClientException::InvalidParameter,
+                 "cred_descriptors->descriptors is NULL and size is not 0");
+    if (cred_descriptors->descriptors && (cred_descriptors->size == 0))
+        ThrowMsg(ClientException::InvalidParameter,
+                 "cred_descriptors->descriptors is not NULL and size is 0");
     for (size_t i = 0; i < cred_descriptors->size; ++i)
     {
         auto desc = cred_descriptors->descriptors[i];
@@ -217,10 +221,12 @@ void CheckParameters(const wauthn_pubkey_cred_hints_s *hints)
 {
     if (!hints)
         return;
-    if (!hints->hints)
-        ThrowMsg(ClientException::InvalidParameter, "hints->hints is NULL");
-    if (hints->size == 0)
-        ThrowMsg(ClientException::InvalidParameter, "hints->size is 0");
+    if (!hints->hints && (hints->size != 0))
+        ThrowMsg(ClientException::InvalidParameter,
+                 "hints->hints is NULL and size is not 0");
+    if (hints->hints && (hints->size == 0))
+        ThrowMsg(ClientException::InvalidParameter,
+                 "hints->hints is not NULL and size is 0");
     for (size_t i = 0; i < hints->size; ++i)
     {
         auto hint = hints->hints[i];
@@ -244,11 +250,12 @@ void CheckParameters(const wauthn_attestation_formats_s *attestation_formats)
 {
     if (!attestation_formats)
         return;
-    if (!attestation_formats->attestation_formats)
+    if (!attestation_formats->attestation_formats && (attestation_formats->size != 0))
         ThrowMsg(ClientException::InvalidParameter,
-                "attestation_formats->attestation_formats is NULL");
-    if (attestation_formats->size == 0)
-        ThrowMsg(ClientException::InvalidParameter, "attestation_formats->size is 0");
+                "attestation_formats->attestation_formats is NULL and size is not 0");
+    if (attestation_formats->attestation_formats && (attestation_formats->size == 0))
+        ThrowMsg(ClientException::InvalidParameter,
+                 "attestation_formats->attestation_formats is not NULL and size is 0");
     for (size_t i = 0; i < attestation_formats->size; ++i)
     {
         auto format = attestation_formats->attestation_formats[i];
@@ -260,10 +267,16 @@ void CheckParameters(const wauthn_authentication_exts_s *extensions)
 {
     if (!extensions)
         return;
-    if (!extensions->extensions)
-        ThrowMsg(ClientException::InvalidParameter, "extensions->extensions is NULL");
-    if (extensions->size == 0)
-        ThrowMsg(ClientException::InvalidParameter, "extensions->size is 0");
+    if (!extensions->extensions && (extensions->size != 0))
+    {
+        ThrowMsg(ClientException::InvalidParameter,
+                 "extensions->extensions is NULL and size is not 0");
+    }
+    if (extensions->extensions && (extensions->size == 0))
+    {
+        ThrowMsg(ClientException::InvalidParameter,
+                 "extensions->extensions is not NULL and size is 0");
+    }
     for (size_t i = 0; i < extensions->size; ++i)
     {
         auto extension = extensions->extensions[i];