summaryrefslogtreecommitdiffstats
path: root/src/xxd/xxd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/xxd/xxd.c')
-rw-r--r--src/xxd/xxd.c44
1 files changed, 39 insertions, 5 deletions
diff --git a/src/xxd/xxd.c b/src/xxd/xxd.c
index 26f8d83..cf8b4ea 100644
--- a/src/xxd/xxd.c
+++ b/src/xxd/xxd.c
@@ -58,6 +58,10 @@
* 20.06.2022 Permit setting the variable names used by -i by David Gow
* 31.08.2023 -R never/auto/always prints colored output
* 06.10.2023 enable -r -b to reverse bit dumps
+ * 12.01.2024 disable auto-conversion for z/OS (MVS)
+ * 17.01.2024 use size_t instead of usigned int for code-generation (-i), #13876
+ * 25.01.2024 revert the previous patch (size_t instead of unsigned int)
+ * 10.02.2024 fix buffer-overflow when writing color output to buffer, #14003
*
* (c) 1990-1998 by Juergen Weigert (jnweiger@gmail.com)
*
@@ -138,7 +142,7 @@ extern void perror __P((char *));
# endif
#endif
-char version[] = "xxd 2023-10-25 by Juergen Weigert et al.";
+char version[] = "xxd 2024-02-10 by Juergen Weigert et al.";
#ifdef WIN32
char osver[] = " (Win32)";
#else
@@ -197,7 +201,33 @@ char osver[] = "";
#define TRY_SEEK /* attempt to use lseek, or skip forward by reading */
#define COLS 256 /* change here, if you ever need more columns */
-#define LLEN ((2*(int)sizeof(unsigned long)) + 4 + (9*COLS-1) + COLS + 2)
+
+/*
+ * LLEN is the maximum length of a line; other than the visible characters
+ * we need to consider also the escape color sequence prologue/epilogue ,
+ * (11 bytes for each character). The most larger format is the default one:
+ * addr + 1 word for each col/2 + 1 char for each col
+ *
+ * addr 1st group 2nd group
+ * +-------+ +-----------------+ +------+
+ * 01234567: 1234 5678 9abc def0 12345678
+ *
+ * - addr: typically 012345678: -> from 10 up to 18 bytes (including trailing
+ * space)
+ * - 1st group: 1234 5678 9abc ... -> each byte may be colored, so add 11
+ * for each byte
+ * - space -> 1 byte
+ * - 2nd group: 12345678 -> each char may be colore so add 11
+ * for each byte
+ * - new line -> 1 byte
+ * - zero (end line) -> 1 byte
+ */
+#define LLEN (2*(int)sizeof(unsigned long) + 2 + /* addr + ": " */ \
+ (11 * 2 + 4 + 1) * (COLS / 2) + /* 1st group */ \
+ 1 + /* space */ \
+ (1 + 11) * COLS + /* 2nd group */ \
+ 1 + /* new line */ \
+ 1) /* zero */
char hexxa[] = "0123456789abcdef0123456789ABCDEF", *hexx = hexxa;
@@ -587,7 +617,7 @@ begin_coloring_char (char *l, int *c, int e, int ebcdic)
}
else /* ASCII */
{
- #ifdef __MVS__
+ #if defined(__MVS__) && __CHARSET_LIB == 0
if (e >= 64)
l[(*c)++] = COLOR_GREEN;
#else
@@ -905,6 +935,10 @@ main(int argc, char *argv[])
}
rewind(fpo);
}
+#ifdef __MVS__
+ // Disable auto-conversion on input file descriptors
+ __disableautocvt(fileno(fp));
+#endif
if (revert)
switch (hextype)
@@ -1066,7 +1100,7 @@ main(int argc, char *argv[])
COLOR_PROLOGUE
begin_coloring_char(l,&c,e,ebcdic);
-#ifdef __MVS__
+#if defined(__MVS__) && __CHARSET_LIB == 0
if (e >= 64)
l[c++] = e;
else
@@ -1094,7 +1128,7 @@ main(int argc, char *argv[])
c += addrlen + 3 + p;
l[c++] =
-#ifdef __MVS__
+#if defined(__MVS__) && __CHARSET_LIB == 0
(e >= 64)
#else
(e > 31 && e < 127)