ref: b14d7ac38c9341e233eee10b74a6c0e716a7915f
parent: 82ece1bb0ca214c1e594ea2443b37ff9db63f2ae
author: cinap_lenrek <[email protected]>
date: Fri Aug 3 18:50:21 EDT 2012
cron: snprint, error handling (update from sources)
--- a/sys/src/cmd/auth/cron.c
+++ b/sys/src/cmd/auth/cron.c
@@ -174,7 +174,7 @@
switch(fork()){
case -1:
- fatal("can't fork");
+ fatal("can't fork: %r");
case 0:
break;
default:
@@ -248,18 +248,18 @@
int fd;
user = getuser();
- sprint(file, "/cron/%s", user);
+ snprint(file, sizeof file, "/cron/%s", user);
fd = create(file, OREAD, 0755|DMDIR);
if(fd < 0)
- sysfatal("couldn't create %s: %r", file);
+ fatal("couldn't create %s: %r", file);
nulldir(&d);
d.gid = user;
dirfwstat(fd, &d);
close(fd);
- sprint(file, "/cron/%s/cron", user);
+ snprint(file, sizeof file, "/cron/%s/cron", user);
fd = create(file, OREAD, 0644);
if(fd < 0)
- sysfatal("couldn't create %s: %r", file);
+ fatal("couldn't create %s: %r", file);
nulldir(&d);
d.gid = user;
dirfwstat(fd, &d);
@@ -276,7 +276,7 @@
fd = open("/cron", OREAD);
if(fd < 0)
- fatal("can't open /cron\n");
+ fatal("can't open /cron: %r");
while((n = dirread(fd, &d)) > 0){
for(i = 0; i < n; i++){
if(strcmp(d[i].name, "log") == 0 ||
@@ -288,7 +288,7 @@
continue;
}
u = newuser(d[i].name);
- sprint(file, "/cron/%s/cron", d[i].name);
+ snprint(file, sizeof file, "/cron/%s/cron", d[i].name);
du = dirstat(file);
if(du == nil || qidcmp(u->lastqid, du->qid) != 0){
freejobs(u->jobs);
@@ -686,7 +686,7 @@
uchar rand[20];
char *cap;
char *key;
- int nfrom, nto;
+ int nfrom, nto, ncap;
uchar hash[SHA1dlen];
if(caphashfd < 0)
@@ -695,8 +695,9 @@
/* create the capability */
nto = strlen(to);
nfrom = strlen(from);
- cap = emalloc(nfrom+1+nto+1+sizeof(rand)*3+1);
- sprint(cap, "%s@%s", from, to);
+ ncap = nfrom + 1 + nto + 1 + sizeof(rand)*3 + 1;
+ cap = emalloc(ncap);
+ snprint(cap, ncap, "%s@%s", from, to);
memrandom(rand, sizeof(rand));
key = cap+nfrom+1+nto+1;
enc64(key, sizeof(rand)*3, rand, sizeof(rand));