Skip to content

Commit 9a3eebd

Browse files
committed
pgm: fix the way we step through the packet.
Step past the PGM header after we finish processing it and before we process the message-type-specific header. Step past the message-type-specific fixed-length header before we process the stuff after that header. This makes the code a bit clearer (by explicitly advancing bp by the size of the stuff we just processed, rather than doing so by trickery involving adding 1 to a pointer to a structure), and fixes the processing of message types that don't have a message-type-specific header (where we weren't stepping past the PGM header). It also affects the way we handle messages of an unknown type.
1 parent a0b7859 commit 9a3eebd

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

print-pgm.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,14 @@ pgm_print(netdissect_options *ndo,
220220
pgm->pgm_gsid[3],
221221
pgm->pgm_gsid[4],
222222
pgm->pgm_gsid[5]);
223+
bp += sizeof(struct pgm_header);
223224
switch (pgm_type_val) {
224225
case PGM_SPM: {
225226
const struct pgm_spm *spm;
226227

227-
spm = (const struct pgm_spm *)(pgm + 1);
228+
spm = (const struct pgm_spm *)bp;
228229
ND_TCHECK_SIZE(spm);
229-
bp = (const u_char *) (spm + 1);
230+
bp += sizeof(struct pgm_spm);
230231

231232
switch (GET_BE_U_2(spm->pgms_nla_afi)) {
232233
case AFNUM_IP:
@@ -256,9 +257,9 @@ pgm_print(netdissect_options *ndo,
256257
const struct pgm_poll *pgm_poll;
257258
uint32_t ivl, rnd, mask;
258259

259-
pgm_poll = (const struct pgm_poll *)(pgm + 1);
260+
pgm_poll = (const struct pgm_poll *)bp;
260261
ND_TCHECK_SIZE(pgm_poll);
261-
bp = (const u_char *) (pgm_poll + 1);
262+
bp += sizeof(struct pgm_poll);
262263

263264
switch (GET_BE_U_2(pgm_poll->pgmp_nla_afi)) {
264265
case AFNUM_IP:
@@ -294,33 +295,33 @@ pgm_print(netdissect_options *ndo,
294295
case PGM_POLR: {
295296
const struct pgm_polr *polr_msg;
296297

297-
polr_msg = (const struct pgm_polr *)(pgm + 1);
298+
polr_msg = (const struct pgm_polr *)bp;
298299
ND_TCHECK_SIZE(polr_msg);
299300
ND_PRINT("POLR seq %u round %u",
300301
GET_BE_U_4(polr_msg->pgmp_seq),
301302
GET_BE_U_2(polr_msg->pgmp_round));
302-
bp = (const u_char *) (polr_msg + 1);
303+
bp += sizeof(struct pgm_polr);
303304
break;
304305
}
305306
case PGM_ODATA: {
306307
const struct pgm_data *odata;
307308

308-
odata = (const struct pgm_data *)(pgm + 1);
309+
odata = (const struct pgm_data *)bp;
309310
ND_PRINT("ODATA trail %u seq %u",
310311
GET_BE_U_4(odata->pgmd_trailseq),
311312
GET_BE_U_4(odata->pgmd_seq));
312-
bp = (const u_char *) (odata + 1);
313+
bp += sizeof(struct pgm_data);
313314
break;
314315
}
315316

316317
case PGM_RDATA: {
317318
const struct pgm_data *rdata;
318319

319-
rdata = (const struct pgm_data *)(pgm + 1);
320+
rdata = (const struct pgm_data *)bp;
320321
ND_PRINT("RDATA trail %u seq %u",
321322
GET_BE_U_4(rdata->pgmd_trailseq),
322323
GET_BE_U_4(rdata->pgmd_seq));
323-
bp = (const u_char *) (rdata + 1);
324+
bp += sizeof(struct pgm_data);
324325
break;
325326
}
326327

@@ -330,9 +331,9 @@ pgm_print(netdissect_options *ndo,
330331
const struct pgm_nak *nak;
331332
char source_buf[INET6_ADDRSTRLEN], group_buf[INET6_ADDRSTRLEN];
332333

333-
nak = (const struct pgm_nak *)(pgm + 1);
334+
nak = (const struct pgm_nak *)bp;
334335
ND_TCHECK_SIZE(nak);
335-
bp = (const u_char *) (nak + 1);
336+
bp += sizeof(struct pgm_nak);
336337

337338
/*
338339
* Skip past the source, saving info along the way
@@ -399,11 +400,11 @@ pgm_print(netdissect_options *ndo,
399400
case PGM_ACK: {
400401
const struct pgm_ack *ack;
401402

402-
ack = (const struct pgm_ack *)(pgm + 1);
403+
ack = (const struct pgm_ack *)bp;
403404
ND_TCHECK_SIZE(ack);
404405
ND_PRINT("ACK seq %u",
405406
GET_BE_U_4(ack->pgma_rx_max_seq));
406-
bp = (const u_char *) (ack + 1);
407+
bp += sizeof(struct pgm_ack);
407408
break;
408409
}
409410

tests/pgm_opts_asan.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
1 00:04:16.587271427 IP (tos 0x41,ECT(1), id 0, offset 0, flags [none], proto PGM (113), length 32639, options (unknown 89 [bad length 232]), bad cksum 5959 (->9eb9)!)
2-
128.121.89.107 > 89.89.16.63: 128.121.89.107.4 > 89.89.16.63.225: PGM, length 0 0x3414eb1f0022 UNKNOWN type 0x1f OPTS LEN 225 OPT_1F [13] OPT_06 [26] PATH_NLA [4] [|pgm]
2+
128.121.89.107 > 89.89.16.63: 128.121.89.107.4 > 89.89.16.63.225: PGM, length 0 0x3414eb1f0022 UNKNOWN type 0x1f[Bad OPT_LENGTH option, length 0 != 4]

tests/pgm_opts_asan_2.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
1 00:04:16.587271427 IP (tos 0x41,ECT(1), id 0, offset 0, flags [none], proto PGM (113), length 32639, options (unknown 89 [bad length 232]), bad cksum 5959 (->96b9)!)
2-
128.121.89.107 > 89.89.16.63: 128.121.89.107.4 > 89.89.16.63.225: PGM, length 0 0x3414eb1f0022 UNKNOWN type 0x1f OPTS LEN 225 OPT_1F [13] OPT_06 [26] [Bad OPT_PGMCC_DATA option, length 4 < 12]
2+
128.121.89.107 > 89.89.16.63: 128.121.89.107.4 > 89.89.16.63.225: PGM, length 0 0x3414eb1f0022 UNKNOWN type 0x1f[Bad OPT_LENGTH option, length 0 != 4]

tests/pgm_opts_asan_3.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
1 00:04:16.587271427 IP (tos 0x41,ECT(1), id 0, offset 0, flags [none], proto PGM (113), length 32639, options (unknown 89 [bad length 232]), bad cksum 5959 (->f814)!)
2-
128.121.89.16 > 0.89.16.63: 128.121.89.16.4 > 0.89.16.63.225: PGM, length 0 0x3414eb1f0022 UNKNOWN type 0x1f OPTS LEN 225 OPT_1F [13] OPT_06 [26] [Bad OPT_REDIRECT option, length 4 < 8]
2+
128.121.89.16 > 0.89.16.63: 128.121.89.16.4 > 0.89.16.63.225: PGM, length 0 0x3414eb1f0022 UNKNOWN type 0x1f[Bad OPT_LENGTH option, length 0 != 4]

0 commit comments

Comments
 (0)