Bug 152257 - dos2unix does not strip away ^M
dos2unix does not strip away ^M
Status: CLOSED INSUFFICIENT_DATA
Product: Fedora
Classification: Fedora
Component: dos2unix (Show other bugs)
3
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Tim Waugh
Ben Levenson
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2005-03-26 17:05 EST by LDB
Modified: 2008-02-07 00:36 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2008-02-07 00:36:42 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
new patch that will get rid of extra characters after #endif (573 bytes, patch)
2005-03-26 17:09 EST, LDB
no flags Details | Diff
new patch that will get rid of extra characters after the #endif statements (1.50 KB, patch)
2005-03-26 17:11 EST, LDB
no flags Details | Diff
This is update to an existing patch that strips away ^M (2.36 KB, patch)
2005-03-26 17:14 EST, LDB
no flags Details | Diff
Simple script to apply patches (374 bytes, patch)
2005-03-26 17:15 EST, LDB
no flags Details | Diff
redo of previous update to an existing patch due security issue that strips away ^M (2.30 KB, patch)
2005-03-26 23:13 EST, LDB
no flags Details | Diff

  None (edit)
Description LDB 2005-03-26 17:05:52 EST
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.2) Gecko/20040805 Netscape/7.2

Description of problem:
dos2unix does not strip away ^M properly and when compiling from source
there are compiler warnings.

Version-Release number of selected component (if applicable):
dos2unix-3.1-21

How reproducible:
Always

Steps to Reproduce:
1. dos2unix "ANY FILE"
2. make clean && make [ on RPM source ]
3.
  

Additional info:

I have the fix
Comment 1 LDB 2005-03-26 17:09:19 EST
Created attachment 112366 [details]
new patch that will get rid of extra characters after #endif

This patch will get rid of extra characters after #endif in dos2unix.h
Comment 2 LDB 2005-03-26 17:11:55 EST
Created attachment 112367 [details]
new patch that will get rid of extra characters after the #endif statements

This is a new patch that will get rid of the extra characters after the #endif
statements in dos2unix.c. This will get rid of compiler warnings when compiling
from source.
Comment 3 LDB 2005-03-26 17:14:03 EST
Created attachment 112368 [details]
This is update to an existing patch that strips away ^M

This is an update to a patch that will strip away ^M from a file.
Comment 4 LDB 2005-03-26 17:15:31 EST
Created attachment 112369 [details]
Simple script to apply patches

This is a simple script that will apply patches in the proper order
Comment 5 LDB 2005-03-26 22:00:34 EST
There is an issue that needs to be fixed as well .. 

when using dos2unix as an privileged user on a file owned by root
dos2unix overwrites the file anyway without printing, 

   dos2unix: problems converting file filetoconvert.txt
 
Comment 6 LDB 2005-03-26 22:21:54 EST
This is my fault .. it corrects the dos2unix inconversion issue but introduces
unprivileged user conversion of privileged files.
Comment 7 LDB 2005-03-26 22:31:38 EST
Comment on attachment 112368 [details]
This is update to an existing patch that strips away ^M

This is a BAD patch the introduces a security issue
Comment 8 LDB 2005-03-26 23:07:24 EST
Comment on attachment 112368 [details]
This is update to an existing patch that strips away ^M

>* Fix http://bugzilla.redhat.com/57508 (make dos2unix not modify Mac
>  files unless in mac2unix mode)
>* Make mac2unix mode not create duplicate Unix line delimiters when
>  run on a DOS file. (mschwendt@users.sf.net)
>* Remove extra directive arguments on #endif DEBUG
>  statements causing compiler warnings (thesource@ldb-jab.org)
>
>diff -Nur dos2unix-3.1-orig/dos2unix.c dos2unix-3.1/dos2unix.c
>--- dos2unix-3.1-orig/dos2unix.c	1998-11-19 13:19:25.000000000 +0100
>+++ dos2unix-3.1/dos2unix.c	2004-09-26 20:57:41.606587616 +0200
>@@ -153,6 +153,24 @@
> }
> 
> 
>+void StripDelimiter(FILE* ipInF, FILE* ipOutF, CFlag *ipFlag, int CurChar)
>+{
>+  int TempNextChar;
>+  /* Don't modify Mac files when in dos2unix mode. */
>+  if ( (TempNextChar = getc(ipInF)) != EOF) {
>+    ungetc( TempNextChar, ipInF );  /* put back peek char */
>+    if ( TempNextChar != '\x0a' ) {
>+      putc( CurChar, ipOutF );  /* Mac line, put back CR */
>+    }
>+  }
>+  else if ( CurChar == '\x0d' ) {  /* EOF: last Mac line delimiter (CR)? */
>+    putc( CurChar, ipOutF );
>+  }
>+  if (!ipFlag->NewLine) {  /* add additional LF? */
>+    putc('\n', ipOutF);
>+  }
>+}
>+
> /* converts stream ipInF to UNIX format text and write to stream ipOutF
>  * RetVal: 0  if success
>  *         -1  otherwise
>@@ -161,6 +179,7 @@
> {
>     int RetVal = 0;
>     int TempChar;
>+    int TempNextChar;
>     
>     if ( macmode )
>       ipFlag->ConvMode = 3;
>@@ -177,9 +196,7 @@
> 		break;
> 	      } 
> 	    } else {
>-	      if (ipFlag->NewLine) {
>-		putc('\n', ipOutF);
>-	      }
>+	      StripDelimiter( ipInF, ipOutF, ipFlag, TempChar );
> 	    }
> 	  }
> 	  break;
>@@ -193,9 +210,7 @@
> 		break;
> 	      }
> 	    } else {
>-	      if (ipFlag->NewLine) {
>-		putc('\n', ipOutF);
>-	      }
>+	      StripDelimiter( ipInF, ipOutF, ipFlag, TempChar );
> 	    }
> 	  }
> 	  break;
>@@ -209,9 +224,7 @@
> 		break;
> 	      }
> 	    } else {
>-	      if (ipFlag->NewLine) {
>-		putc('\n', ipOutF);
>-	      }
>+	      StripDelimiter( ipInF, ipOutF, ipFlag, TempChar );
> 	    }
> 	  }
> 	  break;
>@@ -227,6 +240,13 @@
> 		}
> 	      }
> 	    else{
>+	      if ( (TempNextChar = getc(ipInF)) != EOF) {
>+		ungetc( TempNextChar, ipInF );  /* put back peek char */
>+		/* Don't touch this delimiter if it's a CR,LF pair. */
>+		if ( TempNextChar == '\x0a' ) {
>+		  continue;
>+		}
>+	      }
> 	      if (putc('\x0a', ipOutF) == EOF)
> 		{
> 		  RetVal = -1;
Comment 9 LDB 2005-03-26 23:08:45 EST
(In reply to comment #6)
> This is my fault .. it corrects the dos2unix inconversion issue but introduces
> unprivileged user conversion of privileged files.

I have seemingly fixed it the security issue I created
Comment 10 LDB 2005-03-26 23:10:42 EST
(In reply to comment #7)
> (From update of attachment 112368 [details] [edit])
> This is a BAD patch the introduces a security issue
> 

I will load the patch that will obsolete attachment #112368 [details]
Comment 11 LDB 2005-03-26 23:11:16 EST
(In reply to comment #7)
> (From update of attachment 112368 [details] [edit])
> This is a BAD patch the introduces a security issue
> 

I will upload the patch that will obsolete attachment #112368 [details]
Comment 12 LDB 2005-03-26 23:13:46 EST
Created attachment 112371 [details]
redo of previous update to an existing patch due security issue that strips away ^M
Comment 13 Tim Waugh 2006-07-10 10:57:12 EDT
Completely confused by this.  Is this patch still needed?
Comment 14 petrosyan 2008-02-07 00:36:42 EST
Fedora Core 3 is not maintained anymore.

Setting status to "INSUFFICIENT_DATA". If you can reproduce this bug in the
current Fedora release please reopen this bug and assign it to the corresponding
Fedora version.

Note You need to log in before you can comment on or make changes to this bug.