about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDavid Hill <dhill@conformal.com>2011-03-30 14:41:14 +0000
committerDavid Hill <dhill@conformal.com>2011-03-30 14:41:14 +0000
commit1c55675135b389363c0fecf43f20c512ffbed1a7 (patch)
treee8776f3b7aaab43fc5e9c60d20e08e8e0b3d3a34
parentb323713408cc867cd7568a6a7260743c04f09838 (diff)
downloadxombrero-1c55675135b389363c0fecf43f20c512ffbed1a7.tar.gz
remove race by using fstat instead
-rw-r--r--xxxterm.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/xxxterm.c b/xxxterm.c
index 0918f56..cb4445f 100644
--- a/xxxterm.c
+++ b/xxxterm.c
@@ -2756,17 +2756,16 @@ ca_cmd(struct tab *t, struct karg *args)
 	gnutls_x509_crt_t	*c = NULL;
 	char			*certs_buf = NULL, *s;
 
-	/* yeah yeah stat race */
-	if (stat(ssl_ca_file, &sb)) {
-		show_oops(t, "no CA file: %s", ssl_ca_file);
-		goto done;
-	}
-
 	if ((f = fopen(ssl_ca_file, "r")) == NULL) {
 		show_oops(t, "Can't open CA file: %s", strerror(errno));
 		return (1);
 	}
 
+	if (fstat(fileno(f), &sb) == -1) {
+		show_oops(t, "Can't stat CA file: %s", strerror(errno));
+		goto done;
+	}
+	
 	certs_buf = g_malloc(sb.st_size + 1);
 	if (fread(certs_buf, 1, sb.st_size, f) != sb.st_size) {
 		show_oops(t, "Can't read CA file: %s", strerror(errno));