summaryrefslogtreecommitdiff
path: root/lib/libutil
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2006-10-14 18:53:11 +0000
committerchristos <christos@NetBSD.org>2006-10-14 18:53:11 +0000
commite7acb44bcfcc021d2cb7753c84bbd0ff7c390a49 (patch)
tree3533e62f4c038a497eeaa8ffeadbf26d0c9a11ca /lib/libutil
parentc04db80c0b2435c06ac1bbe1d6d9eb17de4aeaea (diff)
Allow escaping of the separators using a double backslash
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/login_cap.c42
1 files changed, 20 insertions, 22 deletions
diff --git a/lib/libutil/login_cap.c b/lib/libutil/login_cap.c
index aeb8cf68b23..cc988879713 100644
--- a/lib/libutil/login_cap.c
+++ b/lib/libutil/login_cap.c
@@ -1,4 +1,4 @@
-/* $NetBSD: login_cap.c,v 1.23 2005/12/20 21:32:20 christos Exp $ */
+/* $NetBSD: login_cap.c,v 1.24 2006/10/14 18:53:11 christos Exp $ */
/*-
* Copyright (c) 1995,1997 Berkeley Software Design, Inc. All rights reserved.
@@ -36,7 +36,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: login_cap.c,v 1.23 2005/12/20 21:32:20 christos Exp $");
+__RCSID("$NetBSD: login_cap.c,v 1.24 2006/10/14 18:53:11 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -490,7 +490,7 @@ int
setuserenv(login_cap_t *lc, envfunc_t senv, void *envp)
{
const char *stop = ", \t";
- int i, count;
+ size_t i, count;
char *ptr;
char **res;
char *str = login_getcapstr(lc, "setenv", NULL, NULL);
@@ -498,7 +498,10 @@ setuserenv(login_cap_t *lc, envfunc_t senv, void *envp)
if (str == NULL || *str == '\0')
return 0;
- /* count the sub-strings */
+ /*
+ * count the sub-strings, this may over-count since we don't
+ * account for escaped delimiters.
+ */
for (i = 1, ptr = str; *ptr; i++) {
ptr += strcspn(ptr, stop);
if (*ptr)
@@ -512,27 +515,22 @@ setuserenv(login_cap_t *lc, envfunc_t senv, void *envp)
if (!res)
return -1;
- ptr = (char *)(void *)res + count * sizeof(char *);
- strcpy(ptr, str);
+ ptr = (char *)(void *)&res[count];
+ (void)strcpy(ptr, str);
/* split string */
- for (i = 0; *ptr && i < count; i++) {
- res[i] = ptr;
- ptr += strcspn(ptr, stop);
- if (*ptr)
- *ptr++ = '\0';
- }
+ for (i = 0; (res[i] = stresep(&ptr, stop, '\\')) != NULL; )
+ if (*res[i])
+ i++;
- res[i] = NULL;
-
- for (i = 0; i < count && res[i]; i++) {
- if (*res[i] != '\0') {
- if ((ptr = strchr(res[i], '=')) != NULL)
- *ptr++ = '\0';
- else
- ptr = NULL;
- (void)(*senv)(envp, res[i], ptr ? ptr : "", 1);
- }
+ count = i;
+
+ for (i = 0; i < count; i++) {
+ if ((ptr = strchr(res[i], '=')) != NULL)
+ *ptr++ = '\0';
+ else
+ ptr = NULL;
+ (void)(*senv)(envp, res[i], ptr ? ptr : "", 1);
}
free(res);