Bug 57700 - unix2dos segfault if no write permission to current directory
Summary: unix2dos segfault if no write permission to current directory
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: unix2dos   
(Show other bugs)
Version: 7.2
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Bernhard Rosenkraenzer
QA Contact: Ben Levenson
URL:
Whiteboard:
Keywords:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2001-12-19 11:31 UTC by Binand Sethumadhavan
Modified: 2007-04-18 16:38 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2001-12-19 11:31:36 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

Description Binand Sethumadhavan 2001-12-19 11:31:32 UTC
If the current directory is a directory in which the user has no write 
permission,  unix2dos (and dos2unix also, should I file a separate bug 
report for that?) segfaults.

Illustration:

binand@binand[~]:(92) cd /dev
binand@binand[/dev]:(93) unix2dos -n /etc/passwd /tmp/passwd
unix2dos: converting file /etc/passwd to file /tmp/passwd in DOS format 
...
Segmentation fault

Also, there are other problems with unix2dos

1. The man page says it is the documentation for dos2unix ;-)

2. The compilation is not clean. This perl snippet seems to fix
this, but it will add a BuildRequires.

perl -pi -e 's/(#endif|#else)[^ ]*(.*)/$1 \/* $2 *\//g' unix2dos.[ch]

This patch fixes the segfault:

--- unix2dos-2.2/unix2dos.c     Wed Dec 19 16:31:49 2001
+++ unix2dos-2.2.patched/unix2dos.c     Wed Dec 19 16:35:59 2001
@@ -236,7 +236,7 @@
     RetVal = -1;

    /* can close in file? */
-  if ((InF) && (fclose(InF) == EOF))
+  if ((!RetVal) && (InF) && (fclose(InF) == EOF))
     RetVal = -1;

   /* can close out file? */
@@ -315,7 +315,7 @@
     RetVal = -1;

    /* can close in file? */
-  if ((InF) && (fclose(InF) == EOF))
+  if ((!RetVal) && (InF) && (fclose(InF) == EOF))
     RetVal = -1;

   /* can close out file? */

Comment 1 Bernhard Rosenkraenzer 2002-01-17 16:37:36 UTC
Fixed in dos2unix-3.1-9, unix2dos-2.2-14

(Your patch still leaves an fd leak in there, by the way. The right fix is to
use the fd generated by mkstemp)



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