Bug 57700 - unix2dos segfault if no write permission to current directory
unix2dos segfault if no write permission to current directory
Status: CLOSED CURRENTRELEASE
Product: Red Hat Linux
Classification: Retired
Component: unix2dos (Show other bugs)
7.2
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Bernhard Rosenkraenzer
Ben Levenson
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2001-12-19 06:31 EST by Binand Sethumadhavan
Modified: 2007-04-18 12:38 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2001-12-19 06:31:36 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)

  None (edit)
Description Binand Sethumadhavan 2001-12-19 06:31:32 EST
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 11:37:36 EST
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.