From 3f869a689403c385ca761be5535a5de2db054db4 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sun, 1 Mar 2015 11:17:21 +0100 Subject: [PATCH] factotum: cleanup getnvramkey() - remove secstore password code, it is not used anymore. - zero the Nvrsafe structure on the stack before returning. - use smprint(), can't overflow. --- sys/src/cmd/auth/factotum/dat.h | 2 +- sys/src/cmd/auth/factotum/fs.c | 2 +- sys/src/cmd/auth/factotum/util.c | 18 ++++-------------- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/sys/src/cmd/auth/factotum/dat.h b/sys/src/cmd/auth/factotum/dat.h index 10cdc9a34..5cc0c1b8b 100644 --- a/sys/src/cmd/auth/factotum/dat.h +++ b/sys/src/cmd/auth/factotum/dat.h @@ -201,7 +201,7 @@ Keyinfo* mkkeyinfo(Keyinfo*, Fsstate*, Attr*); int findkey(Key**, Keyinfo*, char*, ...); int findp9authkey(Key**, Fsstate*); Proto *findproto(char*); -char *getnvramkey(int, char**); +char *getnvramkey(int); void initcap(void); int isclient(char*); int matchattr(Attr*, Attr*, Attr*); diff --git a/sys/src/cmd/auth/factotum/fs.c b/sys/src/cmd/auth/factotum/fs.c index b9a51d383..7d195ac01 100644 --- a/sys/src/cmd/auth/factotum/fs.c +++ b/sys/src/cmd/auth/factotum/fs.c @@ -148,7 +148,7 @@ main(int argc, char **argv) } if(sflag){ - s = getnvramkey(kflag ? NVwrite : NVwriteonerr, nil); + s = getnvramkey(kflag ? NVwrite : NVwriteonerr); if(s == nil) fprint(2, "factotum warning: cannot read nvram: %r\n"); else if(ctlwrite(s, 0) < 0) diff --git a/sys/src/cmd/auth/factotum/util.c b/sys/src/cmd/auth/factotum/util.c index a8eab1db7..411935bc1 100644 --- a/sys/src/cmd/auth/factotum/util.c +++ b/sys/src/cmd/auth/factotum/util.c @@ -472,11 +472,10 @@ findproto(char *name) } char* -getnvramkey(int flag, char **secstorepw) +getnvramkey(int flag) { - char *s; Nvrsafe safe; - char spw[CONFIGLEN+1]; + char *s; int i; memset(&safe, 0, sizeof safe); @@ -487,15 +486,6 @@ getnvramkey(int flag, char **secstorepw) if(readnvram(&safe, flag)<0 && safe.authid[0]==0) return nil; - /* - * we're using the config area to hold the secstore - * password. if there's anything there, return it. - */ - memmove(spw, safe.config, CONFIGLEN); - spw[CONFIGLEN] = 0; - if(spw[0] != 0 && secstorepw != nil) - *secstorepw = estrdup(spw); - /* * only use nvram key if it is non-zero */ @@ -505,11 +495,11 @@ getnvramkey(int flag, char **secstorepw) if(i == DESKEYLEN) return nil; - s = emalloc(512); fmtinstall('H', encodefmt); - sprint(s, "key proto=p9sk1 user=%q dom=%q !hex=%.*H !password=______", + s = smprint("key proto=p9sk1 user=%q dom=%q !hex=%.*H !password=______", safe.authid, safe.authdom, DESKEYLEN, safe.machkey); writehostowner(safe.authid); + memset(&safe, 0, sizeof safe); return s; }