LCOV - code coverage report
Current view: top level - librpc/tests - test_ndr_string.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 328 328 100.0 %
Date: 2024-04-21 15:09:00 Functions: 22 22 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Tests for librpc ndr_string.c
       3             :  *
       4             :  * Copyright (C) Catalyst.NET Ltd 2019
       5             :  *
       6             :  * This program is free software; you can redistribute it and/or modify
       7             :  * it under the terms of the GNU General Public License as published by
       8             :  * the Free Software Foundation; either version 3 of the License, or
       9             :  * (at your option) any later version.
      10             :  *
      11             :  * This program is distributed in the hope that it will be useful,
      12             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :  * GNU General Public License for more details.
      15             :  *
      16             :  * You should have received a copy of the GNU General Public License
      17             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18             :  *
      19             :  */
      20             : 
      21             : /*
      22             :  * from cmocka.c:
      23             :  * These headers or their equivalents should be included prior to
      24             :  * including
      25             :  * this header file.
      26             :  *
      27             :  * #include <stdarg.h>
      28             :  * #include <stddef.h>
      29             :  * #include <setjmp.h>
      30             :  *
      31             :  * This allows test applications to use custom definitions of C standard
      32             :  * library functions and types.
      33             :  *
      34             :  */
      35             : #include "replace.h"
      36             : #include <setjmp.h>
      37             : #include <cmocka.h>
      38             : 
      39             : #include "librpc/ndr/ndr_string.c"
      40             : 
      41             : /*
      42             :  * Try and pull a null terminated string from a zero length buffer
      43             :  * Should fail for both 1 byte, and 2 byte character strings.
      44             :  */
      45           1 : static void test_pull_string_zero_len_nul_term(void **state)
      46             : {
      47           1 :         struct ndr_pull ndr = {0};
      48           1 :         enum ndr_err_code err;
      49           1 :         ndr_flags_type flags = NDR_SCALARS;
      50           1 :         uint8_t data[] = {0x0, 0x0};
      51           1 :         const char *s = NULL;
      52             : 
      53           1 :         ndr.flags = LIBNDR_FLAG_STR_UTF8 | LIBNDR_FLAG_STR_NULLTERM;
      54           1 :         ndr.data = data;
      55           1 :         ndr.data_size = 0;
      56           1 :         err = ndr_pull_string(&ndr, flags, &s);
      57           1 :         assert_int_equal(err, NDR_ERR_BUFSIZE);
      58           1 :         assert_null(s);
      59           1 :         assert_int_equal(0, ndr.offset);
      60             : 
      61           1 :         ndr.flags = LIBNDR_FLAG_STR_NULLTERM;
      62           1 :         ndr.offset = 0;
      63           1 :         err = ndr_pull_string(&ndr, flags, &s);
      64           1 :         assert_int_equal(err, NDR_ERR_BUFSIZE);
      65           1 :         assert_null(s);
      66           1 :         assert_int_equal(0, ndr.offset);
      67             : 
      68           1 : }
      69             : 
      70             : /*
      71             :  * Try and pull a null terminated string from a 1 byte buffer
      72             :  * Should succeed for 1 byte character and
      73             :  *        fail    for 2 byte character strings.
      74             :  */
      75           1 : static void test_pull_string_len_1_nul_term(void **state)
      76             : {
      77           1 :         struct ndr_pull ndr = {0};
      78           1 :         enum ndr_err_code err;
      79           1 :         ndr_flags_type flags = NDR_SCALARS;
      80           1 :         const char *s = NULL;
      81           1 :         uint8_t data[] = {0x0, 0x0};
      82             : 
      83           1 :         ndr.flags = LIBNDR_FLAG_STR_UTF8 | LIBNDR_FLAG_STR_NULLTERM;
      84           1 :         ndr.data = data;
      85           1 :         ndr.data_size = 1;
      86           1 :         err = ndr_pull_string(&ndr, flags, &s);
      87           1 :         assert_int_equal(err, NDR_ERR_SUCCESS);
      88           1 :         assert_non_null(s);
      89           1 :         assert_int_equal(1, ndr.offset);
      90             : 
      91           1 :         ndr.offset = 0;
      92           1 :         ndr.flags = LIBNDR_FLAG_STR_NULLTERM;
      93           1 :         err = ndr_pull_string(&ndr, flags, &s);
      94           1 :         assert_int_equal(err, NDR_ERR_BUFSIZE);
      95           1 :         assert_int_equal(0, ndr.offset);
      96           1 : }
      97             : 
      98             : /*
      99             :  * Try and pull a null terminated string from a 2 byte buffer
     100             :  * Should succeed for both 1 byte, and 2 byte character strings.
     101             :  */
     102           1 : static void test_pull_string_len_2_nul_term(void **state)
     103             : {
     104           1 :         struct ndr_pull ndr = {0};
     105           1 :         enum ndr_err_code err;
     106           1 :         ndr_flags_type flags = NDR_SCALARS;
     107           1 :         const char *s;
     108           1 :         uint8_t data[] = {0x0, 0x0};
     109             : 
     110           1 :         ndr.flags = LIBNDR_FLAG_STR_UTF8 | LIBNDR_FLAG_STR_NULLTERM;
     111           1 :         ndr.data = data;
     112           1 :         ndr.data_size = 2;
     113           1 :         err = ndr_pull_string(&ndr, flags, &s);
     114           1 :         assert_int_equal(err, NDR_ERR_SUCCESS);
     115           1 :         assert_non_null(s);
     116           1 :         assert_int_equal(1, ndr.offset);
     117             : 
     118           1 :         ndr.offset = 0;
     119           1 :         ndr.flags = LIBNDR_FLAG_STR_NULLTERM;
     120           1 :         err = ndr_pull_string(&ndr, flags, &s);
     121           1 :         assert_int_equal(err, NDR_ERR_SUCCESS);
     122           1 :         assert_non_null(s);
     123           1 :         assert_int_equal(2, ndr.offset);
     124             : 
     125             : 
     126           1 : }
     127             : 
     128           1 : static void test_ndr_string_n_length(void **state)
     129             : {
     130           1 :         char test_str1[5] = "Test";
     131           1 :         char test_str2[5] = {0};
     132           1 :         char test_str3[32] = "This is a test too";
     133           1 :         uint8_t test_str_u16[64] = {
     134             :                 0x5C, 0x00, 0x5C, 0x00, 0x4C, 0x00, 0x6F, 0x00,
     135             :                 0x67, 0x00, 0x6F, 0x00, 0x6E, 0x00, 0x2D, 0x00,
     136             :                 0x6D, 0x00, 0x75, 0x00, 0x63, 0x00, 0x5C, 0x00,
     137             :                 0x6B, 0x00, 0x79, 0x00, 0x6F, 0x00, 0x63, 0x00,
     138             :                 0x65, 0x00, 0x72, 0x00, 0x61, 0x00, 0x2D, 0x00,
     139             :                 0x6D, 0x00, 0x75, 0x00, 0x63, 0x00, 0x2D, 0x00,
     140             :                 0x6E, 0x00, 0x00, 0x00 };
     141           1 :         size_t len;
     142             : 
     143           1 :         len = ndr_string_n_length(test_str1, sizeof(test_str1), 1);
     144           1 :         assert_int_equal(len, 5);
     145             : 
     146           1 :         len = ndr_string_n_length(test_str1, sizeof(test_str1) - 1, 1);
     147           1 :         assert_int_equal(len, 4);
     148             : 
     149           1 :         len = ndr_string_n_length(test_str2, sizeof(test_str2), 1);
     150           1 :         assert_int_equal(len, 1);
     151             : 
     152           1 :         len = ndr_string_n_length(test_str3, sizeof(test_str3), 1);
     153           1 :         assert_int_equal(len, 19);
     154             : 
     155           1 :         len = ndr_string_n_length(test_str3, 0, 1);
     156           1 :         assert_int_equal(len, 0);
     157             : 
     158           1 :         len = ndr_string_n_length(test_str_u16, 32, 2);
     159           1 :         assert_int_equal(len, 26);
     160           1 : }
     161             : 
     162           1 : static void test_pull_string_array(void **state)
     163             : {
     164             :         /* We try pulling long string arrays without long strings */
     165           1 :         const char **r = NULL;
     166           1 :         struct ndr_pull ndr = {0};
     167           1 :         enum ndr_err_code err;
     168           1 :         TALLOC_CTX *mem_ctx = talloc_new(NULL);
     169           1 :         size_t len = 1 * 1024 * 1024;
     170           1 :         uint8_t *data = talloc_array(mem_ctx, uint8_t, len);
     171           1 :         size_t i;
     172             : 
     173     1048578 :         for (i = 0; i < len; i++) {
     174     1572864 :                 data[i] = (i & 1) ? '\0' : 'X';
     175             :         }
     176             : 
     177           1 :         ndr.current_mem_ctx = mem_ctx;
     178             : 
     179           1 :         ndr.flags = (LIBNDR_FLAG_REF_ALLOC |
     180             :                      LIBNDR_FLAG_REMAINING |
     181             :                      LIBNDR_FLAG_STR_NULLTERM |
     182             :                      LIBNDR_FLAG_STR_RAW8);
     183           1 :         ndr.data = data;
     184           1 :         ndr.data_size = len;
     185             : 
     186           1 :         err = ndr_pull_string_array(&ndr, NDR_SCALARS, &r);
     187           1 :         assert_int_equal(err, NDR_ERR_SUCCESS);
     188           1 :         assert_string_equal(r[0], "X");
     189           1 :         assert_string_equal(r[len / 3], "X");
     190           1 :         assert_string_equal(r[len / 2 - 1], "X");
     191           1 :         assert_ptr_equal(r[len / 2], NULL);
     192           1 :         TALLOC_FREE(mem_ctx);
     193           1 : }
     194             : 
     195           1 : static void test_pull_string_zero_len_utf8_NOTERM_STR_NO_EMBEDDED_NUL(void **state)
     196             : {
     197           1 :         struct ndr_pull ndr = {0};
     198           1 :         enum ndr_err_code err;
     199           1 :         ndr_flags_type flags = NDR_SCALARS;
     200           1 :         const char *s = NULL;
     201           1 :         uint8_t data[] = { 0x0, 0x0 };
     202             : 
     203           1 :         ndr.flags = LIBNDR_FLAG_STR_UTF8 | LIBNDR_FLAG_STR_SIZE2 | LIBNDR_FLAG_STR_NOTERM | LIBNDR_FLAG_STR_NO_EMBEDDED_NUL;
     204             : 
     205           1 :         ndr.data = data;
     206           1 :         ndr.data_size = sizeof(data);
     207           1 :         err = ndr_pull_string(&ndr, flags, &s);
     208           1 :         assert_int_equal(err, NDR_ERR_SUCCESS);
     209           1 :         assert_non_null(s);
     210           1 :         assert_string_equal(s, "");
     211           1 :         assert_int_equal(sizeof(data), ndr.offset);
     212             : 
     213           1 : }
     214             : 
     215           1 : static void test_pull_string_utf8_nul_term_STR_NO_EMBEDDED_NUL(void **state)
     216             : {
     217             : 
     218           1 :         struct ndr_pull ndr = {0};
     219           1 :         enum ndr_err_code err;
     220           1 :         ndr_flags_type flags = NDR_SCALARS;
     221           1 :         const char *s = NULL;
     222           1 :         uint8_t data[] = { 0x2, 0x0, 'a', 0x0 };
     223             : 
     224           1 :         ndr.flags = LIBNDR_FLAG_STR_UTF8 | LIBNDR_FLAG_STR_SIZE2 | LIBNDR_FLAG_STR_NO_EMBEDDED_NUL;
     225             : 
     226           1 :         ndr.data = data;
     227           1 :         ndr.data_size = sizeof(data);
     228           1 :         err = ndr_pull_string(&ndr, flags, &s);
     229           1 :         assert_int_equal(err, NDR_ERR_SUCCESS);
     230           1 :         assert_non_null(s);
     231           1 :         assert_string_equal(s, "a");
     232           1 :         assert_int_equal(sizeof(data), ndr.offset);
     233             : 
     234           1 : }
     235             : 
     236           1 : static void test_pull_string_utf8_nul_term_NOTERM_STR_NO_EMBEDDED_NUL(void **state)
     237             : {
     238             : 
     239           1 :         struct ndr_pull ndr = {0};
     240           1 :         enum ndr_err_code err;
     241           1 :         ndr_flags_type flags = NDR_SCALARS;
     242           1 :         const char *s = NULL;
     243           1 :         uint8_t data[] = { 0x2, 0x0, 'a', 0x0 };
     244             : 
     245           1 :         ndr.flags = LIBNDR_FLAG_STR_UTF8 | LIBNDR_FLAG_STR_SIZE2 | LIBNDR_FLAG_STR_NOTERM | LIBNDR_FLAG_STR_NO_EMBEDDED_NUL;
     246             : 
     247           1 :         ndr.data = data;
     248           1 :         ndr.data_size = sizeof(data);
     249           1 :         err = ndr_pull_string(&ndr, flags, &s);
     250           1 :         assert_int_equal(err, NDR_ERR_CHARCNV);
     251           1 :         assert_int_equal(2, ndr.offset);
     252             : 
     253           1 : }
     254             : 
     255           1 : static void test_pull_string_utf8_nullterm_STR_NO_EMBEDDED_NUL(void **state)
     256             : {
     257             : 
     258           1 :         struct ndr_pull ndr = {0};
     259           1 :         enum ndr_err_code err;
     260           1 :         ndr_flags_type flags = NDR_SCALARS;
     261           1 :         const char *s = NULL;
     262           1 :         uint8_t data[] = { 0x4, 0x0, 'a', 'b', 'c', 0x0};
     263             : 
     264           1 :         ndr.flags = LIBNDR_FLAG_STR_UTF8 | LIBNDR_FLAG_STR_SIZE2 | LIBNDR_FLAG_STR_NO_EMBEDDED_NUL;
     265             : 
     266           1 :         ndr.data = data;
     267           1 :         ndr.data_size = sizeof(data);
     268           1 :         err = ndr_pull_string(&ndr, flags, &s);
     269           1 :         assert_int_equal(err, NDR_ERR_SUCCESS);
     270           1 :         assert_non_null(s);
     271           1 :         assert_string_equal(s, "abc");
     272           1 :         assert_int_equal(sizeof(data), ndr.offset);
     273             : 
     274           1 : }
     275             : 
     276           1 : static void test_pull_string_utf8_STR_NO_EMBEDDED_NUL(void **state)
     277             : {
     278             : 
     279           1 :         struct ndr_pull ndr = {0};
     280           1 :         enum ndr_err_code err;
     281           1 :         ndr_flags_type flags = NDR_SCALARS;
     282           1 :         const char *s = NULL;
     283           1 :         uint8_t data[] = { 0x3, 0x0, 'a', 'b', 'c'};
     284             : 
     285           1 :         ndr.flags = LIBNDR_FLAG_STR_UTF8 | LIBNDR_FLAG_STR_SIZE2 | LIBNDR_FLAG_STR_NO_EMBEDDED_NUL;
     286             : 
     287           1 :         ndr.data = data;
     288           1 :         ndr.data_size = sizeof(data);
     289           1 :         err = ndr_pull_string(&ndr, flags, &s);
     290           1 :         assert_int_equal(err, NDR_ERR_CHARCNV);
     291           1 :         assert_int_equal(2, ndr.offset);
     292             : 
     293           1 : }
     294             : 
     295           1 : static void test_pull_string_utf8_NOTERM_STR_NO_EMBEDDED_NUL(void **state)
     296             : {
     297             : 
     298           1 :         struct ndr_pull ndr = {0};
     299           1 :         enum ndr_err_code err;
     300           1 :         ndr_flags_type flags = NDR_SCALARS;
     301           1 :         const char *s = NULL;
     302           1 :         uint8_t data[] = { 0x3, 0x0, 'a', 'b', 'c'};
     303             : 
     304           1 :         ndr.flags = LIBNDR_FLAG_STR_UTF8 | LIBNDR_FLAG_STR_SIZE2 | LIBNDR_FLAG_STR_NOTERM | LIBNDR_FLAG_STR_NO_EMBEDDED_NUL;
     305             : 
     306           1 :         ndr.data = data;
     307           1 :         ndr.data_size = sizeof(data);
     308           1 :         err = ndr_pull_string(&ndr, flags, &s);
     309           1 :         assert_int_equal(err, NDR_ERR_SUCCESS);
     310           1 :         assert_non_null(s);
     311           1 :         assert_string_equal(s, "abc");
     312           1 :         assert_int_equal(sizeof(data), ndr.offset);
     313             : 
     314           1 : }
     315             : 
     316           1 : static void test_pull_string_utf8_nullterm_NOTERM_STR_NO_EMBEDDED_NUL(void **state)
     317             : {
     318             : 
     319           1 :         struct ndr_pull ndr = {0};
     320           1 :         enum ndr_err_code err;
     321           1 :         ndr_flags_type flags = NDR_SCALARS;
     322           1 :         const char *s = NULL;
     323           1 :         uint8_t data[] = { 0x4, 0x0, 'a', 'b', 'c', 0x0};
     324             : 
     325           1 :         ndr.flags = LIBNDR_FLAG_STR_UTF8 | LIBNDR_FLAG_STR_SIZE2 | LIBNDR_FLAG_STR_NOTERM | LIBNDR_FLAG_STR_NO_EMBEDDED_NUL;
     326             : 
     327           1 :         ndr.data = data;
     328           1 :         ndr.data_size = sizeof(data);
     329           1 :         err = ndr_pull_string(&ndr, flags, &s);
     330           1 :         assert_int_equal(err, NDR_ERR_CHARCNV);
     331           1 :         assert_int_equal(2, ndr.offset);
     332             : 
     333           1 : }
     334             : 
     335           1 : static void test_pull_string_utf8_LIBNDR_FLAG_STR_NOTERM_STR_NO_EMBEDDED_NUL_fail(void **state)
     336             : {
     337             : 
     338           1 :         struct ndr_pull ndr = {0};
     339           1 :         enum ndr_err_code err;
     340           1 :         ndr_flags_type flags = NDR_SCALARS;
     341           1 :         const char *s = NULL;
     342           1 :         uint8_t data[] = { 0x3, 0x0, 'a', 0x0, 'a'};
     343             : 
     344           1 :         ndr.flags = LIBNDR_FLAG_STR_UTF8 | LIBNDR_FLAG_STR_SIZE2 | LIBNDR_FLAG_STR_NOTERM | LIBNDR_FLAG_STR_NO_EMBEDDED_NUL;
     345             : 
     346           1 :         ndr.data = data;
     347           1 :         ndr.data_size = sizeof(data);
     348           1 :         err = ndr_pull_string(&ndr, flags, &s);
     349           1 :         assert_int_equal(err, NDR_ERR_CHARCNV);
     350           1 :         assert_int_equal(2, ndr.offset);
     351             : 
     352           1 : }
     353             : 
     354           1 : static void test_pull_string_utf16_LIBNDR_FLAG_STR_NOTERM_STR_NO_EMBEDDED_NUL(void **state)
     355             : {
     356             : 
     357           1 :         struct ndr_pull ndr = {0};
     358           1 :         enum ndr_err_code err;
     359           1 :         ndr_flags_type flags = NDR_SCALARS;
     360           1 :         const char *s = NULL;
     361           1 :         uint8_t data[] = { 0x3, 0x0, 'a', 0x0, 'b', 0x0, 'c', 0x0};
     362             : 
     363           1 :         ndr.flags = LIBNDR_FLAG_STR_SIZE2 | LIBNDR_FLAG_STR_NOTERM | LIBNDR_FLAG_STR_NO_EMBEDDED_NUL;
     364             : 
     365           1 :         ndr.data = data;
     366           1 :         ndr.data_size = sizeof(data);
     367           1 :         err = ndr_pull_string(&ndr, flags, &s);
     368           1 :         assert_int_equal(err, NDR_ERR_SUCCESS);
     369           1 :         assert_non_null(s);
     370           1 :         assert_string_equal(s, "abc");
     371           1 :         assert_int_equal(sizeof(data), ndr.offset);
     372             : 
     373           1 : }
     374             : 
     375           1 : static void test_pull_string_utf16_LIBNDR_FLAG_STR_NOTERM_STR_NO_EMBEDDED_NUL_fail(void **state)
     376             : {
     377             : 
     378           1 :         struct ndr_pull ndr = {0};
     379           1 :         enum ndr_err_code err;
     380           1 :         ndr_flags_type flags = NDR_SCALARS;
     381           1 :         const char *s = NULL;
     382           1 :         uint8_t data[] = { 0x3, 0x0, 'a', 0x0, 0x0, 0x0, 'c', 0x0};
     383             : 
     384           1 :         ndr.flags = LIBNDR_FLAG_STR_SIZE2 | LIBNDR_FLAG_STR_NOTERM | LIBNDR_FLAG_STR_NO_EMBEDDED_NUL;
     385             : 
     386           1 :         ndr.data = data;
     387           1 :         ndr.data_size = sizeof(data);
     388           1 :         err = ndr_pull_string(&ndr, flags, &s);
     389           1 :         assert_int_equal(err, NDR_ERR_CHARCNV);
     390           1 :         assert_int_equal(2, ndr.offset);
     391             : 
     392           1 : }
     393             : 
     394           1 : static void test_pull_string_zero_len_utf8_STR_NO_EMBEDDED_NUL(void **state)
     395             : {
     396             : 
     397           1 :         struct ndr_pull ndr = {0};
     398           1 :         enum ndr_err_code err;
     399           1 :         ndr_flags_type flags = NDR_SCALARS;
     400           1 :         const char *s = NULL;
     401           1 :         uint8_t data[] = { 0x0, 0x0 };
     402             : 
     403           1 :         ndr.flags = LIBNDR_FLAG_STR_UTF8 | LIBNDR_FLAG_STR_SIZE2 | LIBNDR_FLAG_STR_NO_EMBEDDED_NUL;
     404             : 
     405           1 :         ndr.data = data;
     406           1 :         ndr.data_size = sizeof(data);
     407           1 :         err = ndr_pull_string(&ndr, flags, &s);
     408           1 :         assert_int_equal(err, NDR_ERR_SUCCESS);
     409           1 :         assert_non_null(s);
     410           1 :         assert_string_equal(s, "");
     411           1 :         assert_int_equal(sizeof(data), ndr.offset);
     412             : 
     413           1 : }
     414             : 
     415           1 : static void test_pull_string_nul_only_utf8_STR_NO_EMBEDDED_NUL(void **state)
     416             : {
     417             : 
     418           1 :         struct ndr_pull ndr = {0};
     419           1 :         enum ndr_err_code err;
     420           1 :         ndr_flags_type flags = NDR_SCALARS;
     421           1 :         const char *s = NULL;
     422           1 :         uint8_t data[] = { 0x2, 0x0, 0x0, 0x0 };
     423             : 
     424           1 :         ndr.flags = LIBNDR_FLAG_STR_UTF8 | LIBNDR_FLAG_STR_SIZE2 | LIBNDR_FLAG_STR_NO_EMBEDDED_NUL;
     425             : 
     426           1 :         ndr.data = data;
     427           1 :         ndr.data_size = sizeof(data);
     428           1 :         err = ndr_pull_string(&ndr, flags, &s);
     429           1 :         assert_int_equal(err, NDR_ERR_CHARCNV);
     430           1 :         assert_int_equal(2, ndr.offset);
     431             : 
     432           1 : }
     433             : 
     434           1 : static void test_pull_string_nul_term_utf8_NOTERM_NDR_REMAINING_STR_NO_EMBEDDED_NUL(void **state)
     435             : {
     436             : 
     437           1 :         struct ndr_pull ndr = {0};
     438           1 :         enum ndr_err_code err;
     439           1 :         ndr_flags_type flags = NDR_SCALARS;
     440           1 :         const char *s = NULL;
     441           1 :         uint8_t data[] = {'a', 'b', 'c', 0x0 };
     442             : 
     443           1 :         ndr.flags = LIBNDR_FLAG_STR_UTF8 | LIBNDR_FLAG_STR_NOTERM | LIBNDR_FLAG_REMAINING | LIBNDR_FLAG_STR_NO_EMBEDDED_NUL;
     444             : 
     445           1 :         ndr.data = data;
     446           1 :         ndr.data_size = sizeof(data);
     447           1 :         err = ndr_pull_string(&ndr, flags, &s);
     448           1 :         assert_int_equal(err, NDR_ERR_CHARCNV);
     449           1 :         assert_int_equal(0, ndr.offset);
     450             : 
     451           1 : }
     452             : 
     453           1 : static void test_pull_string_utf8_NOTERM_NDR_REMAINING_STR_NO_EMBEDDED_NUL(void **state)
     454             : {
     455             : 
     456           1 :         struct ndr_pull ndr = {0};
     457           1 :         enum ndr_err_code err;
     458           1 :         ndr_flags_type flags = NDR_SCALARS;
     459           1 :         const char *s = NULL;
     460           1 :         uint8_t data[] = {'a', 'b', 'c' };
     461             : 
     462           1 :         ndr.flags = LIBNDR_FLAG_STR_UTF8 | LIBNDR_FLAG_STR_NOTERM | LIBNDR_FLAG_REMAINING | LIBNDR_FLAG_STR_NO_EMBEDDED_NUL;
     463             : 
     464           1 :         ndr.data = data;
     465           1 :         ndr.data_size = sizeof(data);
     466           1 :         err = ndr_pull_string(&ndr, flags, &s);
     467           1 :         assert_int_equal(err, NDR_ERR_SUCCESS);
     468           1 :         assert_non_null(s);
     469           1 :         assert_string_equal(s, "abc");
     470           1 :         assert_int_equal(sizeof(data), ndr.offset);
     471             : 
     472           1 : }
     473             : 
     474           1 : static void test_pull_string_nul_term_utf8_STR_NULLTERM_NDR_REMAINING_STR_NO_EMBEDDED_NUL(void **state)
     475             : {
     476             : 
     477           1 :         struct ndr_pull ndr = {0};
     478           1 :         enum ndr_err_code err;
     479           1 :         ndr_flags_type flags = NDR_SCALARS;
     480           1 :         const char *s = NULL;
     481           1 :         uint8_t data[] = {'a', 'b', 'c', 0x0 };
     482             : 
     483           1 :         ndr.flags = LIBNDR_FLAG_STR_UTF8 | LIBNDR_FLAG_STR_NULLTERM | LIBNDR_FLAG_REMAINING | LIBNDR_FLAG_STR_NO_EMBEDDED_NUL;
     484             : 
     485           1 :         ndr.data = data;
     486           1 :         ndr.data_size = sizeof(data);
     487           1 :         err = ndr_pull_string(&ndr, flags, &s);
     488           1 :         assert_int_equal(err, NDR_ERR_SUCCESS);
     489           1 :         assert_non_null(s);
     490           1 :         assert_string_equal(s, "abc");
     491           1 :         assert_int_equal(sizeof(data), ndr.offset);
     492             : 
     493           1 : }
     494             : 
     495           1 : static void test_pull_string_utf8_NDR_REMAINING_STR_NULLTERM_STR_NO_EMBEDDED_NUL(void **state)
     496             : {
     497             : 
     498           1 :         struct ndr_pull ndr = {0};
     499           1 :         enum ndr_err_code err;
     500           1 :         ndr_flags_type flags = NDR_SCALARS;
     501           1 :         const char *s = NULL;
     502           1 :         uint8_t data[] = {'a', 'b', 'c' };
     503             : 
     504           1 :         ndr.flags = LIBNDR_FLAG_STR_UTF8 | LIBNDR_FLAG_STR_NULLTERM | LIBNDR_FLAG_REMAINING | LIBNDR_FLAG_STR_NO_EMBEDDED_NUL;
     505             : 
     506           1 :         ndr.data = data;
     507           1 :         ndr.data_size = sizeof(data);
     508           1 :         err = ndr_pull_string(&ndr, flags, &s);
     509           1 :         assert_int_equal(err, NDR_ERR_CHARCNV);
     510           1 :         assert_int_equal(0, ndr.offset);
     511             : 
     512           1 : }
     513             : 
     514           1 : int main(int argc, const char **argv)
     515             : {
     516           1 :         const struct CMUnitTest tests[] = {
     517             :                 cmocka_unit_test(test_pull_string_zero_len_nul_term),
     518             :                 cmocka_unit_test(test_pull_string_len_1_nul_term),
     519             :                 cmocka_unit_test(test_pull_string_len_2_nul_term),
     520             :                 cmocka_unit_test(test_ndr_string_n_length),
     521             :                 cmocka_unit_test(test_pull_string_array),
     522             :                 cmocka_unit_test(test_pull_string_zero_len_utf8_NOTERM_STR_NO_EMBEDDED_NUL),
     523             :                 cmocka_unit_test(test_pull_string_utf8_nul_term_STR_NO_EMBEDDED_NUL),
     524             :                 cmocka_unit_test(test_pull_string_utf8_nul_term_NOTERM_STR_NO_EMBEDDED_NUL),
     525             :                 cmocka_unit_test(test_pull_string_utf8_nullterm_STR_NO_EMBEDDED_NUL),
     526             :                 cmocka_unit_test(test_pull_string_utf8_STR_NO_EMBEDDED_NUL),
     527             :                 cmocka_unit_test(test_pull_string_utf8_NOTERM_STR_NO_EMBEDDED_NUL),
     528             :                 cmocka_unit_test(test_pull_string_utf8_nullterm_NOTERM_STR_NO_EMBEDDED_NUL),
     529             :                 cmocka_unit_test(test_pull_string_utf8_LIBNDR_FLAG_STR_NOTERM_STR_NO_EMBEDDED_NUL_fail),
     530             :                 cmocka_unit_test(test_pull_string_utf16_LIBNDR_FLAG_STR_NOTERM_STR_NO_EMBEDDED_NUL),
     531             :                 cmocka_unit_test(test_pull_string_utf16_LIBNDR_FLAG_STR_NOTERM_STR_NO_EMBEDDED_NUL_fail),
     532             :                 cmocka_unit_test(test_pull_string_zero_len_utf8_STR_NO_EMBEDDED_NUL),
     533             :                 cmocka_unit_test(test_pull_string_nul_only_utf8_STR_NO_EMBEDDED_NUL),
     534             :                 cmocka_unit_test(test_pull_string_nul_term_utf8_NOTERM_NDR_REMAINING_STR_NO_EMBEDDED_NUL),
     535             :                 cmocka_unit_test(test_pull_string_utf8_NOTERM_NDR_REMAINING_STR_NO_EMBEDDED_NUL),
     536             :                 cmocka_unit_test(test_pull_string_nul_term_utf8_STR_NULLTERM_NDR_REMAINING_STR_NO_EMBEDDED_NUL),
     537             :                 cmocka_unit_test(test_pull_string_utf8_NDR_REMAINING_STR_NULLTERM_STR_NO_EMBEDDED_NUL)
     538             :         };
     539             : 
     540           1 :         cmocka_set_message_output(CM_OUTPUT_SUBUNIT);
     541           1 :         return cmocka_run_group_tests(tests, NULL, NULL);
     542             : }

Generated by: LCOV version 1.14