From 6ae92b87678b5c2e19b673da3d6e2a1ffa7649c0 Mon Sep 17 00:00:00 2001 From: Lukas Berk Date: Thu, 21 Jul 2011 14:50:54 -0400 Subject: [PATCH] Reorder open/access sequence * ctl.c: reorder access()/open() The previous order was not actually subject to a race condition, because the file being accessed cannot be modified by a non-root user. --- runtime/staprun/ctl.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/runtime/staprun/ctl.c b/runtime/staprun/ctl.c index f65c99558..1ffc8e33b 100644 --- a/runtime/staprun/ctl.c +++ b/runtime/staprun/ctl.c @@ -27,11 +27,18 @@ int init_ctl_channel(const char *name, int verb) return -2; } - if (access(buf, R_OK|W_OK) != 0) - return -5; - control_channel = open(buf, O_RDWR); dbug(2, "Opened %s (%d)\n", buf, control_channel); + +/* It's actually safe to do this check before the open(), + * as the file we're trying to access connot be modified + * by a typical user. + */ + if (access(buf, R_OK|W_OK) != 0){ + close(control_channel); + return -5; + } + if (control_channel < 0) { if (verb) { if (attach_mod && errno == ENOENT) -- 2.43.5