Allow escaping of the separators using a double backslash

This commit is contained in:
christos 2006-10-14 18:53:11 +00:00
parent c04db80c0b
commit e7acb44bcf

View File

@ -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;
count = i;
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);
}
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);