From owner-freebsd-ports-bugs@FreeBSD.ORG Thu Mar 10 07:00:16 2005 Return-Path: Delivered-To: freebsd-ports-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9587916A4CE for ; Thu, 10 Mar 2005 07:00:16 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2F0EB43D60 for ; Thu, 10 Mar 2005 07:00:16 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.3/8.13.3) with ESMTP id j2A70GZX091901 for ; Thu, 10 Mar 2005 07:00:16 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.3/8.13.1/Submit) id j2A70FdO091900; Thu, 10 Mar 2005 07:00:15 GMT (envelope-from gnats) Resent-Date: Thu, 10 Mar 2005 07:00:15 GMT Resent-Message-Id: <200503100700.j2A70FdO091900@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-ports-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Mats Peterson Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E2D5416A4CE for ; Thu, 10 Mar 2005 06:54:29 +0000 (GMT) Received: from sm5sxl.net (as13-5-6.n.n.bonet.se [217.215.6.225]) by mx1.FreeBSD.org (Postfix) with ESMTP id D510343D4C for ; Thu, 10 Mar 2005 06:54:28 +0000 (GMT) (envelope-from mats@sm5sxl.net) Received: from pc10.snowbee.foo (localhost [127.0.0.1]) by sm5sxl.net (8.12.3/8.12.3) with ESMTP id j2A6sSqF026366; Thu, 10 Mar 2005 07:54:28 +0100 (CET) (envelope-from mats@pc10.snowbee.foo) Received: (from mats@localhost) by pc10.snowbee.foo (8.12.3/8.12.3/Submit) id j2A6sRDO026365; Thu, 10 Mar 2005 07:54:27 +0100 (CET) (envelope-from mats) Message-Id: <200503100654.j2A6sRDO026365@pc10.snowbee.foo> Date: Thu, 10 Mar 2005 07:54:27 +0100 (CET) From: Mats Peterson To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 cc: mats@sm5sxl.net Subject: ports/78662: [PATCH] Metamail 2.7 incorrectly patched X-BeenThere: freebsd-ports-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Mats Peterson List-Id: Ports bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Mar 2005 07:00:16 -0000 >Number: 78662 >Category: ports >Synopsis: [PATCH] Metamail 2.7 incorrectly patched >Confidential: no >Severity: non-critical >Priority: high >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu Mar 10 07:00:15 GMT 2005 >Closed-Date: >Last-Modified: >Originator: Mats Peterson >Release: >Organization: >Environment: >Description: The file 'patch-af' for Metamail 2.7 replaces gets() with fgets() at several places in mailto.c and metamail.c. Unfortunately, the person who made the patch back in -95 seems to have overlooked the fact that fgets() retains the trailing newline character in the buffer, which leads to the test for string match in line 1809 of mailto.c (original source) never returning true. Consequently, 'mailto' will report any manually entered content-type as not being listed in the local mailcap files. Since my original submission of the patch in 2002 (which went completely unprocessed), there has been another patch provided by a guy called Ulf Härnhammar. His patch, however, doesn't correct the abovementioned issues. I have included a patch that includes both my and Ulf's changes. >How-To-Repeat: When including non-text data with "~*" in the 'mailto' program, choose option 1 (Raw data from a file), and manually specify a content-type known to exist in the local mailcap files. >Fix: Below is an updated "patch-af" with additional code to make fgets() work as expected in both mailto.c and metamail.c, and including Ulf Härnhammar's changes. *** metamail.old/mailto.c Wed Feb 9 21:30:26 1994 --- metamail/mailto.c Thu Jul 29 14:32:28 2004 *************** *** 570,575 **** --- 570,576 ---- if (isupper(*sdum)) *sdum = tolower(*sdum); } if (strcmp(CharacterSet, "us-ascii") + && strcmp(CharacterSet, "koi8-r") && strncmp(CharacterSet, "iso-8859-", 9)) { fprintf(stderr, "mailto: Unsupported character set: %s\n", CharacterSet); exit(-1); *************** *** 1130,1135 **** --- 1131,1137 ---- if (part->isrich) { if (strcmp(CharacterSet, "us-ascii") && (strncmp(CharacterSet, "iso-8859-", 9) + && strcmp(CharacterSet, "koi8-r") || part->encoding_type_needed != ENC_NONE)) { fprintf(fp, "Content-type: text/richtext; charset=\"%s\"\n", CharacterSet); } else { *************** *** 1140,1145 **** --- 1142,1148 ---- WriteCtypeNicely(fp, part->content_type); if (strcmp(CharacterSet, "us-ascii") && (strncmp(CharacterSet, "iso-8859-", 9) + && strcmp(CharacterSet, "koi8-r") || part->encoding_type_needed != ENC_NONE)) { fprintf(fp, "; charset=\"%s\"\n", CharacterSet); } else fputs("\n", fp); *************** *** 1745,1750 **** --- 1748,1754 ---- } printf("\n\nEnter your choice as a number from 0 to %d: ", i); fflush(stdout); + *LineBuf = '\0'; fgets(LineBuf, sizeof(LineBuf), stdin); ans = atoi(LineBuf); if (ans == 0 || ans == 1) { *************** *** 1752,1759 **** FILE *fpi, *fpo; printf("\nIf you want to include non-textual data from a file, enter the file name.\nTo include the output of a command, enter \"|\" followed by the command.\nIf you do not want to include anything, just press ENTER (RETURN).\n> "); fflush(stdout); fgets(CTLineBuf, sizeof(CTLineBuf), stdin); ! sdum = CTLineBuf+strlen(CTLineBuf) -1; while (sdum >= CTLineBuf && isspace((unsigned char) *sdum)) { *sdum = '\0'; --sdum; --- 1756,1764 ---- FILE *fpi, *fpo; printf("\nIf you want to include non-textual data from a file, enter the file name.\nTo include the output of a command, enter \"|\" followed by the command.\nIf you do not want to include anything, just press ENTER (RETURN).\n> "); fflush(stdout); + *CTLineBuf = '\0'; fgets(CTLineBuf, sizeof(CTLineBuf), stdin); ! sdum = *CTLineBuf ? CTLineBuf+strlen(CTLineBuf) -1 : CTLineBuf; while (sdum >= CTLineBuf && isspace((unsigned char) *sdum)) { *sdum = '\0'; --sdum; *************** *** 1791,1797 **** int ct; printf("\nEnter the MIME Content-type value for the data from file %s\n (type '?' for a list of locally-valid content-types): ", sdum); fflush(stdout); ! gets(LineBuf); if (index(LineBuf, '/')) { char lc[100], *s, AnsBuf[100]; strcpy(lc, LineBuf); --- 1796,1805 ---- int ct; printf("\nEnter the MIME Content-type value for the data from file %s\n (type '?' for a list of locally-valid content-types): ", sdum); fflush(stdout); ! *LineBuf = '\0'; ! fgets(LineBuf, sizeof(LineBuf), stdin); ! if (*LineBuf) ! LineBuf[strlen(LineBuf) - 1] = '\0'; if (index(LineBuf, '/')) { char lc[100], *s, AnsBuf[100]; strcpy(lc, LineBuf); *************** *** 1809,1815 **** } if (mc) break; printf("The MIME content-type '%s' is not listed in your local mailcap files,\nand may not be a valid MIME type. Do you want to use it anyway [no] ? ", LineBuf); ! s = gets(AnsBuf); while (s && *s && isspace((unsigned char) *s)) ++s; if (s && (*s == 'y' || *s == 'Y')) break; continue; --- 1817,1823 ---- } if (mc) break; printf("The MIME content-type '%s' is not listed in your local mailcap files,\nand may not be a valid MIME type. Do you want to use it anyway [no] ? ", LineBuf); ! s = fgets(AnsBuf, sizeof(AnsBuf), stdin); while (s && *s && isspace((unsigned char) *s)) ++s; if (s && (*s == 'y' || *s == 'Y')) break; continue; *************** *** 2137,2142 **** --- 2145,2151 ---- printf("2: %s\n", CmdBuf); printf("\n\nEnter 1 or 2, or 0 to not edit it: "); fflush(stdout); + *LineBuf = '\0'; fgets(LineBuf, sizeof(LineBuf), stdin); ans = atoi(LineBuf); } else ans = 2; *** metamail.old/metamail.c Thu Feb 17 02:57:19 1994 --- metamail/metamail.c Wed Mar 9 21:30:22 2005 *************** *** 83,89 **** #define MAX_FILE_NAME_SIZE 256 #define WRITE_BINARY "w" #else /* AMIGA */ ! extern char **environ, *gets(); #define CATCOMMAND "cat" #define CATTEMPLATE "cat %s" #define METAMAIL "metamail" --- 83,89 ---- #define MAX_FILE_NAME_SIZE 256 #define WRITE_BINARY "w" #else /* AMIGA */ ! extern char **environ; #define CATCOMMAND "cat" #define CATTEMPLATE "cat %s" #define METAMAIL "metamail" *************** *** 540,545 **** --- 540,546 ---- ans = 2; } else { printf("\nWhat do you want to do with the %s data?\n1 -- See it as text\n2 -- Write it to a file\n3 -- Just skip it\n\n", octetstream ? "raw" : ContentType); + *Fname = '\0'; fgets(Fname, sizeof(Fname), stdin); ans = atoi(Fname); } *************** *** 554,561 **** needname = 0; printf("Please enter the name of a file to which the data should be written\n(Default: %s) > ", suggestedname); fflush(stdout); fgets(Fname, sizeof(Fname), stdin); ! Fname[strlen(Fname) - 1] = '\0'; /* bogus newline */ #if !defined(AMIGA) && !defined(MSDOS) if (!Fname[0]) strcpy(Fname, suggestedname); if (Fname[0] == '~' && Fname[1] == '/') { --- 555,564 ---- needname = 0; printf("Please enter the name of a file to which the data should be written\n(Default: %s) > ", suggestedname); fflush(stdout); + *Fname = '\0'; fgets(Fname, sizeof(Fname), stdin); ! if (*Fname) ! Fname[strlen(Fname) - 1] = '\0'; /* bogus newline */ #if !defined(AMIGA) && !defined(MSDOS) if (!Fname[0]) strcpy(Fname, suggestedname); if (Fname[0] == '~' && Fname[1] == '/') { *************** *** 579,588 **** int overwriteans = -1; do { printf("File %s exists. Do you want to overwrite it (y/n) ?\n", Fname); ! s = gets(AnsBuf); if (!s) { overwriteans = 0; } else { while (s && *s && isspace((unsigned char) *s)) ++s; if (*s == 'y' || *s == 'Y' || !*s || *s == '\n') { overwriteans = 1; --- 582,593 ---- int overwriteans = -1; do { printf("File %s exists. Do you want to overwrite it (y/n) ?\n", Fname); ! *AnsBuf = '\0'; ! s = fgets(AnsBuf, sizeof(AnsBuf), stdin); if (!s) { overwriteans = 0; } else { + s[strlen(s) - 1] = '\0'; while (s && *s && isspace((unsigned char) *s)) ++s; if (*s == 'y' || *s == 'Y' || !*s || *s == '\n') { overwriteans = 1; *************** *** 1202,1210 **** fprintf(outfp, "Content-type: %s", ContentType); for (j=0; jRelease-Note: >Audit-Trail: >Unformatted: System: FreeBSD 4.6.2-RELEASE-p12