Make the logic for checking service type string 95/156595/3 accepted/tizen/unified/20171019.145804 submit/tizen/20171019.074138
authorJiung <jiung.yu@samsung.com>
Thu, 19 Oct 2017 05:33:23 +0000 (14:33 +0900)
committerJiung Yu <jiung.yu@samsung.com>
Thu, 19 Oct 2017 07:09:54 +0000 (07:09 +0000)
Change-Id: I83ba4bc6aa00555542453456d80ae80a13eec3af
Signed-off-by: Yu jiung <jiung.yu@samsung.com>
packaging/capi-network-asp.spec
src/asp-client.c

index 5e7c9e6..bcbc0ae 100755 (executable)
@@ -2,7 +2,7 @@
 
 Name:       capi-network-asp
 Summary:    An Application Service Platform(ASP) libraries in Native API
-Version:    0.0.20
+Version:    0.0.21
 Release:    1
 Group:      Network & Connectivity/API
 License:    Apache-2.0
index 3336f6d..08ad4c7 100644 (file)
@@ -70,7 +70,8 @@
  *****************************************************************************/
 
 #define INSTANCE_NAME_LEN 63
-#define SERVICE_TYPE_LEN 15
+#define MAX_SERVICE_NAME_LEN 15
+#define MAX_SERVICE_TYPE_LEN 255
 #define PROTO_LEN 4
 #define KEY_LEN 9 /* http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt */
 #define KEY_MIN 0x20 /* RFC 20 */
@@ -1455,14 +1456,22 @@ int asp_advert_destroy(asp_advert_service_h adv_service)
        return ASP_ERROR_NONE;
 }
 
-static bool __is_valid_service_name(char *service_name)
+static bool __is_valid_service_type_for_wfds(char *service_type)
 {
        int pos = 0;
-       while(service_name[pos] != 0) {
-               if (!g_ascii_isalpha(service_name[pos]) &&
-                       !g_ascii_isdigit(service_name[pos]) &&
-                       service_name[pos] != '.' &&
-                       service_name[pos] != '-')
+
+       /* Wi-Fi Peer-to-Peer Services Technical Specification v1.1
+       * The UTF-8 encoded service name (and therefore the contents
+       * of each service_name parameter) shall be 255 bytes or less
+       */
+       if (strlen(service_type) > MAX_SERVICE_TYPE_LEN)
+               return false;
+
+       while(service_type[pos] != 0) {
+               if (!g_ascii_isalpha(service_type[pos]) &&
+                       !g_ascii_isdigit(service_type[pos]) &&
+                       service_type[pos] != '.' &&
+                       service_type[pos] != '-')
                        return false;
                pos++;
        }
@@ -1471,23 +1480,42 @@ static bool __is_valid_service_name(char *service_name)
 
 static bool __is_valid_service_type(char *service_type)
 {
-       int type_len = strlen(service_type) - PROTO_LEN - 1;
-       char *proto = &(service_type[type_len + 1]);
-       int pos = 1;
+       int srv_name_len = strlen(service_type) - PROTO_LEN - 1;
+       char *proto;
+       int pos;
+
+       if(srv_name_len < 2)
+               return __is_valid_service_type_for_wfds(service_type);
 
+       proto = &(service_type[srv_name_len + 1]);
        if (strncmp(proto, "_udp", PROTO_LEN) != 0 && strncmp(proto, "_tcp", PROTO_LEN) != 0)
-               return __is_valid_service_name(service_type);
+               return __is_valid_service_type_for_wfds(service_type);
+
+       /* Service Type = <_>service_name.<_><Transport protocol>
+       * Service Name description:
+       * Shall be at least 1 character and no more than 15 characters long
+       * Shall contain only US-ASCII [ANSI.X3.4-1986] letters 'A' - 'Z' and
+       * 'a' - 'z', digits '0' - '9', and hyphens ('-', ASCII 0x2D or decimal 45)
+       * Shall contain at least one letter ('A' - 'Z' or 'a' - ‘z')
+       * Shall NOT begin or end with a hyphen
+       */
+
+       if (srv_name_len > MAX_SERVICE_NAME_LEN + 1)
+               return false;
 
-       if (type_len > SERVICE_TYPE_LEN + 1)
+       if (service_type[0] != '_' || service_type[1] == '-' ||
+            service_type[srv_name_len] != '.')
                return false;
 
-       while (pos < type_len) {
+       pos = 1;
+       while (pos < srv_name_len) {
                if (!g_ascii_isalpha(service_type[pos]) &&
                        !g_ascii_isdigit(service_type[pos]) &&
                        service_type[pos] != '-')
                        return false;
                pos++;
        }
+
        return true;
 }
 
@@ -1511,6 +1539,13 @@ int asp_advert_set_service_type(asp_advert_service_h adv_service,
                __ASP_LOG_FUNC_END__;
                return ASP_ERROR_INVALID_PARAMETER;
        }
+
+       if (strlen(service_type) == 0) {
+               ASP_LOGE("Zero length value");
+               __ASP_LOG_FUNC_END__;
+               return ASP_ERROR_INVALID_PARAMETER;
+       }
+
        ASP_LOGD("service [%p]", adv_service);
 
        if (!__is_valid_service_type(service_type)) {