Coverage Report

Created: 2026-09-03 07:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/samba/lib/util/talloc_keep_secret.c
Line
Count
Source
1
/*
2
 * Copyright (c) 2019      Andreas Schneider <asn@samba.org>
3
 *
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17
18
#include "replace.h"
19
#include <talloc.h>
20
#include "lib/util/fault.h"
21
#include "talloc_keep_secret.h"
22
23
static int talloc_keep_secret_destructor(void *ptr)
24
656
{
25
656
  size_t size = talloc_get_size(ptr);
26
27
656
  if (unlikely(size == 0)) {
28
0
    return 0;
29
0
  }
30
31
656
  BURN_PTR_SIZE(ptr, size);
32
33
656
  return 0;
34
656
}
35
36
void _talloc_keep_secret(void *ptr, const char *name)
37
656
{
38
656
  size_t size;
39
40
656
  if (unlikely(ptr == NULL)) {
41
0
#ifdef DEVELOPER
42
0
    smb_panic("Invalid talloc pointer");
43
0
#endif
44
0
    return;
45
0
  }
46
47
656
  size = talloc_get_size(ptr);
48
656
  if (unlikely(size == 0)) {
49
0
    return;
50
0
  }
51
52
  /*
53
   * Overwrite talloc name only if it reveals memory content.
54
   * That prevents breaking talloc_get_type_abort().
55
   */
56
656
  if (talloc_get_name(ptr) == ptr) {
57
38
    talloc_set_name_const(ptr, name);
58
38
  }
59
656
  talloc_set_destructor(ptr, talloc_keep_secret_destructor);
60
656
}