]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/libsystemd-bus/bus-internal.c
bus: properly validate object path values
[thirdparty/systemd.git] / src / libsystemd-bus / bus-internal.c
CommitLineData
de1c301e
LP
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3/***
4 This file is part of systemd.
5
6 Copyright 2013 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
22#include "bus-internal.h"
ac89bf1d
LP
23
24bool object_path_is_valid(const char *p) {
25 const char *q;
26 bool slash;
27
28 if (!p)
29 return false;
30
31 if (p[0] != '/')
32 return false;
33
34 if (p[1] == 0)
35 return true;
36
37 for (slash = true, q = p+1; *q; q++)
38 if (*q == '/') {
39 if (slash)
40 return false;
41
42 slash = true;
43 } else {
44 bool good;
45
46 good =
47 (*q >= 'a' && *q <= 'z') ||
48 (*q >= 'A' && *q <= 'Z') ||
49 (*q >= '0' && *q <= '9') ||
50 *q == '_';
51
52 if (!good)
53 return false;
54
55 slash = false;
56 }
57
58 if (slash)
59 return false;
60
61 return true;
62}