--- a/tftp/tftp.c +++ a/tftp/tftp.c @@ -52,7 +52,7 @@ sigjmp_buf toplevel; sigjmp_buf timeoutbuf; static void nak(int, const char *); -static int makerequest(int, const char *, struct tftphdr *, const char *); +static int makerequest(int, const char *, void *, const char *); static void printstats(const char *, unsigned long); static void startclock(void); static void stopclock(void); @@ -276,17 +276,23 @@ void tftp_recvfile(int fd, const char *name, const char *mode) static int makerequest(int request, const char *name, - struct tftphdr *tp, const char *mode) + void *p, const char *mode) { char *cp; + struct tftphdr *tp = p; + size_t namelen, modelen; tp->th_opcode = htons((u_short) request); - cp = (char *)&(tp->th_stuff); + cp = (char*)p + offsetof(struct tftphdr, th_stuff); + namelen = strlen(name); + modelen = strlen(mode); + if (namelen + modelen + 2 > SEGSIZE) + perror("Filename is too long"); strcpy(cp, name); - cp += strlen(name); + cp += namelen; *cp++ = '\0'; strcpy(cp, mode); - cp += strlen(mode); + cp += modelen; *cp++ = '\0'; return (cp - (char *)tp); }