diff options
author | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2009-01-22 21:25:46 +0000 |
---|---|---|
committer | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2009-01-22 21:25:46 +0000 |
commit | 5bb40c4b513e7d98e9609e96290151bbe267d56b (patch) | |
tree | a9820b18d1b1e987c7d1e11c55cb895fc704788b /main/abstract_jb.c | |
parent | a7a8d397732aceafd90ce355f2098a6987b7b8c7 (diff) |
Create logfile safely.
(closes issue #14160)
Reported by: tzafrir
Patches:
20090104__bug14160.diff.txt uploaded by Corydon76 (license 14)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@170307 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/abstract_jb.c')
-rw-r--r-- | main/abstract_jb.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/main/abstract_jb.c b/main/abstract_jb.c index d5a4c7ffd..440d38186 100644 --- a/main/abstract_jb.c +++ b/main/abstract_jb.c @@ -484,6 +484,8 @@ static int create_jb(struct ast_channel *chan, struct ast_frame *frr) /* Create a frame log file */ if (ast_test_flag(jbconf, AST_JB_LOG)) { + char safe_logfile[30] = "/tmp/logfile-XXXXXX"; + int safe_fd; snprintf(name2, sizeof(name2), "%s", chan->name); tmp = strchr(name2, '/'); if (tmp) @@ -497,14 +499,17 @@ static int create_jb(struct ast_channel *chan, struct ast_frame *frr) tmp = strchr(name1, '/'); if (tmp) *tmp = '#'; - + snprintf(logfile_pathname, sizeof(logfile_pathname), "/tmp/ast_%s_jb_%s--%s.log", jbimpl->name, name1, name2); - jb->logfile = fopen(logfile_pathname, "w+b"); - - if (!jb->logfile) - ast_log(LOG_ERROR, "Failed to create frame log file with pathname '%s'\n", logfile_pathname); - + if (!(safe_fd = mkstemp(safe_logfile)) > -1 || unlink(logfile_pathname) || link(safe_logfile, logfile_pathname) || unlink(safe_logfile) || !(jb->logfile = fdopen(safe_fd, "w+b"))) { + jb->logfile = NULL; + if (safe_fd > -1) { + close(safe_fd); + } + ast_log(LOG_ERROR, "Failed to create frame log file with pathname '%s': %s\n", logfile_pathname, strerror(errno)); + } + if (res == JB_IMPL_OK) jb_framelog("JB_PUT_FIRST {now=%ld}: Queued frame with ts=%ld and len=%ld\n", now, frr->ts, frr->len); |