mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-16 06:48:25 +00:00
Create logfile safely.
(closes issue #14160) Reported by: tzafrir Patches: 20090104__bug14160.diff.txt uploaded by Corydon76 (license 14) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@170307 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -484,6 +484,8 @@ static int create_jb(struct ast_channel *chan, struct ast_frame *frr)
|
|||||||
|
|
||||||
/* Create a frame log file */
|
/* Create a frame log file */
|
||||||
if (ast_test_flag(jbconf, AST_JB_LOG)) {
|
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);
|
snprintf(name2, sizeof(name2), "%s", chan->name);
|
||||||
tmp = strchr(name2, '/');
|
tmp = strchr(name2, '/');
|
||||||
if (tmp)
|
if (tmp)
|
||||||
@@ -500,10 +502,13 @@ static int create_jb(struct ast_channel *chan, struct ast_frame *frr)
|
|||||||
|
|
||||||
snprintf(logfile_pathname, sizeof(logfile_pathname),
|
snprintf(logfile_pathname, sizeof(logfile_pathname),
|
||||||
"/tmp/ast_%s_jb_%s--%s.log", jbimpl->name, name1, name2);
|
"/tmp/ast_%s_jb_%s--%s.log", jbimpl->name, name1, name2);
|
||||||
jb->logfile = fopen(logfile_pathname, "w+b");
|
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 (!jb->logfile)
|
if (safe_fd > -1) {
|
||||||
ast_log(LOG_ERROR, "Failed to create frame log file with pathname '%s'\n", logfile_pathname);
|
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)
|
if (res == JB_IMPL_OK)
|
||||||
jb_framelog("JB_PUT_FIRST {now=%ld}: Queued frame with ts=%ld and len=%ld\n",
|
jb_framelog("JB_PUT_FIRST {now=%ld}: Queued frame with ts=%ld and len=%ld\n",
|
||||||
|
|||||||
Reference in New Issue
Block a user