summaryrefslogtreecommitdiffstats
path: root/usr.bin/chpass
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2003-04-09 18:18:42 +0000
committerdes <des@FreeBSD.org>2003-04-09 18:18:42 +0000
commitf8704b9d92f255282ae477eefb7c0691410f5aa9 (patch)
tree29d944e4a475bac6ad14b2713a39b4008e166e61 /usr.bin/chpass
parent3ea200b250b81b61bd52f8274a5912e5ce208ad3 (diff)
downloadFreeBSD-src-f8704b9d92f255282ae477eefb7c0691410f5aa9.zip
FreeBSD-src-f8704b9d92f255282ae477eefb7c0691410f5aa9.tar.gz
Avoid clobbering the gecos field, as we intend to use the original later.
PR: bin/50563
Diffstat (limited to 'usr.bin/chpass')
-rw-r--r--usr.bin/chpass/edit.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/usr.bin/chpass/edit.c b/usr.bin/chpass/edit.c
index 59646f0..ce82f8e 100644
--- a/usr.bin/chpass/edit.c
+++ b/usr.bin/chpass/edit.c
@@ -109,7 +109,7 @@ static int
display(const char *tfn, struct passwd *pw)
{
FILE *fp;
- char *bp, *p;
+ char *bp, *gecos, *p;
if ((fp = fopen(tfn, "w")) == NULL) {
warn("%s", tfn);
@@ -151,8 +151,13 @@ display(const char *tfn, struct passwd *pw)
(void)fprintf(fp, "Shell: %s\n",
*pw->pw_shell ? pw->pw_shell : _PATH_BSHELL);
else
- list[E_SHELL].restricted = 1;
- bp = pw->pw_gecos;
+ list[E_SHELL].restricted = 1;
+
+ if ((bp = gecos = strdup(pw->pw_gecos)) == NULL) {
+ warn(NULL);
+ fclose(fp);
+ return (-1);
+ }
p = strsep(&bp, ",");
p = strdup(p ? p : "");
@@ -183,6 +188,8 @@ display(const char *tfn, struct passwd *pw)
if (!list[E_OTHER].restricted || master_mode)
(void)fprintf(fp, "Other information: %s\n", bp);
+ free(gecos);
+
(void)fchown(fileno(fp), getuid(), getgid());
(void)fclose(fp);
return (0);
OpenPOWER on IntegriCloud