s4:registry/util - Don't include the trailing '\0' in the internal data format but...
[ira/wip.git] / source4 / lib / registry / util.c
index 88b9d18afa77f575fed5bdcb31f3b91e0287a7d6..764660121f0c247eceb6463a35b93ae645ddeb6e 100644 (file)
@@ -56,6 +56,7 @@ _PUBLIC_ char *reg_val_data_string(TALLOC_CTX *mem_ctx,
                                   const DATA_BLOB data)
 {
        char *ret = NULL;
+       size_t ret_cnt;
 
        if (data.length == 0)
                return talloc_strdup(mem_ctx, "");
@@ -63,18 +64,27 @@ _PUBLIC_ char *reg_val_data_string(TALLOC_CTX *mem_ctx,
        switch (type) {
                case REG_EXPAND_SZ:
                case REG_SZ:
-                       convert_string_talloc_convenience(mem_ctx, iconv_convenience, CH_UTF16, CH_UNIX,
-                                             data.data, data.length,
-                                             (void **)&ret, NULL, false);
-                       return ret;
+                       convert_string_talloc_convenience(mem_ctx,
+                                                         iconv_convenience,
+                                                         CH_UTF16, CH_UNIX,
+                                                         data.data,
+                                                         data.length,
+                                                         (void **)&ret,
+                                                         &ret_cnt, false);
+                       ret = talloc_realloc(mem_ctx, ret, char, ret_cnt + 1);
+                       ret[ret_cnt] = '\0';
+                       break;
                case REG_BINARY:
                        ret = data_blob_hex_string_upper(mem_ctx, &data);
-                       return ret;
+                       break;
                case REG_DWORD:
-                       if (*(int *)data.data == 0)
-                               return talloc_strdup(mem_ctx, "0");
-                       return talloc_asprintf(mem_ctx, "0x%x",
-                                              *(int *)data.data);
+                       if (*(int *)data.data == 0) {
+                               ret = talloc_strdup(mem_ctx, "0");
+                       } else {
+                               ret = talloc_asprintf(mem_ctx, "0x%x",
+                                                     *(int *)data.data);
+                       }
+                       break;
                case REG_MULTI_SZ:
                        /* FIXME */
                        break;
@@ -119,13 +129,16 @@ _PUBLIC_ bool reg_string_to_val(TALLOC_CTX *mem_ctx,
 
        /* Convert data appropriately */
 
-       switch (*type)
-       {
+       switch (*type) {
                case REG_SZ:
                case REG_EXPAND_SZ:
-               convert_string_talloc_convenience(mem_ctx, iconv_convenience, CH_UNIX, CH_UTF16,
-                                                    data_str, strlen(data_str)+1,
-                                                    (void **)&data->data, &data->length, false);
+                       convert_string_talloc_convenience(mem_ctx,
+                                                         iconv_convenience,
+                                                         CH_UNIX, CH_UTF16,
+                                                         data_str,
+                                                         strlen(data_str),
+                                                         (void **)&data->data,
+                                                         &data->length, false);
 
                        break;