From f22e47d873ac6b7abbc31fdedc51019766ee7c86 Mon Sep 17 00:00:00 2001 From: Andreas Gruenbacher Date: Sun, 30 Nov 2014 15:47:32 +0100 Subject: More savebuf/savestr error handling * bootstrap.conf: use xmemdup0 module. * src/pch.c (there_is_another_patch): Use xmemdup0 instead of savebuf when we cannot recover from out-of-memory situations. (intuit_diff_type): Likewise, use xstrdup instead of savestr. (another_hunk): Handle the case when savestr returns NULL. * src/util.c (fetchname, parse_name): Use xmemdup0 instead of savebuf when we cannot recover from out-of-memory situations. Bugs pointed out by Tobias Stoeckmann . --- bootstrap.conf | 1 + src/pch.c | 12 ++++++++---- src/util.c | 10 ++++------ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/bootstrap.conf b/bootstrap.conf index 7649539..d6074b3 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -69,6 +69,7 @@ utimens verror xalloc xlist +xmemdup0 " gnulib_tool_option_extras='--symlink --makefile-name=gnulib.mk' diff --git a/src/pch.c b/src/pch.c index aab17aa..abfe87a 100644 --- a/src/pch.c +++ b/src/pch.c @@ -25,6 +25,7 @@ #include #include #include +#include #undef XTERN #define XTERN #include @@ -291,8 +292,7 @@ there_is_another_patch (bool need_header, mode_t *file_type) t = buf + strlen (buf); if (t > buf + 1 && *(t - 1) == '\n') { - inname = savebuf (buf, t - buf); - inname[t - buf - 1] = 0; + inname = xmemdup0 (buf, t - buf - 1); inerrno = stat_file (inname, &instat); if (inerrno) { @@ -623,7 +623,7 @@ intuit_diff_type (bool need_header, mode_t *p_file_type) else { char oldc = *t; *t = '\0'; - revision = savestr (revision); + revision = xstrdup (revision); *t = oldc; } } @@ -1015,7 +1015,7 @@ intuit_diff_type (bool need_header, mode_t *p_file_type) } else { - inname = savestr(p_name[i]); + inname = xstrdup (p_name[i]); inerrno = stat_errno[i]; invc = version_controlled[i]; instat = st[i]; @@ -1255,6 +1255,8 @@ another_hunk (enum diff difftype, bool rev) s++; *s = '\0'; p_c_function = savestr (p_c_function); + if (! p_c_function) + return -1; } p_hunk_beg = p_input_line + 1; while (p_end < p_max) { @@ -1658,6 +1660,8 @@ another_hunk (enum diff difftype, bool rev) s++; *s = '\0'; p_c_function = savestr (p_c_function); + if (! p_c_function) + return -1; } if (!p_ptrn_lines) p_first++; /* do append rather than insert */ diff --git a/src/util.c b/src/util.c index 0af6013..66ae90f 100644 --- a/src/util.c +++ b/src/util.c @@ -27,6 +27,7 @@ #define XTERN #include #include +#include #include #include "ignore-value.h" @@ -1476,8 +1477,7 @@ fetchname (char const *at, int strip_leading, char **pname, break; } } - name = savebuf (at, t - at + 1); - name[t - at] = 0; + name = xmemdup0 (at, t - at); } /* If the name is "/dev/null", ignore the name and mark the file @@ -1509,8 +1509,7 @@ fetchname (char const *at, int strip_leading, char **pname, u--; if (u != t && *(u-1) == '\r') u--; - timestr = savebuf (t, u - t + 1); - timestr[u - t] = 0; + timestr = xmemdup0 (t, u - t); } if (*t != '\n') @@ -1568,8 +1567,7 @@ parse_name (char const *s, int strip_leading, char const **endp) for (t = s; *t && ! ISSPACE ((unsigned char) *t); t++) /* do nothing*/ ; - ret = savebuf (s, t - s + 1); - ret[t - s] = 0; + ret = xmemdup0 (s, t - s); if (endp) *endp = t; } -- cgit v1.2.1