gawk-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gawk-diffs] [SCM] gawk branch, feature/stringfix, created. gawk-4.1.0-2


From: Andrew J. Schorr
Subject: [gawk-diffs] [SCM] gawk branch, feature/stringfix, created. gawk-4.1.0-2416-gbaa3d88
Date: Thu, 26 Jan 2017 19:29:34 +0000 (UTC)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gawk".

The branch, feature/stringfix has been created
        at  baa3d88037962e5a0cd97ad048bb63f8efe2d789 (commit)

- Log -----------------------------------------------------------------
http://git.sv.gnu.org/cgit/gawk.git/commit/?id=baa3d88037962e5a0cd97ad048bb63f8efe2d789

commit baa3d88037962e5a0cd97ad048bb63f8efe2d789
Author: Andrew J. Schorr <address@hidden>
Date:   Thu Jan 26 14:29:00 2017 -0500

    Add some paranoid checks to make sure stptr was malloced before freeing it.

diff --git a/ChangeLog b/ChangeLog
index 62b956a..12f0e5c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2017-01-26         Andrew J. Schorr     <address@hidden>
 
+       * node.c (r_format_val): Before we free s->stptr, make sure that it
+       was malloced.
+       (wstr2str): Add comment explaining why it's safe to free n->stptr
+       without doing any checks.
+       * mpfr.c (mpg_format_val): Ditto. And no need to reset the STRCUR flag
+       that we just checked.
+
+2017-01-26         Andrew J. Schorr     <address@hidden>
+
        * awk.h (enum block_id): Remove BLOCK_INVALID, since it serves no
        useful purpose and seems to slow things down a bit.
        * node.c (nextfree): Remove first invalid entry.
diff --git a/mpfr.c b/mpfr.c
index c0f1ff0..8a5e9a6 100644
--- a/mpfr.c
+++ b/mpfr.c
@@ -381,12 +381,10 @@ mpg_format_val(const char *format, int index, NODE *s)
        }
        s->flags = oflags;
        s->stlen = r->stlen;
-       if ((s->flags & STRCUR) != 0)
+       if ((s->flags & (MALLOC|STRCUR)) == (MALLOC|STRCUR))
                efree(s->stptr);
        s->stptr = r->stptr;
        freenode(r);    /* Do not unref(r)! We want to keep s->stptr == 
r->stpr.  */
-
-       s->flags |= STRCUR;
        free_wstr(s);
        return s;
 }
diff --git a/node.c b/node.c
index d7ed98e..6300bd4 100644
--- a/node.c
+++ b/node.c
@@ -248,7 +248,7 @@ r_format_val(const char *format, int index, NODE *s)
                }
                s->flags = oflags;
                s->stlen = r->stlen;
-               if ((s->flags & STRCUR) != 0)
+               if ((s->flags & (MALLOC|STRCUR)) == (MALLOC|STRCUR))
                        efree(s->stptr);
                s->stptr = r->stptr;
                freenode(r);    /* Do not unref(r)! We want to keep s->stptr == 
r->stpr.  */
@@ -273,7 +273,7 @@ r_format_val(const char *format, int index, NODE *s)
                        s->flags |= STRING;
                }
        }
-       if ((s->flags & STRCUR) != 0)
+       if ((s->flags & (MALLOC|STRCUR)) == (MALLOC|STRCUR))
                efree(s->stptr);
        emalloc(s->stptr, char *, s->stlen + 1, "format_val");
        memcpy(s->stptr, sp, s->stlen + 1);
@@ -844,6 +844,7 @@ wstr2str(NODE *n)
        }
        *cp = '\0';
 
+       /* N.B. caller just created n with make_string, so this free is safe */
        efree(n->stptr);
        n->stptr = newval;
        n->stlen = cp - newval;

-----------------------------------------------------------------------


hooks/post-receive
-- 
gawk



reply via email to

[Prev in Thread] Current Thread [Next in Thread]