From: Juan Perez-Sanchez <lithoxs@gmail.com>
To: linux-8086 <linux-8086@vger.kernel.org>
Subject: [PATCH] Fixed bug when copying many files
Date: Wed, 21 Nov 2012 15:03:16 -0600 [thread overview]
Message-ID: <CAD6VGuYDDYckt_u=2jr2Ma5eeC=6Ea5eUD8kCx58PO85fmF8Yg@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 501 bytes --]
Hi,
Attached is a patch to fix a very old bug, the #6 bug listed in
the BUGS file in the elks source. It happened to be a memory leak and
null pointer dereferencing in the cp program. I tested the patch using
Qemu, copying the entire bin directory to a mounted hard disk image.
Now the copy operation succeeds. After the simulation, under linux,
fsck'ed the destination disk image and there were no errors. Also
diff'ed the copied files with the originals and they all matched.
Greetings,
Juan
[-- Attachment #2: elksT.patch --]
[-- Type: application/octet-stream, Size: 956 bytes --]
diff -Nurb elkscmd.orig/file_utils/cp.c elkscmd/file_utils/cp.c
--- elkscmd.orig/file_utils/cp.c 2012-08-18 13:28:59.000000000 -0500
+++ elkscmd/file_utils/cp.c 2012-11-21 10:08:33.000000000 -0600
@@ -18,6 +18,10 @@
#include <utime.h>
#include <errno.h>
+#define BUF_SIZE 1024
+
+char *buf;
+
void
main(argc, argv)
char **argv;
@@ -36,6 +40,7 @@
exit(1);
}
+ buf = malloc(BUF_SIZE);
while (argc-- > 2) {
srcname = argv[1];
destname = lastarg;
@@ -44,11 +49,10 @@
(void) copyfile(*++argv, destname, FALSE);
}
+ free(buf);
exit(0);
}
-#define BUF_SIZE 1024
-
typedef struct chunk CHUNK;
#define CHUNKINITSIZE 4
struct chunk {
@@ -93,7 +97,6 @@
int rcc;
int wcc;
char *bp;
- char *buf;
struct stat statbuf1;
struct stat statbuf2;
struct utimbuf times;
@@ -128,7 +131,6 @@
return FALSE;
}
- buf = malloc(BUF_SIZE);
while ((rcc = read(rfd, buf, BUF_SIZE)) > 0) {
bp = buf;
while (rcc > 0) {
reply other threads:[~2012-11-21 21:03 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAD6VGuYDDYckt_u=2jr2Ma5eeC=6Ea5eUD8kCx58PO85fmF8Yg@mail.gmail.com' \
--to=lithoxs@gmail.com \
--cc=linux-8086@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).