Bug 8635 - The "ls" command of nash, if it is built using "-DDEBUG", crashes
Summary: The "ls" command of nash, if it is built using "-DDEBUG", crashes
Status: RESOLVED FIXED
Alias: None
Product: Mageia
Classification: Unclassified
Component: RPM Packages (show other bugs)
Version: 2
Hardware: i586 Linux
Priority: Normal minor
Target Milestone: ---
Assignee: Samuel Verschelde
QA Contact:
URL:
Whiteboard:
Keywords: NEEDINFO, PATCH, Triaged
Depends on:
Blocks:
 
Reported: 2013-01-08 16:57 CET by Gilles Allard
Modified: 2013-09-02 12:58 CEST (History)
1 user (show)

See Also:
Source RPM: mkinitrd
CVE:
Status comment:


Attachments
Patch to fix crash of nash builtin "ls" command (243 bytes, application/octet-stream)
2013-01-08 16:57 CET, Gilles Allard
Details

Description Gilles Allard 2013-01-08 16:57:37 CET
Created attachment 3342 [details]
Patch to fix crash of nash builtin "ls" command

Involved package : mkinitrd-6.0.93-28.mga2.src.rpm ( and beyond )

If nash is built using flag "-DDEBUG" ( this is not very often the case ), it offers a "ls" command which crashes when the listed directory is closed.

My proposal for a patch : see attachment which is an unified diff between nash.c~ ( old ) & fixed nash.c
Comment 1 Samuel Verschelde 2013-08-29 11:45:58 CEST
Hi,

Thanks you for reporting this bug and providing a patch. However, what's not clear is if our build of nash is affected by this bug, or only the sources for people who rebuild it with -DDEBUG. If it's only the latter, I don't think it's really necessary to patch it. We could have patched it in cauldron, but mkinitrd has been replaced by dracut.

Keywords: (none) => NEEDINFO, PATCH
CC: (none) => stormi

Comment 2 Gilles Allard 2013-08-31 09:06:42 CEST
Hi

(In reply to Samuel VERSCHELDE from comment #1)
> Hi,
> 
> Thanks you for reporting this bug and providing a patch. However, what's not
> clear is if our build of nash is affected by this bug, or only the sources
> for people who rebuild it with -DDEBUG. 

The build of "nash" is not at all affected by this patch. Only the source file is.

> If it's only the latter, I don't
> think it's really necessary to patch it. We could have patched it in
> cauldron, but mkinitrd has been replaced by dracut.

Fixing this bug is not mandatory but I think it can be useful in case of a problem. I used this "nash" feature to fix the "mkinitrd" wrong behaviour.
Comment 3 Samuel Verschelde 2013-08-31 11:06:00 CEST
Here's what I propose to do: I will add the patch in svn, but will not submit the package to the build system. If in the future we have to issue an update to mkinitrd then it will be fixed at the same time. 

Can you explain what your patch does and why it fixes the bug?

Keywords: (none) => Triaged
Assignee: bugsquad => stormi
Source RPM: (none) => mkinitrd

Comment 4 Gilles Allard 2013-09-01 15:05:57 CEST
Hi

(In reply to Samuel VERSCHELDE from comment #3)
> Here's what I propose to do: I will add the patch in svn, but will not
> submit the package to the build system. If in the future we have to issue an
> update to mkinitrd then it will be fixed at the same time. 
> 
> Can you explain what your patch does and why it fixes the bug?

In lsdir subroutine (between #ifdef DEBUG, #endif) this patch changes the argument of the last (I think) call to "closedir" from closedir(thedir) into closedir(dir)

"closedir" requires a DIR* arg (dir is of type DIR*) but "thedir" is a char* variable (one of the arguments of "lsdir"). Obviously, calling "closedir(char *thedir)" is wrong (a real bug); this is why nash crashes.

Best regards.
Comment 5 Samuel Verschelde 2013-09-02 12:56:00 CEST
Looks like the bug comes from an old patch from Mandriva :

[samuel@localhost SOURCES]$ cat Add-missing-closedir.patch
From 1c374f3a2102601ea1510035bdf62427b1190364 Mon Sep 17 00:00:00 2001
From: Andrey Borzenkov <arvidjaar@mail.ru>
Date: Mon, 15 Jun 2009 16:46:48 +0200
Subject: [PATCH] Add missing closedir

Fix missing closedir preventing umount of /initrd/sys (Mandriva bug #16699)
---
 nash/nash.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/nash/nash.c b/nash/nash.c
index d2c5517..0daf281 100644
--- a/nash/nash.c
+++ b/nash/nash.c
@@ -734,6 +734,7 @@ static int lsdir(char *thedir, char * prefix)
             printf("\n");
         }
     }
+    closedir(thedir);
     return 0;
 }
 #endif
--
1.7.1
Comment 6 Samuel Verschelde 2013-09-02 12:58:36 CEST
Fixed in SVN. Package NOT submitted to updates_testing, as I said in comment #3. 

Thanks for reporting.

Status: NEW => RESOLVED
Resolution: (none) => FIXED


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