diff --git a/sys/shell/commands/sc_nanocoap_vfs.c b/sys/shell/commands/sc_nanocoap_vfs.c index e9fd5ba730..c9ccf13eb7 100644 --- a/sys/shell/commands/sc_nanocoap_vfs.c +++ b/sys/shell/commands/sc_nanocoap_vfs.c @@ -121,7 +121,16 @@ static int _nanocoap_get_handler(int argc, char **argv) } dst = buffer; } else { + char *filename = strrchr(url, '/'); dst = argv[2]; + if (_is_dir(dst) && filename) { + if (snprintf(buffer, sizeof(buffer), "%s%s", + dst, filename + 1) >= (int)sizeof(buffer)) { + printf("Output file path too long\n"); + return -ENOBUFS; + } + dst = buffer; + } } /* alternatively write the file to stdout */