[syslinux] [PATCH v2] tftp-hpa: add error check for disk filled up

H. Peter Anvin hpa at zytor.com
Tue Sep 3 20:49:44 PDT 2013


On 09/03/2013 12:02 AM, rongqing.li at windriver.com wrote:
> diff --git a/tftpd/tftpd.c b/tftpd/tftpd.c
> index 1873e70..c2adbda 100644
> --- a/tftpd/tftpd.c
> +++ b/tftpd/tftpd.c
> @@ -1681,7 +1681,11 @@ static void tftp_recvfile(const struct formats *pf, struct tftphdr *oap, int oac
>              syslog(LOG_WARNING, "tftpd: write(ack): %m");
>              goto abort;
>          }
> -        write_behind(file, pf->f_convert);
> +        if(write_behind(file, pf->f_convert) < 0) {
> +            nak(ENOSPACE, NULL);
> +            (void)fclose(file);
> +            goto abort;
> +        }
>          for (;;) {
>              n = recv_time(peer, dp, PKTSIZE, 0, &r_timeout);
>              if (n < 0) {        /* really? */
> @@ -1712,7 +1716,11 @@ static void tftp_recvfile(const struct formats *pf, struct tftphdr *oap, int oac
>              goto abort;
>          }
>      } while (size == segsize);
> -    write_behind(file, pf->f_convert);
> +    if(write_behind(file, pf->f_convert) < 0) {
> +        nak(ENOSPACE, NULL);
> +        (void)fclose(file);
> +        goto abort;
> +    }
>      (void)fclose(file);         /* close data file */
>  
>      ap->th_opcode = htons((u_short) ACK);       /* send the "final" ack */
> 

For the terminal block, you *have* to call fflush(), then check
ferror(), before sending the ACK.

Also, you are sending ENOSPACE without actually considering other error
conditions... not that it is all that essential.  Passing NULL in as the
human error string is also a bit obnoxious.

	-hpa




More information about the Syslinux mailing list