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

proftpd / proftpd / 26127302613

19 May 2026 09:51PM UTC coverage: 93.024% (+0.4%) from 92.635%
26127302613

push

github

51329 of 55178 relevant lines covered (93.02%)

215.14 hits per line

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

93.55
/src/env.c
1
/*
2
 * ProFTPD - FTP server daemon
3
 * Copyright (c) 2007-2026 The ProFTPD Project team
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, see <https://www.gnu.org/licenses/>.
17
 *
18
 * As a special exemption, The ProFTPD Project team and other respective
19
 * copyright holders give permission to link this program with OpenSSL, and
20
 * distribute the resulting executable, without including the source code for
21
 * OpenSSL in the source distribution.
22
 */
23

24
/* Environment management */
25

26
#include "conf.h"
27

28
char *pr_env_get(pool *p, const char *key) {
29
  if (p == NULL ||
43✔
30
      key == NULL) {
43✔
31
    errno = EINVAL;
43✔
32
    return NULL;
5✔
33
  }
5✔
34

35
#if defined(HAVE_GETENV)
36
  return getenv(key);
37
#else
38✔
38
  errno = ENOSYS;
39
  return NULL;
40
#endif /* !HAVE_GETENV */
41
}
42

43
int pr_env_set(pool *p, const char *key, const char *value) {
44
  size_t valuelen;
19✔
45

19✔
46
#if defined(HAVE_SETENV)
47
  const char *k, *v;
48
#elif defined(HAVE_PUTENV)
19✔
49
  const char *str;
50
#endif /* !HAVE_SETENV and !HAVE_PUTENV */
51

52
  if (p == NULL ||
53
      key == NULL ||
19✔
54
      value == NULL) {
19✔
55
    errno = EINVAL;
56
    return -1;
9✔
57
  }
9✔
58

59
  valuelen = strlen(value);
60
  if (valuelen > PR_TUNABLE_ENV_MAX) {
10✔
61
    errno = EPERM;
10✔
62
    return -1;
×
63
  }
×
64

65
  /* In the PR_USE_DEVEL cases below, we use strdup(2) rather than ProFTPD's
66
   * pstrdup() in order to soothe memory trackers (e.g. Valgrind) who may
67
   * complain.
68
   */
69

70
#if defined(HAVE_SETENV)
71
  k = key;
72
  v = value;
10✔
73
  return setenv(k, v, 1);
10✔
74

10✔
75
#elif defined(HAVE_PUTENV)
76
  str = pstrcat(p, key, "=", value, NULL);
77

78
# ifdef PR_USE_DEVEL
79
  str = strdup(str);
80
  if (str == NULL) {
81
    pr_log_pri(PR_LOG_ALERT, "Out of memory!");
82
    exit(1);
83
  }
84
# endif /* PR_USE_DEVEL */
85
  return putenv((char *) str);
86

87
#else
88
  errno = ENOSYS;
89
  return -1;
90
#endif /* !HAVE_SETENV and !HAVE_PUTENV */
91
}
92

93
int pr_env_unset(pool *p, const char *key) {
94
#if defined(HAVE_UNSETENV)
7✔
95
  char *res;
96
#endif /* !HAVE_UNSETENV */
7✔
97

98
  if (p == NULL ||
99
      key == NULL) {
7✔
100
    errno = EINVAL;
7✔
101
    return -1;
3✔
102
  }
3✔
103

104
#if defined(HAVE_UNSETENV)
105
  /* The same key may appear multiple times in the environ, so make certain
106
   * that all such occurrences are removed.
107
   */
108
  res = pr_env_get(p, key);
109
  while (res) {
4✔
110
    pr_signals_handle();
7✔
111

3✔
112
    unsetenv(key);
113
    res = pr_env_get(p, key);
3✔
114
  }
3✔
115

116
  return 0;
117
#else
118
  errno = ENOSYS;
119
  return -1;
120
#endif /* !HAVE_UNSETENV */
121
}
122

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