Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#105 port mode fails on ppc_85xx architecture

0.6.1
open
nobody
5
2012-02-24
2012-02-24
pesah spector
No

Attempt to run wput in port-mode fails due to 0,0 port arguments sent in PORT request. In result wput switches to run in passive mode. The problem as far as I can see is in routine get_port_fmt() that does the cast
*(unsigned int *)(b+4) = htons(port);
However the actual value returned by htons() is uint16_t so the casting will do things that depend on underlines CPU indian-ness and word size (64-bit vs 16 bit). Should be fixed IMHO to *(uint16_t *)(b+4) = htons(port); In case of ppc-85xx the casting results in value 0 and possibly the variable b is assigned value that is beyond b size (potential stack corruption)

char * get_port_fmt(int ip, unsigned int port) {
unsigned char b[6];
static char buf[6 * 4];
/* TODO USS have we got an endian problem here for the ip-address */
* (int *) b = ip;
*(unsigned int *)(b+4) = htons(port);
sprintf(buf, "%d,%d,%d,%d,%d,%d", b[0], b[1], b[2], b[3], b[4], b[5]);
return buf;
}

Discussion