]> git.ipfire.org Git - thirdparty/util-linux.git/blame - libmount/src/init.c
libmount: fix memory overflow [AddressSanitizer]
[thirdparty/util-linux.git] / libmount / src / init.c
CommitLineData
c12cec75
KZ
1/*
2 * Copyright (C) 2008 Karel Zak <kzak@redhat.com>
3 *
4 * This file may be redistributed under the terms of the
5 * GNU Lesser General Public License.
6 */
7
192c6aad
KZ
8/**
9 * SECTION: init
10 * @title: Library initialization
d58b3157 11 * @short_description: initialize debugging
192c6aad
KZ
12 */
13
3f31a959 14#include <stdarg.h>
c12cec75
KZ
15
16#include "mountP.h"
17
d7365821 18UL_DEBUG_DEFINE_MASK(libmount);
819d9a29 19UL_DEBUG_DEFINE_MASKNAMES(libmount) =
03e4220d 20{
35333416
KZ
21 { "all", MNT_DEBUG_ALL, "info about all subsystems" },
22 { "cache", MNT_DEBUG_CACHE, "paths and tags cache" },
23 { "cxt", MNT_DEBUG_CXT, "library context (handler)" },
24 { "diff", MNT_DEBUG_DIFF, "mountinfo changes tracking" },
25 { "fs", MNT_DEBUG_FS, "FS abstraction" },
26 { "help", MNT_DEBUG_HELP, "this help" },
27 { "locks", MNT_DEBUG_LOCKS, "mtab and utab locking" },
28 { "options", MNT_DEBUG_OPTIONS, "mount options parsing" },
29 { "tab", MNT_DEBUG_TAB, "fstab, mtab, moutninfo routines" },
30 { "update", MNT_DEBUG_UPDATE, "mtab, utab updates" },
31 { "utils", MNT_DEBUG_UTILS, "misc library utils" },
14ad2353
OO
32 { NULL, 0 }
33};
03e4220d 34
192c6aad
KZ
35/**
36 * mnt_init_debug:
d58b3157 37 * @mask: debug mask (0xffff to enable full debugging)
192c6aad 38 *
d58b3157
OO
39 * If the @mask is not specified, then this function reads
40 * the LIBMOUNT_DEBUG environment variable to get the mask.
192c6aad 41 *
d58b3157
OO
42 * Already initialized debugging stuff cannot be changed. Calling
43 * this function twice has no effect.
192c6aad 44 */
c12cec75
KZ
45void mnt_init_debug(int mask)
46{
35333416
KZ
47 if (libmount_debug_mask)
48 return;
49
274228fe 50 __UL_INIT_DEBUG(libmount, MNT_DEBUG_, mask, LIBMOUNT_DEBUG);
39de73f5 51
35333416
KZ
52 if (libmount_debug_mask != MNT_DEBUG_INIT
53 && libmount_debug_mask != (MNT_DEBUG_HELP|MNT_DEBUG_INIT)) {
39de73f5
KZ
54 const char *ver = NULL;
55 const char **features = NULL, **p;
56
39de73f5
KZ
57 mnt_get_library_version(&ver);
58 mnt_get_library_features(&features);
59
35333416 60 DBG(INIT, ul_debug("library debug mask: 0x%04x", libmount_debug_mask));
83a78332 61 DBG(INIT, ul_debug("library version: %s", ver));
39de73f5
KZ
62 p = features;
63 while (p && *p)
83a78332 64 DBG(INIT, ul_debug(" feature: %s", *p++));
39de73f5 65 }
35333416
KZ
66
67 ON_DBG(HELP, ul_debug_print_masks("LIBMOUNT_DEBUG",
68 UL_DEBUG_MASKNAMES(libmount)));
c12cec75 69}
14ad2353
OO
70
71#ifdef TEST_PROGRAM
72
73#include <errno.h>
74#include <stdlib.h>
75int main(int argc, char *argv[])
76{
77 if (argc == 2) {
78 int mask;
79
80 errno = 0;
81 mask = strtoul(argv[1], 0, 0);
82
83 if (errno)
84 return 1;
85
74d70957 86 mnt_init_debug(mask);
14ad2353
OO
87 }
88 else if (argc == 1) {
74d70957
KZ
89 mnt_init_debug(0);
90 } else
14ad2353
OO
91 return 1;
92
93 return 0;
94}
95#endif /* TEST_PROGRAM */
96