--- Convert-UUlib/uulib/uunconc.c 2001/06/11 19:49:00 1.1 +++ Convert-UUlib/uulib/uunconc.c 2002/02/10 22:47:18 1.3 @@ -1,7 +1,7 @@ /* * This file is part of uudeview, the simple and friendly multi-part multi- - * file uudecoder program (c) 1994 by Frank Pilhofer. The author may be - * contacted by his email address, fp@informatik.uni-frankfurt.de + * file uudecoder program (c) 1994-2001 by Frank Pilhofer. The author may + * be contacted at fp@fpx.de * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -49,7 +49,7 @@ #include #endif -#include +#include #include #include #include @@ -165,7 +165,7 @@ /* prepare line length table */ UUxlen[0] = 1; - for(i = 1, j = 5; i <= 60; i += 3, j += 4) + for(i = 1, j = 5; i <= 61; i += 3, j += 4) UUxlen[i] = UUxlen[i+1] = UUxlen[i+2] = j; /* prepare other tables */ @@ -243,9 +243,9 @@ */ while (*p1) { if (*p1 == '&') { - if (FP_strnicmp (p1, "&", 5) == 0) { p1+=5; *p2++='&'; } - else if (FP_strnicmp (p1, "<", 4) == 0) { p1+=4; *p2++='<'; } - else if (FP_strnicmp (p1, ">", 4) == 0) { p1+=4; *p2++='>'; } + if (FP_strnicmp (p1, "&", 5) == 0) { p1+=5; *p2++='&'; res=1; } + else if (FP_strnicmp (p1, "<", 4) == 0) { p1+=4; *p2++='<'; res=1; } + else if (FP_strnicmp (p1, ">", 4) == 0) { p1+=4; *p2++='>'; res=1; } else *p2++ = *p1++; res = 1; } @@ -450,8 +450,10 @@ * evaluated if the first character is lowercase, which really shouldn't * be in uuencoded text. */ - if (len != j && - !(*ptr != 'M' && *ptr != 'h' && len > j && len <= UUxlen[UUxlat['M']])) { + if (len != j && + ((ptr[0] == '-' && ptr[1] == '-' && strstr(ptr,"part")!=NULL) || + !(*ptr != 'M' && *ptr != 'h' && + len > j && len <= UUxlen[UUxlat['M']]))) { if (encoding==UU_ENCODED) return 0; goto _t_XX; /* bad length */ } @@ -861,9 +863,8 @@ * So if the part ends here, don't print a line break" */ if ((*ptr == '\012' || *ptr == '\015') && - (!feof (datain) && - (ftell(datain)thisfile == NULL) return UURET_ILLVAL; @@ -1151,18 +1157,40 @@ if (data->state & UUFILE_NOBEGIN && !uu_desperate) return UURET_NODATA; - if (data->uudet == QP_ENCODED || data->uudet == PT_ENCODED) + if (data->uudet == PT_ENCODED) mode = "wt"; /* open text files in text mode */ else mode = "wb"; /* otherwise in binary */ +#ifdef HAVE_MKSTEMP + if ((getuid()==geteuid()) && (getgid()==getegid())) { + tmpdir=getenv("TMPDIR"); + } + + if (!tmpdir) { + tmpdir = "/tmp"; + } + data->binfile = malloc(strlen(tmpdir)+strlen(tmpprefix)+2); + + if (!data->binfile) { +#else if ((data->binfile = tempnam (NULL, "uu")) == NULL) { +#endif /* HAVE_MKSTEMP */ UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, uustring (S_NO_TEMP_NAME)); return UURET_NOMEM; } +#ifdef HAVE_MKSTEMP + strcpy(data->binfile, tmpdir); + strcat(data->binfile, "/"); + strcat(data->binfile, tmpprefix); + + if ((tmpfd = mkstemp(data->binfile)) == -1 || + (dataout = fdopen(tmpfd, mode)) == NULL) { +#else if ((dataout = fopen (data->binfile, mode)) == NULL) { +#endif /* HAVE_MKSTEMP */ /* * we couldn't create a temporary file. Usually this means that TMP * and TEMP aren't set @@ -1170,11 +1198,18 @@ UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, uustring (S_WR_ERR_TARGET), data->binfile, strerror (uu_errno = errno)); +#ifdef HAVE_MKSTEMP + if (tmpfd != -1) { + unlink(data->binfile); + close(tmpfd); + } +#endif /* HAVE_MKSTEMP */ FP_free (data->binfile); data->binfile = NULL; uu_errno = errno; return UURET_IOERR; } + /* * we don't have begin lines in Base64 or plain text files. */ @@ -1318,7 +1353,13 @@ */ if (data->uudet == BH_ENCODED && data->binfile) { +#ifdef HAVE_MKSTEMP + ntmp = malloc(strlen(tmpdir)+strlen(tmpprefix)+2); + + if (ntmp == NULL) { +#else if ((ntmp = tempnam (NULL, "uu")) == NULL) { +#endif /* HAVE_MKSTEMP */ UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, uustring (S_NO_TEMP_NAME)); progress.action = 0; @@ -1332,15 +1373,30 @@ free (ntmp); return UURET_IOERR; } +#ifdef HAVE_MKSTEMP + strcpy(ntmp, tmpdir); + strcat(ntmp, "/"); + strcat(ntmp, tmpprefix); + if ((tmpfd = mkstemp(ntmp)) == -1 || + (dataout = fdopen(tmpfd, "wb")) == NULL) { +#else if ((dataout = fopen (ntmp, "wb")) == NULL) { +#endif /* HAVE_MKSTEMP */ UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, uustring (S_NOT_OPEN_TARGET), ntmp, strerror (uu_errno = errno)); progress.action = 0; fclose (datain); +#ifdef HAVE_MKSTEMP + if (tmpfd != -1) { + unlink(ntmp); + close(tmpfd); + } +#endif /* HAVE_MKSTEMP */ free (ntmp); return UURET_IOERR; } + /* * read fork lengths. remember they're in Motorola format */