diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2005-11-12 16:40:59 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2005-11-12 16:40:59 +0000 |
commit | 837c0ec1b08d23651a0ff96b717edca574e5d82f (patch) | |
tree | 99eaf6eb13e2df665c3f50b8c2c437dfec05a163 /sbin | |
parent | e87ea93520fa0802b26b3d90fe0e4beb9a3766fa (diff) |
do not stat() before open(); instead -- use fstat(); ok hshoexer
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/ipsecctl/parse.y | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/sbin/ipsecctl/parse.y b/sbin/ipsecctl/parse.y index 7d29595909d..9c420ddfae1 100644 --- a/sbin/ipsecctl/parse.y +++ b/sbin/ipsecctl/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.34 2005/11/12 12:00:53 hshoexer Exp $ */ +/* $OpenBSD: parse.y,v 1.35 2005/11/12 16:40:58 deraadt Exp $ */ /* * Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -1003,16 +1003,15 @@ parsekeyfile(char *filename) int fd; unsigned char *hex; - if (stat(filename, &sb) < 0) + if ((fd = open(filename, O_RDONLY)) < 0) + err(1, "parsekeyfile: open"); + if (fstat(fd, &sb) < 0) err(1, "parsekeyfile: stat %s", filename); if ((sb.st_size > KEYSIZE_LIMIT) || (sb.st_size == 0)) errx(1, "parsekeyfile: key too %s", sb.st_size ? "large" : "small"); - if ((hex = calloc(sb.st_size, sizeof(unsigned char))) - == NULL) + if ((hex = calloc(sb.st_size, sizeof(unsigned char))) == NULL) err(1, "parsekeyfile: calloc"); - if ((fd = open(filename, O_RDONLY)) < 0) - err(1, "parsekeyfile: open"); if (read(fd, hex, sb.st_size) < sb.st_size) err(1, "parsekeyfile: read"); close(fd); |