From: Andreas Henriksson <andreas@fatal.se>
To: shemminger@linux-foundation.org
Cc: netdev@vger.kernel.org, Andreas Henriksson <andreas@fatal.se>
Subject: [PATCH 07/12] Fix corruption when using batch files with comments and broken lines.
Date: Fri, 12 Oct 2007 10:56:42 +0200 [thread overview]
Message-ID: <1192179407-22461-7-git-send-email-andreas@fatal.se> (raw)
In-Reply-To: <1192179407-22461-6-git-send-email-andreas@fatal.se>
I could only reproduce on some old pentium machine, don't know why.
Anyway, the patch fixes a problem resulting in a double free
that occurs when using batch files that contains a special combination
of broken up lines and comments as reported in:
http://bugs.debian.org/398912
Thanks to Michal Pokrywka <mpokrywka@hoga.pl> for testcase and information
on which conditions problem could be reproduced under.
Signed-off-by: Andreas Henriksson <andreas@fatal.se>
---
include/utils.h | 2 +-
lib/utils.c | 8 +++++---
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/include/utils.h b/include/utils.h
index 7da2b29..9ee55fd 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -144,7 +144,7 @@ int print_timestamp(FILE *fp);
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
extern int cmdlineno;
-extern size_t getcmdline(char **line, size_t *len, FILE *in);
+extern ssize_t getcmdline(char **line, size_t *len, FILE *in);
extern int makeargs(char *line, char *argv[], int maxargs);
#endif /* __UTILS_H__ */
diff --git a/lib/utils.c b/lib/utils.c
index 4c42dfd..ffef6fe 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -642,9 +642,9 @@ int print_timestamp(FILE *fp)
int cmdlineno;
/* Like glibc getline but handle continuation lines and comments */
-size_t getcmdline(char **linep, size_t *lenp, FILE *in)
+ssize_t getcmdline(char **linep, size_t *lenp, FILE *in)
{
- size_t cc;
+ ssize_t cc;
char *cp;
if ((cc = getline(linep, lenp, in)) < 0)
@@ -672,9 +672,11 @@ size_t getcmdline(char **linep, size_t *lenp, FILE *in)
if (cp)
*cp = '\0';
- *linep = realloc(*linep, strlen(*linep) + strlen(line1) + 1);
+ *lenp = strlen(*linep) + strlen(line1) + 1;
+ *linep = realloc(*linep, *lenp);
if (!*linep) {
fprintf(stderr, "Out of memory\n");
+ *lenp = 0;
return -1;
}
cc += cc1 - 2;
--
1.5.3.4
next prev parent reply other threads:[~2007-10-12 8:57 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-12 8:56 [PATCH 01/12] Fix various typos and nitpicks Andreas Henriksson
2007-10-12 8:56 ` [PATCH 02/12] Add parameters to usage help text Andreas Henriksson
2007-10-12 8:56 ` [PATCH 03/12] Prevent renaming interfaces to empty string Andreas Henriksson
2007-10-12 8:56 ` [PATCH 04/12] Fix up various problems in netbug script Andreas Henriksson
2007-10-12 8:56 ` [PATCH 05/12] Fix typo in tunnel code (o_key vs. i_key) Andreas Henriksson
2007-10-12 8:56 ` [PATCH 06/12] Remove bogus reference to tc-filters(8) from tc(8) manpage Andreas Henriksson
2007-10-12 8:56 ` Andreas Henriksson [this message]
2007-10-12 8:56 ` [PATCH 08/12] Fix ematch cmp and nbyte syntax help text Andreas Henriksson
2007-10-12 8:56 ` [PATCH 09/12] Add new rtacct/nstat manpages and additional symlinks Andreas Henriksson
2007-10-12 8:56 ` [PATCH 10/12] Fix off-by-one in print of wrandom algo Andreas Henriksson
2007-10-12 8:56 ` [PATCH 11/12] Fix overflow in time2tick / tick2time Andreas Henriksson
2007-10-12 8:56 ` [PATCH 12/12] Drop bogus reference to tc-filters and add lartc.org link to manpage Andreas Henriksson
2007-10-12 21:50 ` Stephen Hemminger
2007-10-12 22:49 ` Patrick McHardy
2007-10-17 16:50 ` Andreas Henriksson
2007-10-17 17:05 ` Stephen Hemminger
2007-10-17 17:58 ` Andreas Henriksson
2007-10-17 18:02 ` Stephen Hemminger
2007-10-18 8:13 ` Andreas Henriksson
2007-10-12 21:39 ` [PATCH 10/12] Fix off-by-one in print of wrandom algo Stephen Hemminger
2007-10-12 17:14 ` [PATCH 04/12] Fix up various problems in netbug script Stephen Hemminger
2007-10-12 17:39 ` Andreas Henriksson
2007-10-12 12:01 ` [PATCH 03/12] Prevent renaming interfaces to empty string Patrick McHardy
2007-10-12 17:07 ` Stephen Hemminger
2007-10-12 17:45 ` Andreas Henriksson
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=1192179407-22461-7-git-send-email-andreas@fatal.se \
--to=andreas@fatal.se \
--cc=netdev@vger.kernel.org \
--cc=shemminger@linux-foundation.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 NNTP newsgroup(s).