From: David Levine Date: Wed, 22 Jan 2014 02:55:57 +0000 (-0600) Subject: Always check that mktemp()/mktemp2() succeeds before trying to X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/4a78cbcd4fa986d9c1e7bd0a5a4bdb619faeb7cb?ds=sidebyside;hp=-c Always check that mktemp()/mktemp2() succeeds before trying to use result. And if it fails, have the error message report the directory where the failed temporary file creation occurred. And, removed all chmod()'s of temporary files created by mktemp()/ mktemp2() because they set the umask to 077 before calling mkstemp(3). --- 4a78cbcd4fa986d9c1e7bd0a5a4bdb619faeb7cb diff --git a/uip/annosbr.c b/uip/annosbr.c index ae9df280..2f40560b 100644 --- a/uip/annosbr.c +++ b/uip/annosbr.c @@ -184,7 +184,10 @@ annosbr (int fd, char *file, char *comp, char *text, int inplace, int datesw, in mode = fstat (fd, &st) != NOTOK ? (int) (st.st_mode & 0777) : m_gmprot (); - strncpy (tmpfil, m_mktemp2(file, "annotate", NULL, &tmp), sizeof(tmpfil)); + if ((cp = m_mktemp2(file, "annotate", NULL, &tmp)) == NULL) { + adios(NULL, "unable to create temporary file in %s", get_temp_dir()); + } + strncpy (tmpfil, cp, sizeof(tmpfil)); chmod (tmpfil, mode); /* diff --git a/uip/attach.c b/uip/attach.c index e19a0eba..9ff7d095 100644 --- a/uip/attach.c +++ b/uip/attach.c @@ -100,12 +100,15 @@ attach(char *attachment_header_field_name, char *draft_file_name, * Make names for the temporary files. */ - (void)strncpy(body_file_name, - m_mktemp2(NULL, invo_name, NULL, NULL), - body_file_name_len); - (void)strncpy(composition_file_name, - m_mktemp2(NULL, invo_name, NULL, NULL), - composition_file_name_len); + if ((p = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) { + adios(NULL, "unable to create temporary file in %s", get_temp_dir()); + } + (void)strncpy(body_file_name, p, body_file_name_len); + if ((p = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) { + unlink(body_file_name); + adios(NULL, "unable to create temporary file in %s", get_temp_dir()); + } + (void)strncpy(composition_file_name, p, composition_file_name_len); if (has_body) body_file = fopen(body_file_name, "w"); diff --git a/uip/burst.c b/uip/burst.c index 9b893cfe..c3f21710 100644 --- a/uip/burst.c +++ b/uip/burst.c @@ -464,8 +464,14 @@ burst (struct msgs **mpp, int msgnum, struct smsg *smsgs, int numburst, i = inplace ? msgnum + numburst : mp->hghmsg; for (j = numburst; j >= (inplace ? 0 : 1); i--, j--) { + char *tempfile; + + if ((tempfile = m_mktemp2(NULL, invo_name, NULL, &out)) == NULL) { + adios(NULL, "unable to create temporary file in %s", + get_temp_dir()); + } + strncpy (f2, tempfile, sizeof(f2)); strncpy (f1, m_name (i), sizeof(f1)); - strncpy (f2, m_mktemp2(NULL, invo_name, NULL, &out), sizeof(f2)); if (verbosw && i != msgnum) printf ("message %d of digest %d becomes message %d\n", j, msgnum, i); diff --git a/uip/distsbr.c b/uip/distsbr.c index d7a27120..d371ec1d 100644 --- a/uip/distsbr.c +++ b/uip/distsbr.c @@ -141,9 +141,8 @@ ready_msg (char *msgnam) cp = m_mktemp2(NULL, "dist", &hdrfd, NULL); if (cp == NULL) { - adios("distsbr", "unable to create temporary file"); + adios(NULL, "unable to create temporary file in %s", get_temp_dir()); } - fchmod(hdrfd, 0600); strncpy(tmpfil, cp, sizeof(tmpfil)); if ((out = dup (hdrfd)) == NOTOK || (ofp = fdopen (out, "w")) == NULL) @@ -170,7 +169,8 @@ ready_msg (char *msgnam) cp = m_mktemp2(NULL, "dist", &txtfd, NULL); if (cp == NULL) { - adios("distsbr", "unable to create temporary file"); + adios(NULL, "unable to create temporary file in %s", + get_temp_dir()); } fchmod(txtfd, 0600); strncpy (tmpfil, cp, sizeof(tmpfil)); diff --git a/uip/forwsbr.c b/uip/forwsbr.c index 48fecb17..90838e24 100644 --- a/uip/forwsbr.c +++ b/uip/forwsbr.c @@ -174,7 +174,9 @@ finished: } cp = m_mktemp2(NULL, invo_name, NULL, &tmp); - if (cp == NULL) adios("forw", "unable to create temporary file"); + if (cp == NULL) { + adios(NULL, "unable to create temporary file in %s", get_temp_dir()); + } strncpy (tmpfil, cp, sizeof(tmpfil)); unlink (tmpfil); if ((in = dup (fileno (tmp))) == NOTOK) diff --git a/uip/mhbuild.c b/uip/mhbuild.c index 624cf4b9..f3dc91c7 100644 --- a/uip/mhbuild.c +++ b/uip/mhbuild.c @@ -315,8 +315,13 @@ main (int argc, char **argv) * Process the composition file from standard input. */ if (compfile[0] == '-' && compfile[1] == '\0') { + if ((cp = m_mktemp2(NULL, invo_name, NULL, &fp)) == NULL) { + adios(NULL, "unable to create temporary file in %s", + get_temp_dir()); + } + /* copy standard input to temporary file */ - strncpy (infile, m_mktemp2(NULL, invo_name, NULL, &fp), sizeof(infile)); + strncpy (infile, cp, sizeof(infile)); while (fgets (buffer, BUFSIZ, stdin)) fputs (buffer, fp); fclose (fp); @@ -367,8 +372,10 @@ main (int argc, char **argv) cts[1] = NULL; /* output MIME message to this temporary file */ - strncpy(outfile, m_mktemp2(compfile, invo_name, NULL, &fp_out), - sizeof(outfile)); + if ((cp = m_mktemp2(compfile, invo_name, NULL, &fp_out)) == NULL) { + adios(NULL, "unable to create temporary file in %s", get_temp_dir()); + } + strncpy(outfile, cp, sizeof(outfile)); unlink_outfile = 1; /* output the message */ diff --git a/uip/mhbuildsbr.c b/uip/mhbuildsbr.c index ea47bf0b..2b78a364 100644 --- a/uip/mhbuildsbr.c +++ b/uip/mhbuildsbr.c @@ -527,8 +527,10 @@ user_content (FILE *in, char *file, char *buf, CT *ctp) FILE *out; char *cp; - cp = m_mktemp2(NULL, invo_name, NULL, &out); - if (cp == NULL) adios("mhbuildsbr", "unable to create temporary file"); + if ((cp = m_mktemp2(NULL, invo_name, NULL, &out)) == NULL) { + adios("mhbuildsbr", "unable to create temporary file in %s", + get_temp_dir()); + } /* use a temp file to collect the plain text lines */ ce->ce_file = add (cp, NULL); @@ -1087,10 +1089,10 @@ compose_content (CT ct) if (!(cp = ci->ci_magic)) adios (NULL, "internal error(5)"); - tfile = m_mktemp2(NULL, invo_name, NULL, NULL); - if (tfile == NULL) { - adios("mhbuildsbr", "unable to create temporary file"); - } + if ((tfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) { + adios("mhbuildsbr", "unable to create temporary file in %s", + get_temp_dir()); + } ce->ce_file = add (tfile, NULL); ce->ce_unlink = 1; diff --git a/uip/mhfixmsg.c b/uip/mhfixmsg.c index ad4bf0df..d81337d6 100644 --- a/uip/mhfixmsg.c +++ b/uip/mhfixmsg.c @@ -290,11 +290,11 @@ main (int argc, char **argv) { using_stdin = 1; if ((cp = m_mktemp2 (NULL, invo_name, &fd, NULL)) == NULL) { - adios (NULL, "unable to create temporary file"); + adios (NULL, "unable to create temporary file in %s", + get_temp_dir()); } else { free (file); file = add (cp, NULL); - chmod (file, 0600); cpydata (STDIN_FILENO, fd, "-", file); } @@ -396,7 +396,12 @@ mhfixmsgsbr (CT *ctp, const fix_transformations *fx, char *outfile) { modify_inplace = 1; if ((*ctp)->c_file) { - outfile = add (m_mktemp2 (NULL, invo_name, NULL, NULL), NULL); + char *tempfile; + if ((tempfile = m_mktemp2 (NULL, invo_name, NULL, NULL)) == NULL) { + adios (NULL, "unable to create temporary file in %s", + get_temp_dir()); + } + outfile = add (tempfile, NULL); } else { adios (NULL, "missing both input and output filenames\n"); } @@ -534,7 +539,8 @@ fix_boundary (CT *ct, int *message_mods) { status = NOTOK; } } else { - advise (NULL, "unable to create temporary file"); + advise (NULL, "unable to create temporary file in %s", + get_temp_dir()); status = NOTOK; } @@ -1019,7 +1025,13 @@ build_text_plain_part (CT encoded_part) { contains the decoded contents. And the decoding function, such as openQuoted, will have set ...->ce_unlink to 1 so that it will be unlinked by free_content (). */ - tmp_plain_file = add (m_mktemp2 (NULL, invo_name, NULL, NULL), NULL); + char *tempfile; + + if ((tempfile = m_mktemp2 (NULL, invo_name, NULL, NULL)) == NULL) { + advise (NULL, "unable to create temporary file in %s", + get_temp_dir()); + } + tmp_plain_file = add (tempfile, NULL); if (reformat_part (tp_part, tmp_plain_file, tp_part->c_ctinfo.ci_type, tp_part->c_ctinfo.ci_subtype, @@ -1090,8 +1102,12 @@ static int decode_part (CT ct) { char *tmp_decoded; int status; + char *tempfile; - tmp_decoded = add (m_mktemp2 (NULL, invo_name, NULL, NULL), NULL); + if ((tempfile = m_mktemp2 (NULL, invo_name, NULL, NULL)) == NULL) { + adios (NULL, "unable to create temporary file in %s", get_temp_dir()); + } + tmp_decoded = add (tempfile, NULL); /* The following call will load ct->c_cefile.ce_file with the tmp filename of the decoded content. tmp_decoded will contain the encoded output, get rid of that. */ @@ -1679,8 +1695,14 @@ strip_crs (CT ct, int *message_mods) { if (has_crs) { int fd; - char *stripped_content_file = - add (m_mktemp2 (NULL, invo_name, &fd, NULL), NULL); + char *stripped_content_file; + char *tempfile = m_mktemp2 (NULL, invo_name, &fd, NULL); + + if (tempfile == NULL) { + adios (NULL, "unable to create temporary file in %s", + get_temp_dir()); + } + stripped_content_file = add (tempfile, NULL); /* Strip each CR before a LF from the content. */ fseeko (*fp, begin, SEEK_SET); @@ -1832,6 +1854,7 @@ convert_codeset (CT ct, char *dest_codeset, int *message_mods) { int opened_input_file = 0; char src_buffer[BUFSIZ]; HF hf; + char *tempfile; if ((conv_desc = iconv_open (dest_codeset, src_codeset)) == (iconv_t) -1) { @@ -1839,7 +1862,11 @@ convert_codeset (CT ct, char *dest_codeset, int *message_mods) { return -1; } - dest = add (m_mktemp2 (NULL, invo_name, &fd, NULL), NULL); + if ((tempfile = m_mktemp2 (NULL, invo_name, &fd, NULL)) == NULL) { + adios (NULL, "unable to create temporary file in %s", + get_temp_dir()); + } + dest = add (tempfile, NULL); if (ct->c_cefile.ce_file) { file = &ct->c_cefile.ce_file; diff --git a/uip/mhparse.c b/uip/mhparse.c index e15296e5..9489a8e4 100644 --- a/uip/mhparse.c +++ b/uip/mhparse.c @@ -194,11 +194,11 @@ parse_mime (char *file) if ((is_stdin = !(strcmp (file, "-")))) { char *tfile = m_mktemp2(NULL, invo_name, NULL, &fp); if (tfile == NULL) { - advise("mhparse", "unable to create temporary file"); + advise("mhparse", "unable to create temporary file in %s", + get_temp_dir()); return NULL; } file = add (tfile, NULL); - chmod (file, 0600); while (fgets (buffer, sizeof(buffer), stdin)) fputs (buffer, fp); @@ -1646,7 +1646,12 @@ openBase64 (CT ct, char **file) } if (*file == NULL) { - ce->ce_file = add (m_mktemp2(NULL, invo_name, NULL, NULL), NULL); + char *tempfile; + if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) { + adios(NULL, "unable to create temporary file in %s", + get_temp_dir()); + } + ce->ce_file = add (tempfile, NULL); ce->ce_unlink = 1; } else { ce->ce_file = add (*file, NULL); @@ -1880,7 +1885,12 @@ openQuoted (CT ct, char **file) } if (*file == NULL) { - ce->ce_file = add (m_mktemp2(NULL, invo_name, NULL, NULL), NULL); + char *tempfile; + if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) { + adios(NULL, "unable to create temporary file in %s", + get_temp_dir()); + } + ce->ce_file = add (tempfile, NULL); ce->ce_unlink = 1; } else { ce->ce_file = add (*file, NULL); @@ -2104,7 +2114,12 @@ open7Bit (CT ct, char **file) } if (*file == NULL) { - ce->ce_file = add (m_mktemp2(NULL, invo_name, NULL, NULL), NULL); + char *tempfile; + if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) { + adios(NULL, "unable to create temporary file in %s", + get_temp_dir()); + } + ce->ce_file = add (tempfile, NULL); ce->ce_unlink = 1; } else { ce->ce_file = add (*file, NULL); @@ -2493,8 +2508,14 @@ openFTP (CT ct, char **file) ce->ce_file = add (*file, NULL); else if (caching) ce->ce_file = add (cachefile, NULL); - else - ce->ce_file = add (m_mktemp2(NULL, invo_name, NULL, NULL), NULL); + else { + char *tempfile; + if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) { + adios(NULL, "unable to create temporary file in %s", + get_temp_dir()); + } + ce->ce_file = add (tempfile, NULL); + } if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) { content_error (ce->ce_file, ct, "unable to fopen for reading/writing"); @@ -2682,7 +2703,12 @@ openMail (CT ct, char **file) } if (*file == NULL) { - ce->ce_file = add (m_mktemp2(NULL, invo_name, NULL, NULL), NULL); + char *tempfile; + if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) { + adios(NULL, "unable to create temporary file in %s", + get_temp_dir()); + } + ce->ce_file = add (tempfile, NULL); ce->ce_unlink = 1; } else { ce->ce_file = add (*file, NULL); @@ -2775,8 +2801,14 @@ openURL (CT ct, char **file) ce->ce_file = add(*file, NULL); else if (caching) ce->ce_file = add(cachefile, NULL); - else - ce->ce_file = add(m_mktemp2(NULL, invo_name, NULL, NULL), NULL); + else { + char *tempfile; + if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) { + adios(NULL, "unable to create temporary file in %s", + get_temp_dir()); + } + ce->ce_file = add (tempfile, NULL); + } if ((ce->ce_fp = fopen(ce->ce_file, "w+")) == NULL) { content_error(ce->ce_file, ct, "unable to fopen for read/writing"); diff --git a/uip/mhstoresbr.c b/uip/mhstoresbr.c index 93d3e902..3b689702 100644 --- a/uip/mhstoresbr.c +++ b/uip/mhstoresbr.c @@ -562,7 +562,10 @@ store_content (CT ct, CT p) char *tmpfilenam, *folder; /* Store content in temporary file for now */ - tmpfilenam = m_mktemp(invo_name, NULL, NULL); + if ((tmpfilenam = m_mktemp(invo_name, NULL, NULL)) == NULL) { + adios(NULL, "unable to create temporary file in %s", + get_temp_dir()); + } ct->c_storage = add (tmpfilenam, NULL); /* Get the folder name */ diff --git a/uip/post.c b/uip/post.c index 9483dbf6..2683622e 100644 --- a/uip/post.c +++ b/uip/post.c @@ -535,12 +535,12 @@ main (int argc, char **argv) if ((out = fopen ("/dev/null", "w")) == NULL) adios ("/dev/null", "unable to open"); } else { - char *cp = m_mktemp2(NULL, invo_name, NULL, &out); - if (cp == NULL) { - adios ("post", "unable to create temporary file"); - } + char *cp = m_mktemp2(NULL, invo_name, NULL, &out); + if (cp == NULL) { + adios(NULL, "unable to create temporary file in %s", + get_temp_dir()); + } strncpy(tmpfil, cp, sizeof(tmpfil)); - chmod (tmpfil, 0600); } } @@ -1279,8 +1279,9 @@ make_bcc_file (int dashstuff) FILE *out; char *tfile = NULL, *program; - tfile = m_mktemp2(NULL, "bccs", NULL, &out); - if (tfile == NULL) adios("bcc", "unable to create temporary file"); + if ((tfile = m_mktemp2(NULL, "bccs", NULL, &out)) == NULL) { + adios(NULL, "unable to create temporary file in %s", get_temp_dir()); + } strncpy (bccfil, tfile, sizeof(bccfil)); fprintf (out, "From: %s\n", fullfrom); diff --git a/uip/prompter.c b/uip/prompter.c index afa81f5f..0aedc8c1 100644 --- a/uip/prompter.c +++ b/uip/prompter.c @@ -154,9 +154,9 @@ main (int argc, char **argv) if ((in = fopen (drft, "r")) == NULL) adios (drft, "unable to open"); - tmpfil = m_mktemp2(NULL, invo_name, NULL, &out); - if (tmpfil == NULL) adios("prompter", "unable to create temporary file"); - chmod (tmpfil, 0600); + if ((tmpfil = m_mktemp2(NULL, invo_name, NULL, &out)) == NULL) { + adios(NULL, "unable to create temporary file in %s", get_temp_dir()); + } /* * Are we changing the kill or erase character? diff --git a/uip/rcvdist.c b/uip/rcvdist.c index 6cc8e277..4f7a83f7 100644 --- a/uip/rcvdist.c +++ b/uip/rcvdist.c @@ -104,15 +104,17 @@ main (int argc, char **argv) umask (~m_gmprot ()); - tfile = m_mktemp2(NULL, invo_name, NULL, &fp); - if (tfile == NULL) adios("rcvdist", "unable to create temporary file"); + if ((tfile = m_mktemp2(NULL, invo_name, NULL, &fp)) == NULL) { + adios(NULL, "unable to create temporary file in %s", get_temp_dir()); + } strncpy (tmpfil, tfile, sizeof(tmpfil)); cpydata (fileno (stdin), fileno (fp), "message", tmpfil); fseek (fp, 0L, SEEK_SET); - tfile = m_mktemp2(NULL, invo_name, NULL, NULL); - if (tfile == NULL) adios("forw", "unable to create temporary file"); + if ((tfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) { + adios(NULL, "unable to create temporary file in %s", get_temp_dir()); + } strncpy (drft, tfile, sizeof(tmpfil)); rcvdistout (fp, form, addrs); diff --git a/uip/rcvstore.c b/uip/rcvstore.c index 2822093e..e6de62b0 100644 --- a/uip/rcvstore.c +++ b/uip/rcvstore.c @@ -164,7 +164,7 @@ main (int argc, char **argv) /* create a temporary file */ tmpfilenam = m_mktemp (invo_name, &fd, NULL); if (tmpfilenam == NULL) { - adios ("rcvstore", "unable to create temporary file"); + adios(NULL, "unable to create temporary file in %s", get_temp_dir()); } chmod (tmpfilenam, m_gmprot()); diff --git a/uip/rcvtty.c b/uip/rcvtty.c index 356234ad..760d22dc 100644 --- a/uip/rcvtty.c +++ b/uip/rcvtty.c @@ -255,8 +255,10 @@ header_fd (void) char *nfs; char *tfile = NULL; - tfile = m_mktemp2(NULL, invo_name, &fd, NULL); - if (tfile == NULL) return NOTOK; + if ((tfile = m_mktemp2(NULL, invo_name, &fd, NULL)) == NULL) { + advise(NULL, "unable to create temporary file in %s", get_temp_dir()); + return NOTOK; + } unlink (tfile); rewind (stdin); diff --git a/uip/send.c b/uip/send.c index e7ca7157..2fabe1c3 100644 --- a/uip/send.c +++ b/uip/send.c @@ -398,7 +398,11 @@ go_to_it: && (distsw = atoi (cp)) && altmsg) { vec[vecp++] = "-dist"; - distfile = getcpy (m_mktemp2 (altmsg, invo_name, NULL, NULL)); + if ((cp = m_mktemp2(altmsg, invo_name, NULL, NULL)) == NULL) { + adios(NULL, "unable to create temporary file in %s", + get_temp_dir()); + } + distfile = getcpy (cp); unlink(distfile); if (link (altmsg, distfile) == NOTOK) { /* Cygwin with FAT32 filesystem produces EPERM. */ @@ -409,7 +413,11 @@ go_to_it: ) adios (distfile, "unable to link %s to", altmsg); free (distfile); - distfile = getcpy (m_mktemp2(NULL, invo_name, NULL, NULL)); + if ((cp = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) { + adios(NULL, "unable to create temporary file in %s", + get_temp_dir()); + } + distfile = getcpy (cp); { int in, out; struct stat st; diff --git a/uip/sendsbr.c b/uip/sendsbr.c index 2b946689..c1914aa1 100644 --- a/uip/sendsbr.c +++ b/uip/sendsbr.c @@ -109,10 +109,11 @@ sendsbr (char **vec, int vecp, char *program, char *drft, struct stat *st, * rename the draft file. I'm not quite sure why. */ if (pushsw && unique) { - char *cp = m_mktemp2(drft, invo_name, NULL, NULL); - if (cp == NULL) { - adios ("sendsbr", "unable to create temporary file"); - } + char *cp = m_mktemp2(drft, invo_name, NULL, NULL); + if (cp == NULL) { + adios(NULL, "unable to create temporary file in %s", + get_temp_dir()); + } if (rename (drft, strncpy(file, cp, sizeof(file))) == NOTOK) adios (file, "unable to rename %s to", drft); drft = file; @@ -321,10 +322,10 @@ splitmsg (char **vec, int vecp, char *program, char *drft, char *cp = m_mktemp2(drft, invo_name, NULL, &out); if (cp == NULL) { - adios (drft, "unable to create temporary file for"); + adios(NULL, "unable to create temporary file in %s", + get_temp_dir()); } strncpy(tmpdrf, cp, sizeof(tmpdrf)); - chmod (tmpdrf, 0600); /* * Output the header fields @@ -430,7 +431,8 @@ sendaux (char **vec, int vecp, char *program, char *drft, struct stat *st) snprintf (buf, sizeof(buf), "%d", fd2); vec[vecp++] = buf; } else { - admonish (NULL, "unable to create file for annotation list"); + admonish (NULL, "unable to create temporary file in %s " + "for annotation list", get_temp_dir()); } } if (distfile && distout (drft, distfile, backup) == NOTOK) @@ -571,11 +573,9 @@ static int tmp_fd (void) { int fd; - char *tfile = NULL; + char *tfile; - tfile = m_mktemp2(NULL, invo_name, &fd, NULL); - if (tfile == NULL) return NOTOK; - fchmod(fd, 0600); + if ((tfile = m_mktemp2(NULL, invo_name, &fd, NULL)) == NULL) return NOTOK; if (debugsw) advise (NULL, "temporary file %s selected", tfile); diff --git a/uip/slocal.c b/uip/slocal.c index 8daf6081..7ffbe57d 100644 --- a/uip/slocal.c +++ b/uip/slocal.c @@ -317,14 +317,16 @@ main (int argc, char **argv) if (debug) debug_printf ("retrieving message from file \"%s\"\n", file); if ((fd = copy_message (tempfd, tmpfil, 1)) == -1) - adios (NULL, "unable to create temporary file"); + adios(NULL, "unable to create temporary file in %s", + get_temp_dir()); close (tempfd); } else { /* getting message from stdin */ if (debug) debug_printf ("retrieving message from stdin\n"); if ((fd = copy_message (fileno (stdin), tmpfil, 1)) == -1) - adios (NULL, "unable to create temporary file"); + adios(NULL, "unable to create temporary file in %s", + get_temp_dir()); } if (debug) @@ -1198,7 +1200,6 @@ copy_message (int qd, char *tmpfil, int fold) tfile = m_mktemp2(NULL, invo_name, &fd1, NULL); if (tfile == NULL) return -1; - fchmod(fd1, 0600); strncpy (tmpfil, tfile, BUFSIZ); if (!fold) { diff --git a/uip/viamail.c b/uip/viamail.c index 7c81079d..198413f2 100644 --- a/uip/viamail.c +++ b/uip/viamail.c @@ -191,9 +191,9 @@ via_mail (char *mailsw, char *subjsw, char *parmsw, char *descsw, umask (~m_gmprot ()); - tfile = m_mktemp2(NULL, invo_name, NULL, &fp); - if (tfile == NULL) adios("viamail", "unable to create temporary file"); - chmod(tfile, 0600); + if ((tfile = m_mktemp2(NULL, invo_name, NULL, &fp)) == NULL) { + adios(NULL, "unable to create temporary file in %s", get_temp_dir()); + } strncpy (tmpfil, tfile, sizeof(tmpfil)); if (!strchr(mailsw, '@')) diff --git a/uip/whatnowsbr.c b/uip/whatnowsbr.c index 7c2c021b..d4141389 100644 --- a/uip/whatnowsbr.c +++ b/uip/whatnowsbr.c @@ -1304,7 +1304,11 @@ sendit (char *sp, char **arg, char *file, int pushed) #endif /* not lint */ && altmsg) { vec[vecp++] = "-dist"; - distfile = getcpy (m_mktemp2(altmsg, invo_name, NULL, NULL)); + if ((cp = m_mktemp2(altmsg, invo_name, NULL, NULL)) == NULL) { + adios(NULL, "unable to create temporary file in %s", + get_temp_dir()); + } + distfile = getcpy (cp); unlink(distfile); if (link (altmsg, distfile) == NOTOK) adios (distfile, "unable to link %s to", altmsg);