Coverage Report

Created: 2026-04-12 06:19

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/sudo/plugins/sudoers/strlcpy_unesc.c
Line
Count
Source
1
/*
2
 * SPDX-License-Identifier: ISC
3
 *
4
 * Copyright (c) 2021 Todd C. Miller <Todd.Miller@sudo.ws>
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
#include <config.h>
20
21
#include <sys/types.h>
22
#include <stdio.h>
23
#include <ctype.h>
24
25
#include <sudoers.h>
26
27
/*
28
 * Like strlcpy() but collapses non-space chars escaped with a backslash.
29
 */
30
size_t
31
strlcpy_unescape(char *restrict dst, const char *restrict src, size_t size)
32
4.05M
{
33
4.05M
    size_t len = 0;
34
4.05M
    char ch;
35
4.05M
    debug_decl(strlcpy_unescape, SUDOERS_DEBUG_UTIL);
36
37
26.7M
    while ((ch = *src++) != '\0') {
38
22.7M
  if (ch == '\\' && *src != '\0' && !isspace((unsigned char)*src))
39
9.70k
      ch = *src++;
40
22.7M
  if (size > 1) {
41
22.7M
      *dst++ = ch;
42
22.7M
      size--;
43
22.7M
  }
44
22.7M
  len++;
45
22.7M
    }
46
4.05M
    if (size > 0)
47
4.05M
  *dst = '\0';
48
49
4.05M
    debug_return_size_t(len);
50
4.05M
}