Skip to content

Commit

Permalink
cli: avoid accept too long path
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
vincenzopalazzo committed Jan 6, 2023
1 parent df29990 commit 43cbd67
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 9 additions & 3 deletions common/configdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <ccan/tal/path/path.h>
#include <ccan/tal/str/str.h>
#include <common/configdir.h>
#include <common/errcode.h>
#include <common/utils.h>
#include <common/version.h>

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

static char *opt_set_abspath(const char *arg, char **p)
{
char* ret;
tal_free(*p);
return opt_set_charp(path_join(options_ctx, take(path_cwd(NULL)), arg),
p);
}

ret = opt_set_charp(path_join(options_ctx, take(path_cwd(NULL)), arg),p);
if (strlen(*p) > 80)
errx(EXITCODE_INVALID_PATH, "absolute path of command line option exceeds 80 chars: '%s'",
*p);
return ret;
}

/* Tal wrappers for opt. */
static void *opt_allocfn(size_t size)
Expand Down
1 change: 1 addition & 0 deletions common/errcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// Setup errors
#define EXITCODE_SUBDAEMON_FAIL 10
#define EXITCODE_PIDFILE_LOCK 11
#define EXITCODE_INVALID_PATH 12

// HSM errors code
#define EXITCODE_HSM_GENERIC_ERROR 20
Expand Down

0 comments on commit 43cbd67

Please sign in to comment.