Print this page
5612 lpadmin dumps core in getlist
*** 17,31 ****
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
- #ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.13 */
/* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
#include "string.h"
#include "errno.h"
#include "stdlib.h"
--- 17,35 ----
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
+
+ /*
+ * Copyright 2015 Gary Mills
+ */
+
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
#include "string.h"
#include "errno.h"
#include "stdlib.h"
*** 70,79 ****
--- 74,86 ----
len;
char buf[10];
+ char *copy,
+ *begin;
+
if (!str || !*str)
return (0);
/*
* Construct in "sep" the full list of characters that
*** 90,117 ****
sep = buf;
strcpy (sep, hardsep);
strcat (sep, ws);
/*
* Skip leading white-space.
*/
! str += strspn(str, ws);
! if (!*str)
return (0);
/*
* Strip trailing white-space.
*/
! p = strchr(str, '\0');
! while (--p != str && strchr(ws, *p))
;
*++p = 0;
/*
* Pass 1: Count the number of items in the list.
*/
! for (n = 0, p = str; *p; ) {
if ((c = *p++) == '\\')
p++;
else
if (strchr(sep, c)) {
n++;
--- 97,135 ----
sep = buf;
strcpy (sep, hardsep);
strcat (sep, ws);
/*
+ * Copy the input string because getlist() sometimes writes to it.
+ */
+ if (!(begin = Strdup(str))) {
+ errno = ENOMEM;
+ return (0);
+ }
+ copy = begin;
+
+ /*
* Skip leading white-space.
*/
! copy += strspn(copy, ws);
! if (!*copy) {
! Free (begin);
return (0);
+ }
/*
* Strip trailing white-space.
*/
! p = strchr(copy, '\0');
! while (--p != copy && strchr(ws, *p))
;
*++p = 0;
/*
* Pass 1: Count the number of items in the list.
*/
! for (n = 0, p = copy; *p; ) {
if ((c = *p++) == '\\')
p++;
else
if (strchr(sep, c)) {
n++;
*** 140,157 ****
}
/*
* This loop will copy all but the last item.
*/
! for (n = 0, p = str; *p; )
if ((c = *p++) == '\\')
p++;
else
if (strchr(sep, c)) {
p[-1] = 0;
! list[n++] = unq_strdup(str, sep);
p[-1] = c;
p += strspn(p, ws);
if (
!strchr(hardsep, c)
--- 158,175 ----
}
/*
* This loop will copy all but the last item.
*/
! for (n = 0, p = copy; *p; )
if ((c = *p++) == '\\')
p++;
else
if (strchr(sep, c)) {
p[-1] = 0;
! list[n++] = unq_strdup(copy, sep);
p[-1] = c;
p += strspn(p, ws);
if (
!strchr(hardsep, c)
*** 158,177 ****
&& strchr(hardsep, *p)
) {
p++;
p += strspn(p, ws);
}
! str = p;
}
! list[n++] = unq_strdup(str, sep);
list[n] = 0;
Done: if (sep != buf)
Free (sep);
return (list);
}
/**
** unq_strdup()
--- 176,196 ----
&& strchr(hardsep, *p)
) {
p++;
p += strspn(p, ws);
}
! copy = p;
}
! list[n++] = unq_strdup(copy, sep);
list[n] = 0;
Done: if (sep != buf)
Free (sep);
+ Free (begin);
return (list);
}
/**
** unq_strdup()