From: Guy Harris Date: Wed, 27 Jan 2010 02:35:53 +0000 (-0800) Subject: Use EXTRACT_16BITS to extract big-endian 16-bit quantities from the packet. X-Git-Tag: tcpdump-4.1.0~30 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/19b5602a0ce71f96fcbc75c3781c41aea4223e1e Use EXTRACT_16BITS to extract big-endian 16-bit quantities from the packet. There's no guarantee that those quantities will be properly aligned, nor is there any guarantee that fetching an improperly-aligned quantity will work as desired. --- diff --git a/print-sctp.c b/print-sctp.c index c0fa3087..0229396d 100644 --- a/print-sctp.c +++ b/print-sctp.c @@ -232,16 +232,16 @@ void sctp_print(const u_char *bp, /* beginning of sctp packet */ u_int chunksize = sizeof(struct sctpDataPart)+ sizeof(struct sctpChunkDesc); payloadPtr = (const u_char *) (dataHdrPtr + 1); - if (htons(chunkDescPtr->chunkLength) < + if (EXTRACT_16BITS(&chunkDescPtr->chunkLength) < sizeof(struct sctpDataPart)+ sizeof(struct sctpChunkDesc)+1) { /* Less than 1 byte of chunk payload */ printf("bogus ForCES chunk length %u]", - htons(chunkDescPtr->chunkLength)); + EXTRACT_16BITS(&chunkDescPtr->chunkLength)); return; } - forces_print(payloadPtr, htons(chunkDescPtr->chunkLength)- chunksize); + forces_print(payloadPtr, EXTRACT_16BITS(&chunkDescPtr->chunkLength)- chunksize); } else if (vflag >= 2) { /* if verbose output is specified */ /* at the command line */ const u_char *payloadPtr; @@ -251,16 +251,16 @@ void sctp_print(const u_char *bp, /* beginning of sctp packet */ if (!suppress_default_print) { payloadPtr = (const u_char *) (++dataHdrPtr); printf(":"); - if (htons(chunkDescPtr->chunkLength) < + if (EXTRACT_16BITS(&chunkDescPtr->chunkLength) < sizeof(struct sctpDataPart)+ sizeof(struct sctpChunkDesc)+1) { /* Less than 1 byte of chunk payload */ printf("bogus chunk length %u]", - htons(chunkDescPtr->chunkLength)); + EXTRACT_16BITS(&chunkDescPtr->chunkLength)); return; } default_print(payloadPtr, - htons(chunkDescPtr->chunkLength) - + EXTRACT_16BITS(&chunkDescPtr->chunkLength) - (sizeof(struct sctpDataPart)+ sizeof(struct sctpChunkDesc))); } else