diff options
author | Ren Kararou <[email protected]> | 2025-01-12 21:37:58 -0600 |
---|---|---|
committer | Ren Kararou <[email protected]> | 2025-01-12 21:37:58 -0600 |
commit | 98a2d3d4f4eefe6e25c22b186b6c4b1a2e5ba6d8 (patch) | |
tree | 545c8ae743dac2c286723403028c84e4e38b6447 | |
parent | 5d087643d3b4aacc907e119d992fbc4038130941 (diff) | |
download | nbtpd-98a2d3d4f4eefe6e25c22b186b6c4b1a2e5ba6d8.tar.gz nbtpd-98a2d3d4f4eefe6e25c22b186b6c4b1a2e5ba6d8.tar.bz2 nbtpd-98a2d3d4f4eefe6e25c22b186b6c4b1a2e5ba6d8.zip |
complete netascii mode checks
-rw-r--r-- | src/handlers.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/handlers.c b/src/handlers.c index eed91f4..1d4d92c 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -241,6 +241,17 @@ void *read_req_resp(void *args) { senderror(s, argptr); goto cleanup; } + if ((opmode == NETASCII) && (!is_netascii_buf(buf, num_read))) { + syslog( + LOG_ERR, + "%s:%d: requested file is not netascii compliant.", + inet_ntoa(argptr->client.sin_addr), + ntohs(argptr->client.sin_port) + ); + argptr->err = 5; + senderror(s, argptr); + goto cleanup; + } char *packet = nbd_tftp_ser_data_from_parts(++bnum, buf, num_read); while (!verif) { syslog(LOG_DEBUG, "sending block number %d to %s:%d", @@ -274,6 +285,9 @@ void *read_req_resp(void *args) { ); if (rcv == 4) { nbd_tftp_packet_ack ack = nbd_tftp_de_ack(rxb, rcv); + if (ack.opcode == 5) { + goto socket_clean; + } syslog(LOG_DEBUG, "%s:%d ack'd with block number: %d (expect %d)", inet_ntoa(argptr->client.sin_addr), htons(argptr->client.sin_port), @@ -296,6 +310,11 @@ void *read_req_resp(void *args) { senderror(s, argptr); goto cleanup; } + if (rcv > 4) { + if ((((uint16_t)buf[0] << 8) + buf[1]) == 5) { + goto socket_clean; + } + } } } free(packet); @@ -303,6 +322,7 @@ void *read_req_resp(void *args) { lon = 0; } } +socket_clean: close(s); cleanup: fclose(fp); @@ -421,6 +441,9 @@ void *write_req_resp(void *args) { ); if (rcv >= 4) { nbd_tftp_packet_data data = nbd_tftp_de_data(rxb, rcv); + if (data.opcode == 5) { + goto cleanup; + } syslog( LOG_DEBUG, "%s:%d sent block number: %d (expect %d)", @@ -433,6 +456,17 @@ void *write_req_resp(void *args) { rxon = 0; verif = 1; if (data.datalen > 0) { + if ((opmode == NETASCII) && (!is_netascii_buf(data.data, data.datalen))) { + syslog( + LOG_ERR, + "%s:%d: requested file is not netascii compliant.", + inet_ntoa(argptr->client.sin_addr), + ntohs(argptr->client.sin_port) + ); + argptr->err = 5; + senderror(s, argptr); + goto cleanup; + } if (fwrite(data.data, 1, data.datalen, fp) < data.datalen) { syslog(LOG_ERR, "filewrite failed for %s: %s", fname, strerror(errno)); argptr->err = 0; |