From owner-svn-src-head@freebsd.org Mon Jan 2 17:27:29 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 44860C9BF4B; Mon, 2 Jan 2017 17:27:29 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E18E11326; Mon, 2 Jan 2017 17:27:28 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id v02HRMcB063419 (version=TLSv1 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Mon, 2 Jan 2017 19:27:22 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua v02HRMcB063419 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id v02HRMn3063418; Mon, 2 Jan 2017 19:27:22 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 2 Jan 2017 19:27:22 +0200 From: Konstantin Belousov To: "Pedro F. Giffuni" Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r311106 - head/usr.bin/patch Message-ID: <20170102172722.GK1923@kib.kiev.ua> References: <201701021712.v02HCEsx098719@repo.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201701021712.v02HCEsx098719@repo.freebsd.org> User-Agent: Mutt/1.7.2 (2016-11-26) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tom.home X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Jan 2017 17:27:29 -0000 On Mon, Jan 02, 2017 at 05:12:14PM +0000, Pedro F. Giffuni wrote: > Author: pfg > Date: Mon Jan 2 17:12:14 2017 > New Revision: 311106 > URL: https://svnweb.freebsd.org/changeset/base/311106 > > Log: > patch(1): extend the maximum length of a line from USHRT_MAX to UINT_MAX. > > We can handle such "big data" without much trouble. No, we don't, at least not on arbitrary platform. UINT_MAX allocations on 32bit arches or even in 32bit processes running on 64bit hosts cannot succeed. As result, the use of strnlen() becomes completely non-sensical. BTW, why is it used there at all ? > Try to do a better job at detecting the rejection cause while here. > > MFC after: 2 weeks > > Modified: > head/usr.bin/patch/patch.c > head/usr.bin/patch/pch.c > head/usr.bin/patch/pch.h > > Modified: head/usr.bin/patch/patch.c > ============================================================================== > --- head/usr.bin/patch/patch.c Mon Jan 2 16:58:55 2017 (r311105) > +++ head/usr.bin/patch/patch.c Mon Jan 2 17:12:14 2017 (r311106) > @@ -749,15 +749,13 @@ rej_line(int ch, LINENUM i) > size_t len; > const char *line = pfetch(i); > > - len = strnlen(line, USHRT_MAX); > + len = strnlen(line, UINT_MAX); > > fprintf(rejfp, "%c%s", ch, line); > - if (len == 0 || line[len-1] != '\n') { > - if (len >= USHRT_MAX) > - fprintf(rejfp, "\n\\ Line too long\n"); > - else > - fprintf(rejfp, "\n\\ No newline at end of line\n"); > - } > + if (len == 0 || line[len-1] != '\n') > + fprintf(rejfp, "\n\\ No newline at end of line\n"); > + else if (len >= UINT_MAX) > + fprintf(rejfp, "\n\\ Line too long\n"); > } > > static void > @@ -1024,7 +1022,7 @@ patch_match(LINENUM base, LINENUM offset > LINENUM pat_lines = pch_ptrn_lines() - fuzz; > const char *ilineptr; > const char *plineptr; > - unsigned short plinelen; > + u_int plinelen; > > for (iline = base + offset + fuzz; pline <= pat_lines; pline++, iline++) { > ilineptr = ifetch(iline, offset >= 0); > > Modified: head/usr.bin/patch/pch.c > ============================================================================== > --- head/usr.bin/patch/pch.c Mon Jan 2 16:58:55 2017 (r311105) > +++ head/usr.bin/patch/pch.c Mon Jan 2 17:12:14 2017 (r311106) > @@ -56,7 +56,7 @@ static LINENUM p_max; /* max allowed va > static LINENUM p_context = 3; /* # of context lines */ > static LINENUM p_input_line = 0; /* current line # from patch file */ > static char **p_line = NULL;/* the text of the hunk */ > -static unsigned short *p_len = NULL; /* length of each line */ > +static u_int *p_len = NULL; /* length of each line */ > static char *p_char = NULL; /* +, -, and ! */ > static int hunkmax = INITHUNKMAX; /* size of above arrays to begin with */ > static int p_indent; /* indent to patch */ > @@ -136,7 +136,7 @@ set_hunkmax(void) > if (p_line == NULL) > p_line = malloc(hunkmax * sizeof(char *)); > if (p_len == NULL) > - p_len = malloc(hunkmax * sizeof(unsigned short)); > + p_len = malloc(hunkmax * sizeof(u_int)); > if (p_char == NULL) > p_char = malloc(hunkmax * sizeof(char)); > } > @@ -153,7 +153,7 @@ grow_hunkmax(void) > fatal("Internal memory allocation error\n"); > > p_line = reallocf(p_line, new_hunkmax * sizeof(char *)); > - p_len = reallocf(p_len, new_hunkmax * sizeof(unsigned short)); > + p_len = reallocf(p_len, new_hunkmax * sizeof(u_int)); > p_char = reallocf(p_char, new_hunkmax * sizeof(char)); > > if (p_line != NULL && p_len != NULL && p_char != NULL) { > @@ -1210,7 +1210,7 @@ bool > pch_swap(void) > { > char **tp_line; /* the text of the hunk */ > - unsigned short *tp_len;/* length of each line */ > + u_int *tp_len; /* length of each line */ > char *tp_char; /* +, -, and ! */ > LINENUM i; > LINENUM n; > @@ -1367,7 +1367,7 @@ pch_context(void) > /* > * Return the length of a particular patch line. > */ > -unsigned short > +u_int > pch_line_len(LINENUM line) > { > return p_len[line]; > > Modified: head/usr.bin/patch/pch.h > ============================================================================== > --- head/usr.bin/patch/pch.h Mon Jan 2 16:58:55 2017 (r311105) > +++ head/usr.bin/patch/pch.h Mon Jan 2 17:12:14 2017 (r311106) > @@ -44,7 +44,7 @@ bool there_is_another_patch(void); > bool another_hunk(void); > bool pch_swap(void); > char *pfetch(LINENUM); > -unsigned short pch_line_len(LINENUM); > +u_int pch_line_len(LINENUM); > LINENUM pch_first(void); > LINENUM pch_ptrn_lines(void); > LINENUM pch_newfirst(void);