From a4244f08adee1fb7b04401c9108e7e218864e2c3 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Fri, 25 Dec 2015 09:17:15 +0800 Subject: [PATCH] info struct add padding pool The info struct is too fragile against additions being able to keep soname. Because if we add something, the library can't count on the user code being built against latest headers with largest info struct size. Then the user code may not have zeroed down enough of the struct and give us junk in the new members. Add a pool at the end of the info struct that exists so it will be zeroed down even though no current use for those future members, then later library versions can compatibly use them without breaking soname if it is understood 0 means default. Because keeping sizeof info straight if you add something is now a thing, also add an lwsl_info letting you confirm it easily. It's fine if the size of info differs on different platforms. But when we add things to the struct we need to balance the padding using a scheme like short new_member; unsigned char _padding1[sizeof(void *) - sizeof(short)]; which is immune to differences in platform differences in sizeof void *. Signed-off-by: Andy Green --- lib/context.c | 1 + lib/libwebsockets.h | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/context.c b/lib/context.c index cb0fbbf..757fdd3 100644 --- a/lib/context.c +++ b/lib/context.c @@ -100,6 +100,7 @@ lws_create_context(struct lws_context_creation_info *info) lwsl_info(" SPEC_LATEST_SUPPORTED: %u\n", SPEC_LATEST_SUPPORTED); lwsl_info(" AWAITING_TIMEOUT: %u\n", AWAITING_TIMEOUT); + lwsl_info(" sizeof (*info): %u\n", sizeof(*info)); #if LWS_POSIX lwsl_info(" SYSTEM_RANDOM_FILEPATH: '%s'\n", SYSTEM_RANDOM_FILEPATH); lwsl_info(" LWS_MAX_ZLIB_CONN_BUFFER: %u\n", LWS_MAX_ZLIB_CONN_BUFFER); diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index 3536125..4855cd9 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -1278,7 +1278,14 @@ struct lws_context_creation_info { #endif /* Add new things just above here ---^ - * This is part of the ABI, don't needlessly break compatibilty */ + * This is part of the ABI, don't needlessly break compatibility + * + * The below is to ensure later library versions with new + * members added above will see 0 (default) even if the app + * was not built against the newer headers. + */ + + void *_unused[9]; }; LWS_VISIBLE LWS_EXTERN void -- 2.7.4