--- ed.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ed.c b/ed.c index 1ecd0d9..62f8477 100644 --- a/ed.c +++ b/ed.c _AT_@ -329,15 +329,17 @@ static void setscratch() { int k; + char *dir; clearbuf(); clearundo(); - strcpy(tmpname, "ed.XXXXXX"); + if ((dir = getenv("TMPDIR")) == NULL) + dir = "/tmp/"; + if (strlen(dir) + sizeof("ed.XXXXXX") > FILENAME_MAX) + error("incorrect scratch file name"); + strcat(strcpy(tmpname, dir), "ed.XXXXX"); if ((scratch = mkstemp(tmpname)) < 0) { - /* try /tmp if cwd is not writable */ - strcpy(tmpname, "/tmp/ed.XXXXXX"); - if ((scratch = mkstemp(tmpname)) < 0) - error("failed to create scratch file"); + error("failed to create scratch file"); } if ((k = makeline("", NULL))) error("input/output error in scratch file"); -- 2.1.4Received on Fri Jan 01 2016 - 18:25:58 CET
This archive was generated by hypermail 2.3.0 : Fri Jan 01 2016 - 18:36:12 CET