diff options
| -rw-r--r-- | src/core/options.c | 3 | ||||
| -rw-r--r-- | tests/sock.c | 21 |
2 files changed, 21 insertions, 3 deletions
diff --git a/src/core/options.c b/src/core/options.c index 843b066d..d61b35ac 100644 --- a/src/core/options.c +++ b/src/core/options.c @@ -157,9 +157,6 @@ nni_copyin_str(char *s, const void *v, size_t sz, size_t maxsz, nni_opt_type t) switch (t) { case NNI_TYPE_STRING: - z = strlen(v) + 1; - NNI_ASSERT(sz == z); - break; case NNI_TYPE_OPAQUE: if ((z = nni_strnlen(v, sz)) >= sz) { return (NNG_EINVAL); // missing terminator diff --git a/tests/sock.c b/tests/sock.c index 4aef1f38..562a05d7 100644 --- a/tests/sock.c +++ b/tests/sock.c @@ -122,6 +122,27 @@ TestMain("Socket Operations", { nng_strfree(allocd); }); + Convey("Oversize sockname handled right", { + char name[256]; // 64 is max + size_t sz = sizeof(name); + memset(name, 'A', sz); + So(nng_setopt(s1, NNG_OPT_SOCKNAME, name, + sz) == NNG_EINVAL); + name[sz - 1] = '\0'; + So(nng_setopt(s1, NNG_OPT_SOCKNAME, name, + sz) == NNG_EINVAL); + + strcpy(name, "hello"); + So(nng_setopt( + s1, NNG_OPT_SOCKNAME, name, sz) == 0); + sz = sizeof(name); + memset(name, 'B', sz); + So(nng_getopt( + s1, NNG_OPT_SOCKNAME, name, &sz) == 0); + So(sz == 6); + So(strcmp(name, "hello") == 0); + }); + Convey("RAW option works", { bool raw; So(nng_getopt_bool(s1, NNG_OPT_RAW, &raw) == |
