aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro F. Giffuni <pfg@FreeBSD.org>2017-01-02 17:12:14 +0000
committerPedro F. Giffuni <pfg@FreeBSD.org>2017-01-02 17:12:14 +0000
commitad8469feec8a84469d38b4a1237fd39abea16198 (patch)
treee1112d2d30e11fef4c8b9ee5947f3312df5d6717
parent53d2e5b73e929fa982911eadae6e8514a2c946be (diff)
downloadsrc-ad8469feec8a84469d38b4a1237fd39abea16198.tar.gz
src-ad8469feec8a84469d38b4a1237fd39abea16198.zip
patch(1): extend the maximum length of a line from USHRT_MAX to UINT_MAX.
We can handle such "big data" without much trouble. Try to do a better job at detecting the rejection cause while here. MFC after: 2 weeks
Notes
Notes: svn path=/head/; revision=311106
-rw-r--r--usr.bin/patch/patch.c14
-rw-r--r--usr.bin/patch/pch.c10
-rw-r--r--usr.bin/patch/pch.h2
3 files changed, 12 insertions, 14 deletions
diff --git a/usr.bin/patch/patch.c b/usr.bin/patch/patch.c
index 1bdbcfb5b84b..71c1e45538b2 100644
--- a/usr.bin/patch/patch.c
+++ b/usr.bin/patch/patch.c
@@ -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 fuzz)
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);
diff --git a/usr.bin/patch/pch.c b/usr.bin/patch/pch.c
index e12e833d54ef..69d5f26f2090 100644
--- a/usr.bin/patch/pch.c
+++ b/usr.bin/patch/pch.c
@@ -56,7 +56,7 @@ static LINENUM p_max; /* max allowed value of p_end */
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];
diff --git a/usr.bin/patch/pch.h b/usr.bin/patch/pch.h
index da7a08d4008b..754b9c1b91eb 100644
--- a/usr.bin/patch/pch.h
+++ b/usr.bin/patch/pch.h
@@ -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);