return 1;
}
+ if (args->file_remote) {
+ if (!tftp_is_valid_filename(args->file_remote)) {
+ fprintf(stderr, "Invalid remote filename '%s'.\n",
+ args->file_remote);
+ return 1;
+ }
+ }
+
err = 1;
sock = ethsock_create(args->intf, ETH_P_NMRP);
break;
}
- if (verbosity) {
- len = 0;
- filename = msg_opt_data(&rx.msg, NMRP_O_FILE_NAME, &len);
- if (filename) {
- printf("Received upload request for '%.*s'.\n", len,
- filename);
+ len = 0;
+ filename = msg_opt_data(&rx.msg, NMRP_O_FILE_NAME, &len);
+ if (filename) {
+ if (!args->file_remote) {
+ args->file_remote = filename;
+ }
+ printf("Received upload request: filename '%.*s'.\n",
+ len, filename);
+ } else if (!args->file_remote) {
+ if (tftp_is_valid_filename(args->file_local)) {
+ args->file_remote = args->file_local;
} else {
- printf("No filename specified in upload request.");
+ args->file_remote = "firmware";
}
+ printf("Received upload request with empty filename.");
}
err = 0;
}
if (!err && args->file_local) {
+ if (verbosity) {
+ printf("Using remote filename '%s'.\n",
+ args->file_remote);
+ }
+
if (!strcmp(args->file_local, "-")) {
printf("Uploading from stdin ... ");
} else {
unsigned ul_timeout;
const char *tftpcmd;
const char *file_local;
+ const char *file_remote;
const char *ipaddr;
const char *ipmask;
const char *intf;
};
int tftp_put(struct nmrpd_args *args);
+bool tftp_is_valid_filename(const char *filename);
+
int nmrp_do(struct nmrpd_args *args);
int select_fd(int fd, unsigned timeout);
size_t len = 2;
filename = leafname(filename);
- if (!is_netascii(filename) || strlen(filename) > 500) {
+ if (!tftp_is_valid_filename(filename)) {
fprintf(stderr, "Overlong/illegal filename; using 'firmware'.\n");
filename = "firmware";
} else if (!strcmp(filename, "-")) {
}
#endif
+inline bool tftp_is_valid_filename(const char *filename)
+{
+ return strlen(filename) <= 500 && is_netascii(filename);
+}
+
int tftp_put(struct nmrpd_args *args)
{
struct sockaddr_in addr;
/* Not really, but this way the loop sends our WRQ before receiving */
timeout = 1;
- pkt_mkwrq(tx, args->file_local);
+ pkt_mkwrq(tx, args->file_remote);
do {
if (!timeout && pkt_num(rx) == ACK) {