2023-02-15 18:53:09 +08:00
|
|
|
/* $NetBSD: print-ascii.c,v 1.1 1999/09/30 14:49:12 sjg Exp $ */
|
1999-12-22 23:44:09 +08:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Alan Barrett and Simon J. Gerraty.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2016-08-14 21:42:19 +08:00
|
|
|
/* \summary: ASCII packet dump printer */
|
|
|
|
|
2018-01-22 04:27:08 +08:00
|
|
|
#include <config.h>
|
1999-12-22 23:44:09 +08:00
|
|
|
|
2018-01-20 22:59:49 +08:00
|
|
|
#include "netdissect-stdinc.h"
|
2019-09-02 07:11:32 +08:00
|
|
|
|
1999-12-22 23:44:09 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2019-09-02 07:11:32 +08:00
|
|
|
#include "netdissect-ctype.h"
|
|
|
|
|
2015-09-06 05:35:58 +08:00
|
|
|
#include "netdissect.h"
|
2017-12-05 05:45:01 +08:00
|
|
|
#include "extract.h"
|
1999-12-22 23:44:09 +08:00
|
|
|
|
2002-04-24 14:55:54 +08:00
|
|
|
#define ASCII_LINELENGTH 300
|
1999-12-22 23:44:09 +08:00
|
|
|
#define HEXDUMP_BYTES_PER_LINE 16
|
|
|
|
#define HEXDUMP_SHORTS_PER_LINE (HEXDUMP_BYTES_PER_LINE / 2)
|
|
|
|
#define HEXDUMP_HEXSTUFF_PER_SHORT 5 /* 4 hex digits and a space */
|
|
|
|
#define HEXDUMP_HEXSTUFF_PER_LINE \
|
|
|
|
(HEXDUMP_HEXSTUFF_PER_SHORT * HEXDUMP_SHORTS_PER_LINE)
|
2002-06-12 01:08:37 +08:00
|
|
|
|
1999-12-22 23:44:09 +08:00
|
|
|
void
|
2014-04-03 20:02:07 +08:00
|
|
|
ascii_print(netdissect_options *ndo,
|
2014-04-03 23:56:07 +08:00
|
|
|
const u_char *cp, u_int length)
|
2005-07-07 04:53:30 +08:00
|
|
|
{
|
2014-10-23 15:06:32 +08:00
|
|
|
u_int caplength;
|
2017-12-14 02:17:47 +08:00
|
|
|
u_char s;
|
ASCII/hex: Use nd_trunc_longjmp() in truncation cases
In functions ascii_print(), hex_and_ascii_print_with_offset() and
hex_print_with_offset().
Therefore indirectly for the functions hex_and_ascii_print(), hex_print()
and ndo_default_print().
Even if hex_and_ascii_print(), hex_print() and ascii_print() are used in
print.c after the setjmp() block with the calls:
1) hex_and_ascii_print(ndo, "\n\t", sp, h->caplen);
2) hex_and_ascii_print(ndo, "\n\t", sp + hdrlen, h->caplen - hdrlen);
3) hex_print(ndo, "\n\t", sp, h->caplen);
4) hex_print(ndo, "\n\t", sp + hdrlen, h->caplen - hdrlen);
5) ascii_print(ndo, sp, h->caplen);
6) ascii_print(ndo, sp + hdrlen, h->caplen - hdrlen);
sp and h->caplen are unmodified, ndo->ndo_snapend was restored.
1), 3) and 5) the length to print is caplen => no truncation can occur.
2), 4) and 6) the length to print is (caplen - hdrlen) after a shift of
hdrlen => no truncation can occur.
Moreover:
Update the output of three tests accordingly.
Remove an useless comment.
Fix indentation.
2021-03-27 23:14:27 +08:00
|
|
|
int truncated = FALSE;
|
2005-07-07 04:53:30 +08:00
|
|
|
|
2018-03-14 23:54:17 +08:00
|
|
|
ndo->ndo_protocol = "ascii";
|
2023-06-06 01:50:11 +08:00
|
|
|
caplength = ND_BYTES_AVAILABLE_AFTER(cp);
|
ASCII/hex: Use nd_trunc_longjmp() in truncation cases
In functions ascii_print(), hex_and_ascii_print_with_offset() and
hex_print_with_offset().
Therefore indirectly for the functions hex_and_ascii_print(), hex_print()
and ndo_default_print().
Even if hex_and_ascii_print(), hex_print() and ascii_print() are used in
print.c after the setjmp() block with the calls:
1) hex_and_ascii_print(ndo, "\n\t", sp, h->caplen);
2) hex_and_ascii_print(ndo, "\n\t", sp + hdrlen, h->caplen - hdrlen);
3) hex_print(ndo, "\n\t", sp, h->caplen);
4) hex_print(ndo, "\n\t", sp + hdrlen, h->caplen - hdrlen);
5) ascii_print(ndo, sp, h->caplen);
6) ascii_print(ndo, sp + hdrlen, h->caplen - hdrlen);
sp and h->caplen are unmodified, ndo->ndo_snapend was restored.
1), 3) and 5) the length to print is caplen => no truncation can occur.
2), 4) and 6) the length to print is (caplen - hdrlen) after a shift of
hdrlen => no truncation can occur.
Moreover:
Update the output of three tests accordingly.
Remove an useless comment.
Fix indentation.
2021-03-27 23:14:27 +08:00
|
|
|
if (length > caplength) {
|
2014-10-23 15:06:32 +08:00
|
|
|
length = caplength;
|
ASCII/hex: Use nd_trunc_longjmp() in truncation cases
In functions ascii_print(), hex_and_ascii_print_with_offset() and
hex_print_with_offset().
Therefore indirectly for the functions hex_and_ascii_print(), hex_print()
and ndo_default_print().
Even if hex_and_ascii_print(), hex_print() and ascii_print() are used in
print.c after the setjmp() block with the calls:
1) hex_and_ascii_print(ndo, "\n\t", sp, h->caplen);
2) hex_and_ascii_print(ndo, "\n\t", sp + hdrlen, h->caplen - hdrlen);
3) hex_print(ndo, "\n\t", sp, h->caplen);
4) hex_print(ndo, "\n\t", sp + hdrlen, h->caplen - hdrlen);
5) ascii_print(ndo, sp, h->caplen);
6) ascii_print(ndo, sp + hdrlen, h->caplen - hdrlen);
sp and h->caplen are unmodified, ndo->ndo_snapend was restored.
1), 3) and 5) the length to print is caplen => no truncation can occur.
2), 4) and 6) the length to print is (caplen - hdrlen) after a shift of
hdrlen => no truncation can occur.
Moreover:
Update the output of three tests accordingly.
Remove an useless comment.
Fix indentation.
2021-03-27 23:14:27 +08:00
|
|
|
truncated = TRUE;
|
|
|
|
}
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n");
|
2024-02-27 02:41:37 +08:00
|
|
|
while (length != 0) {
|
2018-06-16 23:23:21 +08:00
|
|
|
s = GET_U_1(cp);
|
2017-12-09 16:26:39 +08:00
|
|
|
cp++;
|
2005-07-07 04:53:30 +08:00
|
|
|
length--;
|
2014-02-03 16:01:56 +08:00
|
|
|
if (s == '\r') {
|
|
|
|
/*
|
|
|
|
* Don't print CRs at the end of the line; they
|
|
|
|
* don't belong at the ends of lines on UN*X,
|
|
|
|
* and the standard I/O library will give us one
|
|
|
|
* on Windows so we don't need to print one
|
|
|
|
* ourselves.
|
|
|
|
*
|
|
|
|
* In the middle of a line, just print a '.'.
|
|
|
|
*/
|
2018-06-16 23:23:21 +08:00
|
|
|
if (length > 1 && GET_U_1(cp) != '\n')
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(".");
|
2014-02-03 16:01:56 +08:00
|
|
|
} else {
|
2019-09-02 07:11:32 +08:00
|
|
|
if (!ND_ASCII_ISGRAPH(s) &&
|
2014-02-03 16:01:56 +08:00
|
|
|
(s != '\t' && s != ' ' && s != '\n'))
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(".");
|
2014-02-03 16:01:56 +08:00
|
|
|
else
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("%c", s);
|
2014-02-03 16:01:56 +08:00
|
|
|
}
|
2005-07-07 04:53:30 +08:00
|
|
|
}
|
ASCII/hex: Use nd_trunc_longjmp() in truncation cases
In functions ascii_print(), hex_and_ascii_print_with_offset() and
hex_print_with_offset().
Therefore indirectly for the functions hex_and_ascii_print(), hex_print()
and ndo_default_print().
Even if hex_and_ascii_print(), hex_print() and ascii_print() are used in
print.c after the setjmp() block with the calls:
1) hex_and_ascii_print(ndo, "\n\t", sp, h->caplen);
2) hex_and_ascii_print(ndo, "\n\t", sp + hdrlen, h->caplen - hdrlen);
3) hex_print(ndo, "\n\t", sp, h->caplen);
4) hex_print(ndo, "\n\t", sp + hdrlen, h->caplen - hdrlen);
5) ascii_print(ndo, sp, h->caplen);
6) ascii_print(ndo, sp + hdrlen, h->caplen - hdrlen);
sp and h->caplen are unmodified, ndo->ndo_snapend was restored.
1), 3) and 5) the length to print is caplen => no truncation can occur.
2), 4) and 6) the length to print is (caplen - hdrlen) after a shift of
hdrlen => no truncation can occur.
Moreover:
Update the output of three tests accordingly.
Remove an useless comment.
Fix indentation.
2021-03-27 23:14:27 +08:00
|
|
|
if (truncated)
|
|
|
|
nd_trunc_longjmp(ndo);
|
2005-07-07 04:53:30 +08:00
|
|
|
}
|
|
|
|
|
2018-05-10 22:48:48 +08:00
|
|
|
static void
|
2021-03-28 20:44:35 +08:00
|
|
|
hex_and_ascii_print_with_offset(netdissect_options *ndo, const char *indent,
|
2022-03-04 17:23:59 +08:00
|
|
|
const u_char *cp, u_int length, u_int offset)
|
1999-12-22 23:44:09 +08:00
|
|
|
{
|
2014-10-23 15:06:32 +08:00
|
|
|
u_int caplength;
|
2017-12-14 02:17:47 +08:00
|
|
|
u_int i;
|
2018-12-11 13:23:21 +08:00
|
|
|
u_int s1, s2;
|
|
|
|
u_int nshorts;
|
ASCII/hex: Use nd_trunc_longjmp() in truncation cases
In functions ascii_print(), hex_and_ascii_print_with_offset() and
hex_print_with_offset().
Therefore indirectly for the functions hex_and_ascii_print(), hex_print()
and ndo_default_print().
Even if hex_and_ascii_print(), hex_print() and ascii_print() are used in
print.c after the setjmp() block with the calls:
1) hex_and_ascii_print(ndo, "\n\t", sp, h->caplen);
2) hex_and_ascii_print(ndo, "\n\t", sp + hdrlen, h->caplen - hdrlen);
3) hex_print(ndo, "\n\t", sp, h->caplen);
4) hex_print(ndo, "\n\t", sp + hdrlen, h->caplen - hdrlen);
5) ascii_print(ndo, sp, h->caplen);
6) ascii_print(ndo, sp + hdrlen, h->caplen - hdrlen);
sp and h->caplen are unmodified, ndo->ndo_snapend was restored.
1), 3) and 5) the length to print is caplen => no truncation can occur.
2), 4) and 6) the length to print is (caplen - hdrlen) after a shift of
hdrlen => no truncation can occur.
Moreover:
Update the output of three tests accordingly.
Remove an useless comment.
Fix indentation.
2021-03-27 23:14:27 +08:00
|
|
|
int truncated = FALSE;
|
1999-12-22 23:44:09 +08:00
|
|
|
char hexstuff[HEXDUMP_SHORTS_PER_LINE*HEXDUMP_HEXSTUFF_PER_SHORT+1], *hsp;
|
2002-04-24 14:55:54 +08:00
|
|
|
char asciistuff[ASCII_LINELENGTH+1], *asp;
|
1999-12-22 23:44:09 +08:00
|
|
|
|
2023-06-06 01:50:11 +08:00
|
|
|
caplength = ND_BYTES_AVAILABLE_AFTER(cp);
|
ASCII/hex: Use nd_trunc_longjmp() in truncation cases
In functions ascii_print(), hex_and_ascii_print_with_offset() and
hex_print_with_offset().
Therefore indirectly for the functions hex_and_ascii_print(), hex_print()
and ndo_default_print().
Even if hex_and_ascii_print(), hex_print() and ascii_print() are used in
print.c after the setjmp() block with the calls:
1) hex_and_ascii_print(ndo, "\n\t", sp, h->caplen);
2) hex_and_ascii_print(ndo, "\n\t", sp + hdrlen, h->caplen - hdrlen);
3) hex_print(ndo, "\n\t", sp, h->caplen);
4) hex_print(ndo, "\n\t", sp + hdrlen, h->caplen - hdrlen);
5) ascii_print(ndo, sp, h->caplen);
6) ascii_print(ndo, sp + hdrlen, h->caplen - hdrlen);
sp and h->caplen are unmodified, ndo->ndo_snapend was restored.
1), 3) and 5) the length to print is caplen => no truncation can occur.
2), 4) and 6) the length to print is (caplen - hdrlen) after a shift of
hdrlen => no truncation can occur.
Moreover:
Update the output of three tests accordingly.
Remove an useless comment.
Fix indentation.
2021-03-27 23:14:27 +08:00
|
|
|
if (length > caplength) {
|
2014-10-23 15:06:32 +08:00
|
|
|
length = caplength;
|
ASCII/hex: Use nd_trunc_longjmp() in truncation cases
In functions ascii_print(), hex_and_ascii_print_with_offset() and
hex_print_with_offset().
Therefore indirectly for the functions hex_and_ascii_print(), hex_print()
and ndo_default_print().
Even if hex_and_ascii_print(), hex_print() and ascii_print() are used in
print.c after the setjmp() block with the calls:
1) hex_and_ascii_print(ndo, "\n\t", sp, h->caplen);
2) hex_and_ascii_print(ndo, "\n\t", sp + hdrlen, h->caplen - hdrlen);
3) hex_print(ndo, "\n\t", sp, h->caplen);
4) hex_print(ndo, "\n\t", sp + hdrlen, h->caplen - hdrlen);
5) ascii_print(ndo, sp, h->caplen);
6) ascii_print(ndo, sp + hdrlen, h->caplen - hdrlen);
sp and h->caplen are unmodified, ndo->ndo_snapend was restored.
1), 3) and 5) the length to print is caplen => no truncation can occur.
2), 4) and 6) the length to print is (caplen - hdrlen) after a shift of
hdrlen => no truncation can occur.
Moreover:
Update the output of three tests accordingly.
Remove an useless comment.
Fix indentation.
2021-03-27 23:14:27 +08:00
|
|
|
truncated = TRUE;
|
|
|
|
}
|
1999-12-22 23:44:09 +08:00
|
|
|
nshorts = length / sizeof(u_short);
|
|
|
|
i = 0;
|
|
|
|
hsp = hexstuff; asp = asciistuff;
|
2018-12-11 13:23:21 +08:00
|
|
|
while (nshorts != 0) {
|
2018-06-16 23:23:21 +08:00
|
|
|
s1 = GET_U_1(cp);
|
2018-01-28 21:18:51 +08:00
|
|
|
cp++;
|
2018-06-16 23:23:21 +08:00
|
|
|
s2 = GET_U_1(cp);
|
2018-01-28 21:18:51 +08:00
|
|
|
cp++;
|
2019-08-09 13:39:54 +08:00
|
|
|
(void)snprintf(hsp, sizeof(hexstuff) - (hsp - hexstuff),
|
2005-07-07 04:53:30 +08:00
|
|
|
" %02x%02x", s1, s2);
|
|
|
|
hsp += HEXDUMP_HEXSTUFF_PER_SHORT;
|
2019-09-02 07:11:32 +08:00
|
|
|
*(asp++) = (char)(ND_ASCII_ISGRAPH(s1) ? s1 : '.');
|
|
|
|
*(asp++) = (char)(ND_ASCII_ISGRAPH(s2) ? s2 : '.');
|
2005-07-07 04:53:30 +08:00
|
|
|
i++;
|
|
|
|
if (i >= HEXDUMP_SHORTS_PER_LINE) {
|
2002-04-24 14:55:54 +08:00
|
|
|
*hsp = *asp = '\0';
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("%s0x%04x: %-*s %s",
|
2022-03-04 17:23:59 +08:00
|
|
|
indent, offset, HEXDUMP_HEXSTUFF_PER_LINE,
|
2018-01-07 18:47:30 +08:00
|
|
|
hexstuff, asciistuff);
|
2002-04-24 14:55:54 +08:00
|
|
|
i = 0; hsp = hexstuff; asp = asciistuff;
|
2022-03-04 17:23:59 +08:00
|
|
|
offset += HEXDUMP_BYTES_PER_LINE;
|
1999-12-22 23:44:09 +08:00
|
|
|
}
|
2018-12-11 13:23:21 +08:00
|
|
|
nshorts--;
|
1999-12-22 23:44:09 +08:00
|
|
|
}
|
|
|
|
if (length & 1) {
|
2018-06-16 23:23:21 +08:00
|
|
|
s1 = GET_U_1(cp);
|
2018-01-28 21:18:51 +08:00
|
|
|
cp++;
|
2019-08-09 13:39:54 +08:00
|
|
|
(void)snprintf(hsp, sizeof(hexstuff) - (hsp - hexstuff),
|
2005-07-07 04:53:30 +08:00
|
|
|
" %02x", s1);
|
|
|
|
hsp += 3;
|
2019-09-02 07:11:32 +08:00
|
|
|
*(asp++) = (char)(ND_ASCII_ISGRAPH(s1) ? s1 : '.');
|
1999-12-22 23:44:09 +08:00
|
|
|
++i;
|
|
|
|
}
|
|
|
|
if (i > 0) {
|
|
|
|
*hsp = *asp = '\0';
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("%s0x%04x: %-*s %s",
|
2022-03-04 17:23:59 +08:00
|
|
|
indent, offset, HEXDUMP_HEXSTUFF_PER_LINE,
|
2018-01-07 18:47:30 +08:00
|
|
|
hexstuff, asciistuff);
|
1999-12-22 23:44:09 +08:00
|
|
|
}
|
ASCII/hex: Use nd_trunc_longjmp() in truncation cases
In functions ascii_print(), hex_and_ascii_print_with_offset() and
hex_print_with_offset().
Therefore indirectly for the functions hex_and_ascii_print(), hex_print()
and ndo_default_print().
Even if hex_and_ascii_print(), hex_print() and ascii_print() are used in
print.c after the setjmp() block with the calls:
1) hex_and_ascii_print(ndo, "\n\t", sp, h->caplen);
2) hex_and_ascii_print(ndo, "\n\t", sp + hdrlen, h->caplen - hdrlen);
3) hex_print(ndo, "\n\t", sp, h->caplen);
4) hex_print(ndo, "\n\t", sp + hdrlen, h->caplen - hdrlen);
5) ascii_print(ndo, sp, h->caplen);
6) ascii_print(ndo, sp + hdrlen, h->caplen - hdrlen);
sp and h->caplen are unmodified, ndo->ndo_snapend was restored.
1), 3) and 5) the length to print is caplen => no truncation can occur.
2), 4) and 6) the length to print is (caplen - hdrlen) after a shift of
hdrlen => no truncation can occur.
Moreover:
Update the output of three tests accordingly.
Remove an useless comment.
Fix indentation.
2021-03-27 23:14:27 +08:00
|
|
|
if (truncated)
|
|
|
|
nd_trunc_longjmp(ndo);
|
1999-12-22 23:44:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-03-28 20:44:35 +08:00
|
|
|
hex_and_ascii_print(netdissect_options *ndo, const char *indent,
|
2022-03-04 17:23:59 +08:00
|
|
|
const u_char *cp, u_int length)
|
1999-12-22 23:44:09 +08:00
|
|
|
{
|
2021-03-28 20:44:35 +08:00
|
|
|
hex_and_ascii_print_with_offset(ndo, indent, cp, length, 0);
|
1999-12-22 23:44:09 +08:00
|
|
|
}
|
2002-06-12 01:08:37 +08:00
|
|
|
|
1999-12-22 23:44:09 +08:00
|
|
|
/*
|
|
|
|
* telnet_print() wants this. It is essentially default_print_unaligned()
|
|
|
|
*/
|
|
|
|
void
|
2014-01-02 09:43:45 +08:00
|
|
|
hex_print_with_offset(netdissect_options *ndo,
|
2021-03-28 20:44:35 +08:00
|
|
|
const char *indent, const u_char *cp, u_int length,
|
2022-03-04 17:23:59 +08:00
|
|
|
u_int offset)
|
1999-12-22 23:44:09 +08:00
|
|
|
{
|
2014-10-23 15:06:32 +08:00
|
|
|
u_int caplength;
|
2017-12-14 02:17:47 +08:00
|
|
|
u_int i, s;
|
2018-12-11 13:23:21 +08:00
|
|
|
u_int nshorts;
|
ASCII/hex: Use nd_trunc_longjmp() in truncation cases
In functions ascii_print(), hex_and_ascii_print_with_offset() and
hex_print_with_offset().
Therefore indirectly for the functions hex_and_ascii_print(), hex_print()
and ndo_default_print().
Even if hex_and_ascii_print(), hex_print() and ascii_print() are used in
print.c after the setjmp() block with the calls:
1) hex_and_ascii_print(ndo, "\n\t", sp, h->caplen);
2) hex_and_ascii_print(ndo, "\n\t", sp + hdrlen, h->caplen - hdrlen);
3) hex_print(ndo, "\n\t", sp, h->caplen);
4) hex_print(ndo, "\n\t", sp + hdrlen, h->caplen - hdrlen);
5) ascii_print(ndo, sp, h->caplen);
6) ascii_print(ndo, sp + hdrlen, h->caplen - hdrlen);
sp and h->caplen are unmodified, ndo->ndo_snapend was restored.
1), 3) and 5) the length to print is caplen => no truncation can occur.
2), 4) and 6) the length to print is (caplen - hdrlen) after a shift of
hdrlen => no truncation can occur.
Moreover:
Update the output of three tests accordingly.
Remove an useless comment.
Fix indentation.
2021-03-27 23:14:27 +08:00
|
|
|
int truncated = FALSE;
|
1999-12-22 23:44:09 +08:00
|
|
|
|
2023-06-06 01:50:11 +08:00
|
|
|
caplength = ND_BYTES_AVAILABLE_AFTER(cp);
|
ASCII/hex: Use nd_trunc_longjmp() in truncation cases
In functions ascii_print(), hex_and_ascii_print_with_offset() and
hex_print_with_offset().
Therefore indirectly for the functions hex_and_ascii_print(), hex_print()
and ndo_default_print().
Even if hex_and_ascii_print(), hex_print() and ascii_print() are used in
print.c after the setjmp() block with the calls:
1) hex_and_ascii_print(ndo, "\n\t", sp, h->caplen);
2) hex_and_ascii_print(ndo, "\n\t", sp + hdrlen, h->caplen - hdrlen);
3) hex_print(ndo, "\n\t", sp, h->caplen);
4) hex_print(ndo, "\n\t", sp + hdrlen, h->caplen - hdrlen);
5) ascii_print(ndo, sp, h->caplen);
6) ascii_print(ndo, sp + hdrlen, h->caplen - hdrlen);
sp and h->caplen are unmodified, ndo->ndo_snapend was restored.
1), 3) and 5) the length to print is caplen => no truncation can occur.
2), 4) and 6) the length to print is (caplen - hdrlen) after a shift of
hdrlen => no truncation can occur.
Moreover:
Update the output of three tests accordingly.
Remove an useless comment.
Fix indentation.
2021-03-27 23:14:27 +08:00
|
|
|
if (length > caplength) {
|
2014-10-23 15:06:32 +08:00
|
|
|
length = caplength;
|
ASCII/hex: Use nd_trunc_longjmp() in truncation cases
In functions ascii_print(), hex_and_ascii_print_with_offset() and
hex_print_with_offset().
Therefore indirectly for the functions hex_and_ascii_print(), hex_print()
and ndo_default_print().
Even if hex_and_ascii_print(), hex_print() and ascii_print() are used in
print.c after the setjmp() block with the calls:
1) hex_and_ascii_print(ndo, "\n\t", sp, h->caplen);
2) hex_and_ascii_print(ndo, "\n\t", sp + hdrlen, h->caplen - hdrlen);
3) hex_print(ndo, "\n\t", sp, h->caplen);
4) hex_print(ndo, "\n\t", sp + hdrlen, h->caplen - hdrlen);
5) ascii_print(ndo, sp, h->caplen);
6) ascii_print(ndo, sp + hdrlen, h->caplen - hdrlen);
sp and h->caplen are unmodified, ndo->ndo_snapend was restored.
1), 3) and 5) the length to print is caplen => no truncation can occur.
2), 4) and 6) the length to print is (caplen - hdrlen) after a shift of
hdrlen => no truncation can occur.
Moreover:
Update the output of three tests accordingly.
Remove an useless comment.
Fix indentation.
2021-03-27 23:14:27 +08:00
|
|
|
truncated = TRUE;
|
|
|
|
}
|
2018-12-11 13:23:21 +08:00
|
|
|
nshorts = length / sizeof(u_short);
|
1999-12-22 23:44:09 +08:00
|
|
|
i = 0;
|
2018-12-11 13:23:21 +08:00
|
|
|
while (nshorts != 0) {
|
1999-12-22 23:44:09 +08:00
|
|
|
if ((i++ % 8) == 0) {
|
2022-03-04 17:23:59 +08:00
|
|
|
ND_PRINT("%s0x%04x: ", indent, offset);
|
|
|
|
offset += HEXDUMP_BYTES_PER_LINE;
|
1999-12-22 23:44:09 +08:00
|
|
|
}
|
2018-06-16 23:23:21 +08:00
|
|
|
s = GET_U_1(cp);
|
2018-01-28 21:18:51 +08:00
|
|
|
cp++;
|
2018-06-16 23:23:21 +08:00
|
|
|
ND_PRINT(" %02x%02x", s, GET_U_1(cp));
|
2018-01-28 21:18:51 +08:00
|
|
|
cp++;
|
2018-12-11 13:23:21 +08:00
|
|
|
nshorts--;
|
1999-12-22 23:44:09 +08:00
|
|
|
}
|
|
|
|
if (length & 1) {
|
|
|
|
if ((i % 8) == 0)
|
2022-03-04 17:23:59 +08:00
|
|
|
ND_PRINT("%s0x%04x: ", indent, offset);
|
2018-06-16 23:23:21 +08:00
|
|
|
ND_PRINT(" %02x", GET_U_1(cp));
|
1999-12-22 23:44:09 +08:00
|
|
|
}
|
ASCII/hex: Use nd_trunc_longjmp() in truncation cases
In functions ascii_print(), hex_and_ascii_print_with_offset() and
hex_print_with_offset().
Therefore indirectly for the functions hex_and_ascii_print(), hex_print()
and ndo_default_print().
Even if hex_and_ascii_print(), hex_print() and ascii_print() are used in
print.c after the setjmp() block with the calls:
1) hex_and_ascii_print(ndo, "\n\t", sp, h->caplen);
2) hex_and_ascii_print(ndo, "\n\t", sp + hdrlen, h->caplen - hdrlen);
3) hex_print(ndo, "\n\t", sp, h->caplen);
4) hex_print(ndo, "\n\t", sp + hdrlen, h->caplen - hdrlen);
5) ascii_print(ndo, sp, h->caplen);
6) ascii_print(ndo, sp + hdrlen, h->caplen - hdrlen);
sp and h->caplen are unmodified, ndo->ndo_snapend was restored.
1), 3) and 5) the length to print is caplen => no truncation can occur.
2), 4) and 6) the length to print is (caplen - hdrlen) after a shift of
hdrlen => no truncation can occur.
Moreover:
Update the output of three tests accordingly.
Remove an useless comment.
Fix indentation.
2021-03-27 23:14:27 +08:00
|
|
|
if (truncated)
|
|
|
|
nd_trunc_longjmp(ndo);
|
1999-12-22 23:44:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
ASCII/hex: Use nd_trunc_longjmp() in truncation cases
In functions ascii_print(), hex_and_ascii_print_with_offset() and
hex_print_with_offset().
Therefore indirectly for the functions hex_and_ascii_print(), hex_print()
and ndo_default_print().
Even if hex_and_ascii_print(), hex_print() and ascii_print() are used in
print.c after the setjmp() block with the calls:
1) hex_and_ascii_print(ndo, "\n\t", sp, h->caplen);
2) hex_and_ascii_print(ndo, "\n\t", sp + hdrlen, h->caplen - hdrlen);
3) hex_print(ndo, "\n\t", sp, h->caplen);
4) hex_print(ndo, "\n\t", sp + hdrlen, h->caplen - hdrlen);
5) ascii_print(ndo, sp, h->caplen);
6) ascii_print(ndo, sp + hdrlen, h->caplen - hdrlen);
sp and h->caplen are unmodified, ndo->ndo_snapend was restored.
1), 3) and 5) the length to print is caplen => no truncation can occur.
2), 4) and 6) the length to print is (caplen - hdrlen) after a shift of
hdrlen => no truncation can occur.
Moreover:
Update the output of three tests accordingly.
Remove an useless comment.
Fix indentation.
2021-03-27 23:14:27 +08:00
|
|
|
hex_print(netdissect_options *ndo,
|
2021-03-28 20:44:35 +08:00
|
|
|
const char *indent, const u_char *cp, u_int length)
|
1999-12-22 23:44:09 +08:00
|
|
|
{
|
2021-03-28 20:44:35 +08:00
|
|
|
hex_print_with_offset(ndo, indent, cp, length, 0);
|
1999-12-22 23:44:09 +08:00
|
|
|
}
|