Skip to content

Commit 43cbd67

Browse files
cli: avoid accept too long path
CLN accept long path as cli parameter also if ccan hash a limit to it, but also specific machine has limit on the length of the path, so this explain why Rusty hard coded the upper limit of the length into ccan. So from https://unix.stackexchange.com/a/367012/369490 there is a good description to it. An extraction is: >SUSv3 doesn’t specify the size of the sun_path field. Early BSD implementations used 108 and 104 bytes, and one contemporary implementation (HP-UX 11) uses 92 bytes. Portable applications should code to this lower value, and use `snprintf()` or `strncpy()` to avoid buffer overruns when writing into this field. - OpenBSD: 104 characters - FreeBSD: 104 characters - Mac OS X 10.9: 104 characters P.S: Maybe we could increase the max length from 80 to 100 (?) Changelog-Fixed: cli: avoid accepting too long path Suggested-by: SimonVrouwe <s_github@protonmail.com> Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
1 parent df29990 commit 43cbd67

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

common/configdir.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <ccan/tal/path/path.h>
99
#include <ccan/tal/str/str.h>
1010
#include <common/configdir.h>
11+
#include <common/errcode.h>
1112
#include <common/utils.h>
1213
#include <common/version.h>
1314

@@ -25,10 +26,15 @@ char *opt_set_talstr(const char *arg, char **p)
2526

2627
static char *opt_set_abspath(const char *arg, char **p)
2728
{
29+
char* ret;
2830
tal_free(*p);
29-
return opt_set_charp(path_join(options_ctx, take(path_cwd(NULL)), arg),
30-
p);
31-
}
31+
32+
ret = opt_set_charp(path_join(options_ctx, take(path_cwd(NULL)), arg),p);
33+
if (strlen(*p) > 80)
34+
errx(EXITCODE_INVALID_PATH, "absolute path of command line option exceeds 80 chars: '%s'",
35+
*p);
36+
return ret;
37+
}
3238

3339
/* Tal wrappers for opt. */
3440
static void *opt_allocfn(size_t size)

common/errcode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// Setup errors
99
#define EXITCODE_SUBDAEMON_FAIL 10
1010
#define EXITCODE_PIDFILE_LOCK 11
11+
#define EXITCODE_INVALID_PATH 12
1112

1213
// HSM errors code
1314
#define EXITCODE_HSM_GENERIC_ERROR 20

0 commit comments

Comments
 (0)