From: JinWang An Date: Thu, 23 Dec 2021 05:11:06 +0000 (+0900) Subject: Imported Upstream version 1.2.3 X-Git-Tag: upstream/1.2.3^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0fd919a85063f54f7e267eef5569d58e2e7f3ef4;p=platform%2Fupstream%2Flibpipeline.git Imported Upstream version 1.2.3 --- diff --git a/.bzrignore b/.bzrignore index 61ad801..e7eae70 100644 --- a/.bzrignore +++ b/.bzrignore @@ -29,4 +29,5 @@ tests/basic tests/exec tests/inspect tests/pump +tests/reading_long_line tests/redirect diff --git a/ChangeLog b/ChangeLog index f2187f7..8baa252 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,57 @@ +Wed Apr 24 07:48:26 BST 2013 Colin Watson + + * Version: 1.2.3. + * lib/Makefile.am (libpipeline_la_LDFLAGS): Bump -version-info to + 3:3:2. + +Wed Apr 24 07:44:38 BST 2013 Colin Watson + + * lib/pipeline.c (pipeline_wait_all): Free active_pipelines if it is + entirely empty. + +Wed Apr 24 07:27:44 BST 2013 Peter Schiffer + + * lib/pipeline.c (pipecmd_new_argstr): Fix memory leak when the + first word of argstr is "exec". + * tests/argstr.c (test_argstr_exec): Free cmd at end. + * tests/basic.c (test_basic_wait_all): Free statuses at end. + (test_basic_clearenv): Free p and p2 at end. + * tests/exec.c (test_exec_process, test_exec_function): Free cmd at + end of loop. + * tests/redirect.c (test_redirect_files): Free p and template at + end. + +Tue Apr 23 07:52:40 BST 2013 Colin Watson + + * lib/pipeline.c (pipecmd_exec): Flush stdio before starting a + sequence. + * NEWS: Document this. + +Tue Apr 23 07:50:45 BST 2013 Peter Schiffer + Colin Watson + + Don't read uninitialised memory when testing for the end of long + lines (Fedora bug #876108). + + * lib/pipeline.c (get_line): Fix incorrect memchr bounds. + * tests/Makefile.am (TESTS): Add reading_long_line. + (reading_long_line_SOURCES, reading_long_line_LDADD): Add. + * tests/reading_long_line.c: New file. + * .bzrignore: Add tests/reading_long_line. + * NEWS: Document this. + +Mon Jan 21 11:42:09 GMT 2013 Colin Watson + + * configure.ac (AC_HEADER_SYS_WAIT): Remove; superseded by Gnulib. + +Mon Jan 21 11:26:15 GMT 2013 Colin Watson + + Upgrade to Libtool 2.4.2-1.2 (from Debian). + +Mon Dec 24 02:23:37 GMT 2012 Colin Watson + + * lib/pipeline.c (pipeline_start): Remove redundant condition. + Mon Sep 17 22:54:12 BST 2012 Colin Watson * Version: 1.2.2. diff --git a/NEWS b/NEWS index b8e0cbc..7f36fb2 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,11 @@ +libpipeline 1.2.3 (24 April 2013) +================================= + +Don't read uninitialised memory when testing for the end of long lines (over +4096 bytes). + +Flush stdio before starting a sequence. + libpipeline 1.2.2 (17 September 2012) ===================================== diff --git a/config.h.in b/config.h.in index e304bd5..d901eb5 100644 --- a/config.h.in +++ b/config.h.in @@ -831,7 +831,7 @@ /* Define to 1 if you have the header file. */ #undef HAVE_SYS_TYPES_H -/* Define to 1 if you have that is POSIX.1 compatible. */ +/* Define to 1 if you have the header file. */ #undef HAVE_SYS_WAIT_H /* Define to 1 if you have the `tsearch' function. */ diff --git a/configure b/configure index 5b94b73..f171719 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for libpipeline 1.2.2. +# Generated by GNU Autoconf 2.69 for libpipeline 1.2.3. # # Report bugs to . # @@ -590,8 +590,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='libpipeline' PACKAGE_TARNAME='libpipeline' -PACKAGE_VERSION='1.2.2' -PACKAGE_STRING='libpipeline 1.2.2' +PACKAGE_VERSION='1.2.3' +PACKAGE_STRING='libpipeline 1.2.3' PACKAGE_BUGREPORT='cjwatson@debian.org' PACKAGE_URL='' @@ -1981,7 +1981,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures libpipeline 1.2.2 to adapt to many kinds of systems. +\`configure' configures libpipeline 1.2.3 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -2051,7 +2051,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of libpipeline 1.2.2:";; + short | recursive ) echo "Configuration of libpipeline 1.2.3:";; esac cat <<\_ACEOF @@ -2173,7 +2173,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -libpipeline configure 1.2.2 +libpipeline configure 1.2.3 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -2882,7 +2882,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by libpipeline $as_me 1.2.2, which was +It was created by libpipeline $as_me 1.2.3, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -3717,7 +3717,7 @@ fi # Define the identity of the package. PACKAGE='libpipeline' - VERSION='1.2.2' + VERSION='1.2.3' cat >>confdefs.h <<_ACEOF @@ -6188,7 +6188,8 @@ else ;; *) lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null` - if test -n "$lt_cv_sys_max_cmd_len"; then + if test -n "$lt_cv_sys_max_cmd_len" && \ + test undefined != "$lt_cv_sys_max_cmd_len"; then lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` else @@ -7724,7 +7725,14 @@ s390*-*linux*|s390*-*tpf*|sparc*-*linux*) LD="${LD-ld} -m elf_i386_fbsd" ;; x86_64-*linux*) - LD="${LD-ld} -m elf_i386" + case `/usr/bin/file conftest.o` in + *x86-64*) + LD="${LD-ld} -m elf32_x86_64" + ;; + *) + LD="${LD-ld} -m elf_i386" + ;; + esac ;; ppc64-*linux*|powerpc64-*linux*) LD="${LD-ld} -m elf32ppclinux" @@ -24237,47 +24245,6 @@ done -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sys/wait.h that is POSIX.1 compatible" >&5 -$as_echo_n "checking for sys/wait.h that is POSIX.1 compatible... " >&6; } -if ${ac_cv_header_sys_wait_h+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include -#include -#ifndef WEXITSTATUS -# define WEXITSTATUS(stat_val) ((unsigned int) (stat_val) >> 8) -#endif -#ifndef WIFEXITED -# define WIFEXITED(stat_val) (((stat_val) & 255) == 0) -#endif - -int -main () -{ - int s; - wait (&s); - s = WIFEXITED (s) ? WEXITSTATUS (s) : 1; - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_header_sys_wait_h=yes -else - ac_cv_header_sys_wait_h=no -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_sys_wait_h" >&5 -$as_echo "$ac_cv_header_sys_wait_h" >&6; } -if test $ac_cv_header_sys_wait_h = yes; then - -$as_echo "#define HAVE_SYS_WAIT_H 1" >>confdefs.h - -fi - for ac_header in fcntl.h do : ac_fn_c_check_header_mongrel "$LINENO" "fcntl.h" "ac_cv_header_fcntl_h" "$ac_includes_default" @@ -25393,7 +25360,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by libpipeline $as_me 1.2.2, which was +This file was extended by libpipeline $as_me 1.2.3, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -25459,7 +25426,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -libpipeline config.status 1.2.2 +libpipeline config.status 1.2.3 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/configure.ac b/configure.ac index 8e1731d..b40e82b 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ dnl Process this file with autoconf to produce a configure script. -# Copyright (C) 2010 Colin Watson. +# Copyright (C) 2010, 2011, 2012, 2013 Colin Watson. # # This file is part of libpipeline. # @@ -22,7 +22,7 @@ dnl Process this file with autoconf to produce a configure script. m4_pattern_forbid([^PIPELINE_]) # Initialise and check we're in the correct directory. -AC_INIT([libpipeline], [1.2.2], [cjwatson@debian.org]) +AC_INIT([libpipeline], [1.2.3], [cjwatson@debian.org]) AC_CONFIG_AUX_DIR([tools]) AM_INIT_AUTOMAKE([1.10 -Wall -Werror foreign]) AM_MAINTAINER_MODE @@ -59,7 +59,6 @@ AM_CONDITIONAL([RUN_TESTS], [test "x$run_tests" = xyes]) # Check for various header files and associated libraries. AC_ISC_POSIX gl_INIT -AC_HEADER_SYS_WAIT AC_CHECK_HEADERS([fcntl.h]) # Checks for structures and compiler characteristics. diff --git a/gnulib/m4/libtool.m4 b/gnulib/m4/libtool.m4 index 534d1cc..02b4bbe 100644 --- a/gnulib/m4/libtool.m4 +++ b/gnulib/m4/libtool.m4 @@ -1324,7 +1324,14 @@ s390*-*linux*|s390*-*tpf*|sparc*-*linux*) LD="${LD-ld} -m elf_i386_fbsd" ;; x86_64-*linux*) - LD="${LD-ld} -m elf_i386" + case `/usr/bin/file conftest.o` in + *x86-64*) + LD="${LD-ld} -m elf32_x86_64" + ;; + *) + LD="${LD-ld} -m elf_i386" + ;; + esac ;; ppc64-*linux*|powerpc64-*linux*) LD="${LD-ld} -m elf32ppclinux" @@ -1688,7 +1695,8 @@ AC_CACHE_VAL([lt_cv_sys_max_cmd_len], [dnl ;; *) lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null` - if test -n "$lt_cv_sys_max_cmd_len"; then + if test -n "$lt_cv_sys_max_cmd_len" && \ + test undefined != "$lt_cv_sys_max_cmd_len"; then lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` else diff --git a/lib/Makefile.am b/lib/Makefile.am index 9b5d27a..9407c2d 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -37,7 +37,7 @@ libpipeline_la_LIBADD = ../gnulib/lib/libgnu.la $(LTLIBOBJS) libpipeline_la_LDFLAGS = \ -export-symbols-regex '^(pipecmd|pipeline)_' \ - -version-info 3:2:2 + -version-info 3:3:2 pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = libpipeline.pc diff --git a/lib/Makefile.in b/lib/Makefile.in index d380f1a..17a28cc 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -993,7 +993,7 @@ include_HEADERS = pipeline.h libpipeline_la_LIBADD = ../gnulib/lib/libgnu.la $(LTLIBOBJS) libpipeline_la_LDFLAGS = \ -export-symbols-regex '^(pipecmd|pipeline)_' \ - -version-info 3:2:2 + -version-info 3:3:2 pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = libpipeline.pc diff --git a/lib/pipeline.c b/lib/pipeline.c index eb92e2f..0feb197 100644 --- a/lib/pipeline.c +++ b/lib/pipeline.c @@ -255,6 +255,7 @@ pipecmd *pipecmd_new_argstr (const char *argstr) * work when being executed directly. To work around this, * we just drop "exec" if it appears at the start of argstr. */ + free (arg); arg = argstr_get_word (&argstr); if (!arg) error (FATAL, 0, @@ -733,6 +734,11 @@ void pipecmd_exec (pipecmd *cmd) struct pipecmd_sequence *cmds = &cmd->u.sequence; struct sigaction sa; + /* Flush all pending output so that subprocesses + * don't inherit it. + */ + fflush (NULL); + /* pipeline_start will have blocked SIGCHLD. We like * it that way. Lose the parent's signal handler, * though. @@ -1413,7 +1419,7 @@ void pipeline_start (pipeline *p) p->outfd = pdes[0]; output_read = pdes[0]; output_write = pdes[1]; - } else if (i == p->ncommands - 1) { + } else { if (p->redirect_out == REDIRECT_FD) output_write = p->want_out; else if (p->redirect_out == REDIRECT_FILE_NAME) { @@ -1660,6 +1666,21 @@ int pipeline_wait_all (pipeline *p, int **statuses, int *n_statuses) if (active_pipelines[i] == p) active_pipelines[i] = NULL; + /* It isn't normally safe to compactify active_pipelines as we go, + * because it's used by a signal handler. However, if it's entirely + * empty, we can safely clean it up now. This prevents the table + * growing without bound, not to mention pacifying valgrind. + */ + for (i = 0; i < n_active_pipelines; ++i) + if (active_pipelines[i]) + break; + if (i == n_active_pipelines) { + n_active_pipelines = 0; + max_active_pipelines = 0; + free (active_pipelines); + active_pipelines = NULL; + } + if (statuses && n_statuses) { *statuses = xnmalloc (p->ncommands, sizeof **statuses); *n_statuses = p->ncommands; @@ -2147,7 +2168,7 @@ static const char *get_line (pipeline *p, size_t *outlen) if (!buffer || plen == 0) return NULL; - end = memchr (buffer + block * i, '\n', plen); + end = memchr (buffer + block * i, '\n', plen - block * i); if (!end && plen < block * (i + 1)) /* end of file, no newline found */ end = buffer + plen - 1; diff --git a/tests/Makefile.am b/tests/Makefile.am index 6f1b63a..0bf141f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -27,7 +27,8 @@ TESTS = \ exec \ inspect \ pump \ - redirect + redirect \ + reading_long_line check_PROGRAMS = $(TESTS) LIBS = ../gnulib/lib/libgnu.la $(LTLIBOBJS) $(top_builddir)/lib/libpipeline.la @@ -58,3 +59,6 @@ pump_LDADD = $(LIBS) @CHECK_LIBS@ redirect_SOURCES = redirect.c common.c common.h redirect_LDADD = $(LIBS) @CHECK_LIBS@ + +reading_long_line_SOURCES = reading_long_line.c common.c common.h +reading_long_line_LDADD = $(LIBS) @CHECK_LIBS@ diff --git a/tests/Makefile.in b/tests/Makefile.in index 69a4966..609fa9d 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -51,7 +51,7 @@ POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ TESTS = basic$(EXEEXT) argstr$(EXEEXT) exec$(EXEEXT) inspect$(EXEEXT) \ - pump$(EXEEXT) redirect$(EXEEXT) + pump$(EXEEXT) redirect$(EXEEXT) reading_long_line$(EXEEXT) check_PROGRAMS = $(am__EXEEXT_1) subdir = tests DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in @@ -147,7 +147,8 @@ CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = am__EXEEXT_1 = basic$(EXEEXT) argstr$(EXEEXT) exec$(EXEEXT) \ - inspect$(EXEEXT) pump$(EXEEXT) redirect$(EXEEXT) + inspect$(EXEEXT) pump$(EXEEXT) redirect$(EXEEXT) \ + reading_long_line$(EXEEXT) am_argstr_OBJECTS = argstr.$(OBJEXT) common.$(OBJEXT) argstr_OBJECTS = $(am_argstr_OBJECTS) argstr_DEPENDENCIES = $(LIBS) @@ -166,6 +167,10 @@ inspect_DEPENDENCIES = $(LIBS) am_pump_OBJECTS = pump.$(OBJEXT) common.$(OBJEXT) pump_OBJECTS = $(am_pump_OBJECTS) pump_DEPENDENCIES = $(LIBS) +am_reading_long_line_OBJECTS = reading_long_line.$(OBJEXT) \ + common.$(OBJEXT) +reading_long_line_OBJECTS = $(am_reading_long_line_OBJECTS) +reading_long_line_DEPENDENCIES = $(LIBS) am_redirect_OBJECTS = redirect.$(OBJEXT) common.$(OBJEXT) redirect_OBJECTS = $(am_redirect_OBJECTS) redirect_DEPENDENCIES = $(LIBS) @@ -196,9 +201,11 @@ AM_V_GEN = $(am__v_GEN_@AM_V@) am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) am__v_GEN_0 = @echo " GEN " $@; SOURCES = $(argstr_SOURCES) $(basic_SOURCES) $(exec_SOURCES) \ - $(inspect_SOURCES) $(pump_SOURCES) $(redirect_SOURCES) + $(inspect_SOURCES) $(pump_SOURCES) \ + $(reading_long_line_SOURCES) $(redirect_SOURCES) DIST_SOURCES = $(argstr_SOURCES) $(basic_SOURCES) $(exec_SOURCES) \ - $(inspect_SOURCES) $(pump_SOURCES) $(redirect_SOURCES) + $(inspect_SOURCES) $(pump_SOURCES) \ + $(reading_long_line_SOURCES) $(redirect_SOURCES) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ @@ -979,6 +986,8 @@ pump_SOURCES = pump.c common.c common.h pump_LDADD = $(LIBS) @CHECK_LIBS@ redirect_SOURCES = redirect.c common.c common.h redirect_LDADD = $(LIBS) @CHECK_LIBS@ +reading_long_line_SOURCES = reading_long_line.c common.c common.h +reading_long_line_LDADD = $(LIBS) @CHECK_LIBS@ all: all-am .SUFFIXES: @@ -1037,6 +1046,9 @@ inspect$(EXEEXT): $(inspect_OBJECTS) $(inspect_DEPENDENCIES) $(EXTRA_inspect_DEP pump$(EXEEXT): $(pump_OBJECTS) $(pump_DEPENDENCIES) $(EXTRA_pump_DEPENDENCIES) @rm -f pump$(EXEEXT) $(AM_V_CCLD)$(LINK) $(pump_OBJECTS) $(pump_LDADD) $(LIBS) +reading_long_line$(EXEEXT): $(reading_long_line_OBJECTS) $(reading_long_line_DEPENDENCIES) $(EXTRA_reading_long_line_DEPENDENCIES) + @rm -f reading_long_line$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(reading_long_line_OBJECTS) $(reading_long_line_LDADD) $(LIBS) redirect$(EXEEXT): $(redirect_OBJECTS) $(redirect_DEPENDENCIES) $(EXTRA_redirect_DEPENDENCIES) @rm -f redirect$(EXEEXT) $(AM_V_CCLD)$(LINK) $(redirect_OBJECTS) $(redirect_LDADD) $(LIBS) @@ -1053,6 +1065,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/exec.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/inspect.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pump.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/reading_long_line.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/redirect.Po@am__quote@ .c.o: diff --git a/tests/argstr.c b/tests/argstr.c index b9ccac7..3a15981 100644 --- a/tests/argstr.c +++ b/tests/argstr.c @@ -62,6 +62,7 @@ START_TEST (test_argstr_exec) fail_unless (cmd->u.process.argc == 2); fail_unless (!strcmp (cmd->u.process.argv[0], "foo")); fail_unless (!strcmp (cmd->u.process.argv[1], "bar")); + pipecmd_free (cmd); } END_TEST diff --git a/tests/basic.c b/tests/basic.c index d0dd633..156c756 100644 --- a/tests/basic.c +++ b/tests/basic.c @@ -101,6 +101,7 @@ START_TEST (test_basic_wait_all) fail_unless (statuses[1] == 3 * 256); fail_unless (statuses[2] == 0); pipeline_free (p); + free (statuses); } END_TEST @@ -200,6 +201,8 @@ START_TEST (test_basic_clearenv) "clearenv+setenv+dup returned second line '%s', expected 'bar\n'", line2); pipeline_wait (p2); + pipeline_free (p2); + pipeline_free (p); } END_TEST diff --git a/tests/exec.c b/tests/exec.c index 4516a30..cdef9a3 100644 --- a/tests/exec.c +++ b/tests/exec.c @@ -71,6 +71,8 @@ START_TEST (test_exec_process) fail_unless (WEXITSTATUS (status) == i); else fail_if (WEXITSTATUS (status) == 0); + + pipecmd_free (cmd); } } END_TEST @@ -109,6 +111,8 @@ START_TEST (test_exec_function) fail_unless (WIFEXITED (status)); fail_unless (WEXITSTATUS (status) == i); + + pipecmd_free (cmd); } } END_TEST diff --git a/tests/reading_long_line.c b/tests/reading_long_line.c new file mode 100644 index 0000000..c6b68b9 --- /dev/null +++ b/tests/reading_long_line.c @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2013 Peter Schiffer. + * + * This file is part of libpipeline. + * + * libpipeline is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * libpipeline is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with libpipeline; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 + * USA. + */ + +/* + * Unit test for bug: https://bugzilla.redhat.com/show_bug.cgi?id=876108 + */ + +#include +#include +#include "xvasprintf.h" + +#include "common.h" + +/* Must be 8194 or bigger */ +#define RANDOM_STR_LEN 9000 + +START_TEST (test_reading_longline) +{ + /* Generate long random string */ + static const char *alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz"; + char random_string[RANDOM_STR_LEN] = ""; + unsigned i; + + for (i = 0; i < RANDOM_STR_LEN - 2; i++) { + random_string[i] = alphanum[rand () % (strlen (alphanum) - 1)]; + } + random_string[RANDOM_STR_LEN - 1] = '\0'; + + /* Write the random string to file */ + char *testfile = xasprintf ("%s/test", temp_dir); + FILE *tfd = fopen (testfile, "w"); + if (!tfd) { + fail ("fopen failed: %s", strerror (errno)); + return; + } + fprintf (tfd, "%s\n", random_string); + fclose (tfd); + + char *expected_output = xasprintf ("%s\n", random_string); + + pipeline *p; + const char *line; + char *read_result = NULL, *temp = NULL; + + /* File must be read twice to reproduce the bug */ + p = pipeline_new (); + pipeline_want_infile (p, testfile); + pipeline_want_out (p, -1); + pipeline_start (p); + while ((line = pipeline_readline (p)) != NULL){ + if (read_result) { + temp = read_result; + read_result = xasprintf ("%s%s", read_result, line); + free (temp); + } else { + read_result = xasprintf ("%s", line); + } + } + pipeline_free (p); + fail_unless (!strcmp (read_result, expected_output), + "Returned string doesn't match the input."); + + free (read_result); + read_result = NULL; + + p = pipeline_new (); + pipeline_want_infile (p, testfile); + pipeline_want_out (p, -1); + pipeline_start (p); + while ((line = pipeline_readline (p)) != NULL){ + if (read_result) { + temp = read_result; + read_result = xasprintf ("%s%s", read_result, line); + free (temp); + } else { + read_result = xasprintf ("%s", line); + } + } + pipeline_free (p); + fail_unless (!strcmp (read_result, expected_output), + "Returned string doesn't match the input."); + + free (testfile); + free (expected_output); + free (read_result); +} +END_TEST + +Suite *reading_long_line_suite (void) +{ + Suite *s = suite_create ("Reading long line"); + + TEST_CASE_WITH_FIXTURE (s, reading, longline, + temp_dir_setup, temp_dir_teardown); + + return s; +} + +MAIN (reading_long_line) diff --git a/tests/redirect.c b/tests/redirect.c index 56d541b..3cc0be7 100644 --- a/tests/redirect.c +++ b/tests/redirect.c @@ -56,6 +56,9 @@ START_TEST (test_redirect_files) fclose (fh); unlink (template); + + pipeline_free (p); + free (template); } END_TEST diff --git a/tools/ltmain.sh b/tools/ltmain.sh index 33f642a..499e473 100644 --- a/tools/ltmain.sh +++ b/tools/ltmain.sh @@ -70,7 +70,7 @@ # compiler: $LTCC # compiler flags: $LTCFLAGS # linker: $LD (gnu? $with_gnu_ld) -# $progname: (GNU libtool) 2.4.2 Debian-2.4.2-1.1 +# $progname: (GNU libtool) 2.4.2 Debian-2.4.2-1.2 # automake: $automake_version # autoconf: $autoconf_version # @@ -80,7 +80,7 @@ PROGRAM=libtool PACKAGE=libtool -VERSION="2.4.2 Debian-2.4.2-1.1" +VERSION="2.4.2 Debian-2.4.2-1.2" TIMESTAMP="" package_revision=1.3337