Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/freebsd/poudriere.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan Drewery <bryan@shatow.net>2020-04-29 01:20:03 +0300
committerBryan Drewery <bryan@shatow.net>2020-04-30 18:26:56 +0300
commit7d4c3a78d281e858c2156e99cd403c2522d33028 (patch)
treef832ee1c4ad416b4daab74b5cbf0d5fd70155ff2
parent0dbc97eb2fe1748c9ca8695f4a97b8e8b41033d9 (diff)
gsub builtin: Fix an INTOFF leak
-rw-r--r--src/poudriere-sh/helpers.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/poudriere-sh/helpers.c b/src/poudriere-sh/helpers.c
index e36ee08b..1986af05 100644
--- a/src/poudriere-sh/helpers.c
+++ b/src/poudriere-sh/helpers.c
@@ -26,6 +26,8 @@
#include <sys/types.h>
#include <sys/sbuf.h>
+
+#include <assert.h>
#include <errno.h>
#include <fnmatch.h>
#include <signal.h>
@@ -263,9 +265,8 @@ _gsub_shell(struct sbuf *newstr, char *string, const char *pattern,
ret = 0;
INTOFF;
if (sbuf_new(newstr, buf, bufsiz, SBUF_AUTOEXTEND) == NULL) {
+ INTON;
errx(EX_SOFTWARE, "%s", "sbuf_new");
- ret = 1;
- goto out;
}
/*
* fnmatch(3) doesn't return the length matched so we need to
@@ -310,7 +311,6 @@ _gsub_shell(struct sbuf *newstr, char *string, const char *pattern,
}
sbuf_finish(newstr);
-out:
return (ret);
}
@@ -368,9 +368,8 @@ _gsub_strstr(struct sbuf *newstr, const char *string, const char *pattern,
}
INTOFF;
if (sbuf_new(newstr, buf, bufsiz, SBUF_FIXEDLEN) == NULL) {
+ INTON;
errx(EX_SOFTWARE, "%s", "sbuf_new");
- ret = 1;
- goto out;
}
for (p = string; (p2 = strstr(p, pattern)) != NULL; p2 += pattern_len,
p = p2) {
@@ -379,7 +378,6 @@ _gsub_strstr(struct sbuf *newstr, const char *string, const char *pattern,
}
sbuf_cat(newstr, p);
sbuf_finish(newstr);
-out:
return (ret);
}
@@ -392,6 +390,9 @@ _gsub(char **argv, const char *var_return)
size_t pattern_len, replacement_len;
int ret;
bool match_shell, sbuf_free;
+#ifndef NDEBUG
+ const int inton = is_int_on();
+#endif
ret = 0;
string = argv[1];
@@ -416,17 +417,19 @@ _gsub(char **argv, const char *var_return)
if (match_shell) {
ret = _gsub_shell(&newstr, string, pattern, pattern_len,
replacement, replacement_len, buf, sizeof(buf));
+ assert(is_int_on());
} else if (pattern_len == 1 && replacement_len == 1) {
ret = _gsub_inplace(string, *pattern, *replacement);
outstr = string;
- INTOFF;
+ assert(inton == is_int_on());
} else if (pattern_len == 1 && replacement_len == 0) {
ret = _gsub_shift(string, *pattern);
outstr = string;
- INTOFF;
+ assert(inton == is_int_on());
} else {
ret = _gsub_strstr(&newstr, string, pattern, pattern_len,
replacement, replacement_len, buf, sizeof(buf));
+ assert(is_int_on());
}
if (ret != 0)
goto out;
@@ -439,10 +442,13 @@ empty_pattern:
printf("%s\n", outstr);
else
setvar(var_return, outstr, 0);
- if (sbuf_free)
+ if (sbuf_free) {
+ assert(is_int_on());
sbuf_delete(&newstr);
+ INTON;
+ }
out:
- INTON;
+ assert(inton == is_int_on());
return (ret);
}