Coverage Report

Created: 2026-07-25 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/samba/source3/lib/substitute_generic.c
Line
Count
Source
1
/*
2
   Unix SMB/CIFS implementation.
3
   Samba utility functions
4
5
   Copyright (C) Andrew Tridgell 1992-2001
6
   Copyright (C) Simo Sorce      2001-2002
7
   Copyright (C) Martin Pool     2003
8
   Copyright (C) James Peach   2006
9
   Copyright (C) Jeremy Allison  1992-2007
10
11
   This program is free software; you can redistribute it and/or modify
12
   it under the terms of the GNU General Public License as published by
13
   the Free Software Foundation; either version 3 of the License, or
14
   (at your option) any later version.
15
16
   This program is distributed in the hope that it will be useful,
17
   but WITHOUT ANY WARRANTY; without even the implied warranty of
18
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
   GNU General Public License for more details.
20
21
   You should have received a copy of the GNU General Public License
22
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
*/
24
25
#include "includes.h"
26
27
/**
28
 Similar to string_sub2, but it will accept only allocated strings
29
 and may realloc them so pay attention at what you pass on no
30
 pointers inside strings, no const may be passed
31
 as string.
32
**/
33
34
char *realloc_string_sub2(char *string,
35
      const char *pattern,
36
      const char *insert,
37
      bool remove_unsafe_characters,
38
      bool allow_trailing_dollar)
39
0
{
40
0
  const char *unsafe_characters = NULL;
41
0
  char safe_character = '\0';
42
0
  bool ok;
43
44
0
  if (!insert || !pattern || !*pattern || !string || !*string)
45
0
    return NULL;
46
47
0
  if (remove_unsafe_characters) {
48
0
    unsafe_characters = STRING_SUB_UNSAFE_CHARACTERS;
49
0
    safe_character = '_';
50
0
  }
51
52
0
  ok = realloc_string_sub_raw(&string,
53
0
            pattern,
54
0
            insert,
55
0
            false,  /* replace_once */
56
0
            allow_trailing_dollar,
57
0
            unsafe_characters,
58
0
            safe_character);
59
0
  if (!ok) {
60
0
    DBG_ERR("out of memory, realloc_string_sub_raw()!\n");
61
    /*
62
     * The calling convention of realloc_string_sub2()
63
     * is very strange regarding stale string pointers.
64
     *
65
     * It is assumed the given string was allocated
66
     * on talloc_tos(), so we just don't touch
67
     * it at all here...
68
     */
69
0
    return NULL;
70
0
  }
71
72
0
  return string;
73
0
}
74
75
char *realloc_string_sub(char *string,
76
      const char *pattern,
77
      const char *insert)
78
0
{
79
0
  return realloc_string_sub2(string, pattern, insert, true, false);
80
0
}