/*1* SPDX-License-Identifier: ISC2*3* Copyright (c) 2025 Todd C. Miller <[email protected]>4*5* Permission to use, copy, modify, and distribute this software for any6* purpose with or without fee is hereby granted, provided that the above7* copyright notice and this permission notice appear in all copies.8*9* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES10* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF11* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR12* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES13* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN14* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF15* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.16*/1718#include <config.h>1920#ifdef HAVE_STDBOOL_H21# include <stdbool.h>22#else23# include <compat/stdbool.h>24#endif /* HAVE_STDBOOL_H */25#include <stdio.h>26#include <stdlib.h>27#include <string.h>2829#include <sudo_compat.h>30#include <sudo_debug.h>31#include <logsrv_util.h>3233bool34contains_dot_dot(const char *str)35{36const char *cp;37debug_decl(contains_dot_dot, SUDO_DEBUG_UTIL);3839for (cp = str; *cp != '\0'; cp++) {40/* Match ".." */41if (cp[0] != '.' || cp[1] != '.')42continue;4344/* Match "^.." or "/.." then "../" or "..$" */45if ((cp == str || cp[-1] == '/') && (cp[2] == '/' || cp[2] == '\0'))46debug_return_bool(true);47}4849debug_return_bool(false);50}515253