• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemd / systemd / 14939761809

09 May 2025 06:22PM UTC coverage: 72.251% (-0.001%) from 72.252%
14939761809

push

github

web-flow
mount-tool: honor arg_canonicalize for ACTION_UMOUNT path_is_absolute() check too (#37398)

Split out from #36337

4 of 4 new or added lines in 2 files covered. (100.0%)

3591 existing lines in 114 files now uncovered.

297546 of 411820 relevant lines covered (72.25%)

704170.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.68
/src/basic/syslog-util.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <limits.h>
4
#include <syslog.h>
5

6
#include "sd-id128.h"
7

8
#include "glob-util.h"
9
#include "hexdecoct.h"
10
#include "macro.h"
11
#include "path-util.h"
12
#include "string-table.h"
13
#include "syslog-util.h"
14
#include "unit-name.h"
15

16
int syslog_parse_priority(const char **p, int *priority, bool with_facility) {
950,290✔
17
        int a = 0, b = 0, c = 0;
950,290✔
18
        const char *end;
950,290✔
19
        size_t k;
950,290✔
20

21
        assert(p);
950,290✔
22
        assert(*p);
950,290✔
23
        assert(priority);
950,290✔
24

25
        if ((*p)[0] != '<')
950,290✔
26
                return 0;
27

28
        end = strchr(*p, '>');
414✔
29
        if (!end)
414✔
30
                return 0;
31

32
        k = end - *p;
414✔
33
        assert(k > 0);
414✔
34

35
        if (k == 2)
414✔
36
                c = undecchar((*p)[1]);
9✔
37
        else if (k == 3) {
405✔
38
                b = undecchar((*p)[1]);
399✔
39
                c = undecchar((*p)[2]);
399✔
40
        } else if (k == 4) {
6✔
41
                a = undecchar((*p)[1]);
2✔
42
                b = undecchar((*p)[2]);
2✔
43
                c = undecchar((*p)[3]);
2✔
44
        } else
45
                return 0;
46

47
        if (a < 0 || b < 0 || c < 0 ||
410✔
48
            (!with_facility && (a || b || c > 7)))
9✔
49
                return 0;
50

51
        if (with_facility)
7✔
52
                *priority = a*100 + b*10 + c;
401✔
53
        else
54
                *priority = (*priority & LOG_FACMASK) | c;
7✔
55

56
        *p += k + 1;
408✔
57
        return 1;
408✔
58
}
59

60
static const char *const log_facility_unshifted_table[LOG_NFACILITIES] = {
61
        [LOG_FAC(LOG_KERN)]     = "kern",
62
        [LOG_FAC(LOG_USER)]     = "user",
63
        [LOG_FAC(LOG_MAIL)]     = "mail",
64
        [LOG_FAC(LOG_DAEMON)]   = "daemon",
65
        [LOG_FAC(LOG_AUTH)]     = "auth",
66
        [LOG_FAC(LOG_SYSLOG)]   = "syslog",
67
        [LOG_FAC(LOG_LPR)]      = "lpr",
68
        [LOG_FAC(LOG_NEWS)]     = "news",
69
        [LOG_FAC(LOG_UUCP)]     = "uucp",
70
        [LOG_FAC(LOG_CRON)]     = "cron",
71
        [LOG_FAC(LOG_AUTHPRIV)] = "authpriv",
72
        [LOG_FAC(LOG_FTP)]      = "ftp",
73
        [LOG_FAC(LOG_LOCAL0)]   = "local0",
74
        [LOG_FAC(LOG_LOCAL1)]   = "local1",
75
        [LOG_FAC(LOG_LOCAL2)]   = "local2",
76
        [LOG_FAC(LOG_LOCAL3)]   = "local3",
77
        [LOG_FAC(LOG_LOCAL4)]   = "local4",
78
        [LOG_FAC(LOG_LOCAL5)]   = "local5",
79
        [LOG_FAC(LOG_LOCAL6)]   = "local6",
80
        [LOG_FAC(LOG_LOCAL7)]   = "local7",
81
};
82

83
DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(log_facility_unshifted, int, LOG_FAC(~0));
291✔
84

85
bool log_facility_unshifted_is_valid(int facility) {
×
UNCOV
86
        return facility >= 0 && facility <= LOG_FAC(~0);
×
87
}
88

89
static const char *const log_level_table[] = {
90
        [LOG_EMERG]   = "emerg",
91
        [LOG_ALERT]   = "alert",
92
        [LOG_CRIT]    = "crit",
93
        [LOG_ERR]     = "err",
94
        [LOG_WARNING] = "warning",
95
        [LOG_NOTICE]  = "notice",
96
        [LOG_INFO]    = "info",
97
        [LOG_DEBUG]   = "debug",
98
};
99

100
DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(log_level, int, LOG_DEBUG);
50,989✔
101

102
bool log_level_is_valid(int level) {
692,743✔
103
        return level >= 0 && level <= LOG_DEBUG;
692,743✔
104
}
105

106
/* The maximum size for a log namespace length. This is the file name size limit 255 minus the size of a
107
 * formatted machine ID minus a separator char */
108
#define LOG_NAMESPACE_MAX (NAME_MAX - (SD_ID128_STRING_MAX - 1) - 1)
109

110
bool log_namespace_name_valid(const char *s) {
712✔
111
        /* Let's make sure the namespace fits in a filename that is prefixed with the machine ID and a dot
112
         * (so that /var/log/journal/<machine-id>.<namespace> can be created based on it). Also make sure it
113
         * is suitable as unit instance name, and does not contain fishy characters. */
114

115
        if (!filename_is_valid(s))
712✔
116
                return false;
117

118
        if (strlen(s) > LOG_NAMESPACE_MAX)
712✔
119
                return false;
120

121
        if (!unit_instance_is_valid(s))
712✔
122
                return false;
123

124
        if (!string_is_safe(s))
712✔
125
                return false;
126

127
        /* Let's avoid globbing for now */
128
        if (string_is_glob(s))
712✔
UNCOV
129
                return false;
×
130

131
        return true;
132
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc