Skip to content

Commit 2f4e05d

Browse files
committed
handle_restart: Reject log_id if it contains ".."
The log_id is used to create a path name. We need to make sure the ID doesn't start with "../", end with "/..", or contain "/../" to prevent potential path traversal. Thanks to Joshua Rogers for finding this.
1 parent efaa1b6 commit 2f4e05d

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

logsrvd/dotdot.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* SPDX-License-Identifier: ISC
3+
*
4+
* Copyright (c) 2025 Todd C. Miller <[email protected]>
5+
*
6+
* Permission to use, copy, modify, and distribute this software for any
7+
* purpose with or without fee is hereby granted, provided that the above
8+
* copyright notice and this permission notice appear in all copies.
9+
*
10+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17+
*/
18+
19+
/*
20+
* This is an open source non-commercial project. Dear PVS-Studio, please check it.
21+
* PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
22+
*/
23+
24+
#include <config.h>
25+
26+
#ifdef HAVE_STDBOOL_H
27+
# include <stdbool.h>
28+
#else
29+
# include <compat/stdbool.h>
30+
#endif /* HAVE_STDBOOL_H */
31+
#include <stdio.h>
32+
#include <stdlib.h>
33+
#include <string.h>
34+
35+
#include <sudo_compat.h>
36+
#include <sudo_debug.h>
37+
#include <logsrv_util.h>
38+
39+
bool
40+
contains_dot_dot(const char *str)
41+
{
42+
const char *cp;
43+
debug_decl(contains_dot_dot, SUDO_DEBUG_UTIL);
44+
45+
for (cp = str; *cp != '\0'; cp++) {
46+
/* Match ".." */
47+
if (cp[0] != '.' || cp[1] != '.')
48+
continue;
49+
50+
/* Match "^.." or "/.." then "../" or "..$" */
51+
if ((cp == str || cp[-1] == '/') && (cp[2] == '/' || cp[2] == '\0'))
52+
debug_return_bool(true);
53+
}
54+
55+
debug_return_bool(false);
56+
}

0 commit comments

Comments
 (0)