From 5804afe067edd2bcf3c78d3dce3f3c36121fdbed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= Date: Mon, 26 Feb 2018 16:05:46 +0100 Subject: [PATCH] Fix compiler warnings in pcre2grep --- ...cre2grep-to-avoid-compiler-warnings-.patch | 91 +++++++++++++++++++ pcre2.spec | 4 + 2 files changed, 95 insertions(+) create mode 100644 pcre2-10.31-A-small-fix-to-pcre2grep-to-avoid-compiler-warnings-.patch diff --git a/pcre2-10.31-A-small-fix-to-pcre2grep-to-avoid-compiler-warnings-.patch b/pcre2-10.31-A-small-fix-to-pcre2grep-to-avoid-compiler-warnings-.patch new file mode 100644 index 0000000..05ab874 --- /dev/null +++ b/pcre2-10.31-A-small-fix-to-pcre2grep-to-avoid-compiler-warnings-.patch @@ -0,0 +1,91 @@ +From ecf1a253d8b7c41f8700eb78e598bfddfeb97215 Mon Sep 17 00:00:00 2001 +From: ph10 +Date: Sun, 25 Feb 2018 12:12:48 +0000 +Subject: [PATCH] A small fix to pcre2grep to avoid compiler warnings for + -Wformat-overflow=2. +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +git-svn-id: svn://vcs.exim.org/pcre2/code/trunk@921 6239d852-aaf2-0410-a92c-79f79f948069 +Petr Písař: Ported to 10.31. + +diff --git a/src/pcre2grep.c b/src/pcre2grep.c +index 78121ad..a9379cf 100644 +--- a/src/pcre2grep.c ++++ b/src/pcre2grep.c +@@ -303,7 +303,7 @@ also for include/exclude patterns. */ + typedef struct patstr { + struct patstr *next; + char *string; +- PCRE2_SIZE length; ++ PCRE2_SIZE length; + pcre2_code *compiled; + } patstr; + +@@ -558,7 +558,7 @@ exit(rc); + + Arguments: + s pattern string to add +- patlen length of pattern ++ patlen length of pattern + after if not NULL points to item to insert after + + Returns: new pattern block or NULL on error +@@ -1285,7 +1285,7 @@ doing this for tty input means that no output appears until a lot of input has + been typed. Instead, tty input is handled line by line. We cannot use fgets() + for this, because it does not stop at a binary zero, and therefore there is no + way of telling how many characters it has read, because there may be binary +-zeros embedded in the data. This function is also used for reading patterns ++zeros embedded in the data. This function is also used for reading patterns + from files (the -f option). + + Arguments: +@@ -3497,7 +3497,7 @@ else + + while ((patlen = read_one_line(buffer, sizeof(buffer), f)) > 0) + { +- while (patlen > 0 && isspace((unsigned char)(buffer[patlen-1]))) patlen--; ++ while (patlen > 0 && isspace((unsigned char)(buffer[patlen-1]))) patlen--; + linenumber++; + if (patlen == 0) continue; /* Skip blank lines */ + +@@ -3669,8 +3669,15 @@ for (i = 1; i < argc; i++) + int arglen = (argequals == NULL || equals == NULL)? + (int)strlen(arg) : (int)(argequals - arg); + +- sprintf(buff1, "%.*s", baselen, op->long_name); +- sprintf(buff2, "%s%.*s", buff1, fulllen - baselen - 2, opbra + 1); ++ if (snprintf(buff1, sizeof(buff1), "%.*s", baselen, op->long_name) > ++ (int)sizeof(buff1) || ++ snprintf(buff2, sizeof(buff2), "%s%.*s", buff1, ++ fulllen - baselen - 2, opbra + 1) > (int)sizeof(buff2)) ++ { ++ fprintf(stderr, "pcre2grep: Buffer overflow when parsing %s option\n", ++ op->long_name); ++ pcre2grep_exit(2); ++ } + + if (strncmp(arg, buff1, arglen) == 0 || + strncmp(arg, buff2, arglen) == 0) +@@ -3837,7 +3844,7 @@ for (i = 1; i < argc; i++) + else if (op->type == OP_PATLIST) + { + patdatastr *pd = (patdatastr *)op->dataptr; +- *(pd->lastptr) = add_pattern(option_data, (PCRE2_SIZE)strlen(option_data), ++ *(pd->lastptr) = add_pattern(option_data, (PCRE2_SIZE)strlen(option_data), + *(pd->lastptr)); + if (*(pd->lastptr) == NULL) goto EXIT2; + if (*(pd->anchor) == NULL) *(pd->anchor) = *(pd->lastptr); +@@ -4102,7 +4109,7 @@ if (patterns == NULL && pattern_files == NULL) + if (i >= argc) return usage(2); + patterns = patterns_last = add_pattern(argv[i], (PCRE2_SIZE)strlen(argv[i]), + NULL); +- i++; ++ i++; + if (patterns == NULL) goto EXIT2; + } + +-- +2.13.6 + diff --git a/pcre2.spec b/pcre2.spec index f362b2b..0d7773b 100644 --- a/pcre2.spec +++ b/pcre2.spec @@ -63,6 +63,8 @@ Patch4: pcre2-10.31-Fix-C-bug-with-repeated-character-classes-in-UTF-8-m.pat # Add support to pcre2grep for binary zeros in -f files, upstream bug #2222, # in upstream after 10.31 Patch5: pcre2-10.31-Add-support-to-pcre2grep-for-binary-zeros-in-f-files.patch +# Fix compiler warnings in pcre2grep, in upstream after 10.31 +Patch6: pcre2-10.31-A-small-fix-to-pcre2grep-to-avoid-compiler-warnings-.patch BuildRequires: autoconf BuildRequires: automake BuildRequires: coreutils @@ -144,6 +146,7 @@ Utilities demonstrating PCRE2 capabilities like pcre2grep or pcre2test. %patch3 -p1 %patch4 -p1 %patch5 -p1 +%patch6 -p1 # Because of multilib patch libtoolize --copy --force autoreconf -vif @@ -248,6 +251,7 @@ make %{?_smp_mflags} check VERBOSE=yes %changelog * Mon Feb 26 2018 Petr Pisar - 10.31-3 - Add support to pcre2grep for binary zeros in -f files (upstream bug #2222) +- Fix compiler warnings in pcre2grep * Tue Feb 20 2018 Petr Pisar - 10.31-2 - Fix returning unset groups in POSIX interface if REG_STARTEND has a non-zero