api: improve api string safety
[vpp.git] / src / plugins / http_static / http_static_test.c
index 023d78a..3503a1b 100644 (file)
@@ -71,6 +71,11 @@ api_http_static_enable (vat_main_t * vam)
       else if (unformat (line_input, "fifo-size %U", unformat_memory_size,
                         &tmp))
        {
+         if (tmp >= 0x100000000ULL)
+           {
+             errmsg ("fifo-size %llu, too large", tmp);
+             return -99;
+           }
          fifo_size = (u32) tmp;
        }
       else if (unformat (line_input, "cache-size %U", unformat_memory_size,
@@ -106,11 +111,8 @@ api_http_static_enable (vat_main_t * vam)
 
   /* Construct the API message */
   M (HTTP_STATIC_ENABLE, mp);
-  vl_api_to_api_string (strnlen ((const char *) www_root, 256),
-                       (const char *) www_root,
-                       (vl_api_string_t *) & mp->www_root);
-  vl_api_to_api_string (strnlen ((const char *) uri, 256), (const char *) uri,
-                       (vl_api_string_t *) & mp->uri);
+  strncpy_s ((char *) mp->www_root, 256, (const char *) www_root, 256);
+  strncpy_s ((char *) mp->uri, 256, (const char *) uri, 256);
   mp->fifo_size = ntohl (fifo_size);
   mp->cache_size_limit = ntohl (cache_size_limit);
   mp->prealloc_fifos = ntohl (prealloc_fifos);