diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-07-22 10:27:56 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-07-22 10:27:56 +0100 |
commit | 004535e4002b336a5c9c54b2cddfd17a86489a49 (patch) | |
tree | 738e3028c5bf2db9ba7fa52eccf9845fd8f13712 /contrib | |
parent | a2e2cb74d07ee1e2cdd6649a8ec636db51108677 (diff) | |
download | rspamd-004535e4002b336a5c9c54b2cddfd17a86489a49.tar.gz rspamd-004535e4002b336a5c9c54b2cddfd17a86489a49.zip |
[Minor] Avoid obsolete function usage
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/torch/paths/paths.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/contrib/torch/paths/paths.c b/contrib/torch/paths/paths.c index c53e4bff6..7c3a72e54 100644 --- a/contrib/torch/paths/paths.c +++ b/contrib/torch/paths/paths.c @@ -720,7 +720,9 @@ add_tmpname(lua_State *L, const char *tmp) while (pp && *pp) { struct tmpname_s *p = *pp; - if (!strcmp(p->tmp, tmp)) return; + if (!strcmp(p->tmp, tmp)) { + return; + } pp = &(p->next); } if (pp) @@ -741,10 +743,27 @@ add_tmpname(lua_State *L, const char *tmp) static int lua_tmpname(lua_State *L) { + char *tmp; + int fd = -1; #ifdef _WIN32 - char *tmp = _tempnam("c:/temp", "luatmp"); + tmp = _tempnam("c:/temp", "luatmp"); #else - char *tmp = tempnam(NULL, "luatmp"); + char *tempdir = getenv("TMPDIR"); + if (tempdir == NULL) { + tempdir = "/tmp"; + } + tmp = calloc(1, PATH_MAX); + snprintf(tmp, PATH_MAX, "%s/%sXXXXXXXX", tempdir, "luatmp"); + fd = mkstemp(tmp); + + if (fd == -1) { + free(tmp); + tmp = NULL; + } + else { + /* Stupid and unsafe thing but that's how this library wants to do it */ + close(fd); + } #endif if (tmp) { |