2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-22 01:49:11 +00:00

Update to protobuf-c 1.4.0

This commit is contained in:
Todd C. Miller 2022-06-03 12:50:31 -06:00
parent aee276ea63
commit 71c07579ba
5 changed files with 95 additions and 84 deletions

View File

@ -10,19 +10,19 @@ PROTOBUF_C__BEGIN_DECLS
#if PROTOBUF_C_VERSION_NUMBER < 1003000
# error This file was generated by a newer version of protoc-c which is incompatible with your libprotobuf-c headers. Please update your headers.
#elif 1003003 < PROTOBUF_C_MIN_COMPILER_VERSION
#elif 1004000 < PROTOBUF_C_MIN_COMPILER_VERSION
# error This file was generated by an older version of protoc-c which is incompatible with your libprotobuf-c headers. Please regenerate this file with a newer version of protoc-c.
#endif
typedef struct _InterceptRequest InterceptRequest;
typedef struct _InterceptHello InterceptHello;
typedef struct _HelloResponse HelloResponse;
typedef struct _PolicyCheckRequest PolicyCheckRequest;
typedef struct _PolicyAcceptMessage PolicyAcceptMessage;
typedef struct _PolicyRejectMessage PolicyRejectMessage;
typedef struct _PolicyErrorMessage PolicyErrorMessage;
typedef struct _InterceptResponse InterceptResponse;
typedef struct InterceptRequest InterceptRequest;
typedef struct InterceptHello InterceptHello;
typedef struct HelloResponse HelloResponse;
typedef struct PolicyCheckRequest PolicyCheckRequest;
typedef struct PolicyAcceptMessage PolicyAcceptMessage;
typedef struct PolicyRejectMessage PolicyRejectMessage;
typedef struct PolicyErrorMessage PolicyErrorMessage;
typedef struct InterceptResponse InterceptResponse;
/* --- enums --- */
@ -34,14 +34,14 @@ typedef enum {
INTERCEPT_REQUEST__TYPE__NOT_SET = 0,
INTERCEPT_REQUEST__TYPE_POLICY_CHECK_REQ = 1,
INTERCEPT_REQUEST__TYPE_HELLO = 2
PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(INTERCEPT_REQUEST__TYPE)
PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(INTERCEPT_REQUEST__TYPE__CASE)
} InterceptRequest__TypeCase;
/*
* Intercept message from sudo_intercept.so. Messages on the
* wire are prefixed with a 32-bit size in network byte order.
*/
struct _InterceptRequest
struct InterceptRequest
{
ProtobufCMessage base;
InterceptRequest__TypeCase type_case;
@ -59,7 +59,7 @@ struct _InterceptRequest
* Hello message from sudo_intercept.so to main sudo process.
* Sudo sends back the token and localhost port number.
*/
struct _InterceptHello
struct InterceptHello
{
ProtobufCMessage base;
int32_t pid;
@ -73,7 +73,7 @@ struct _InterceptHello
* Sudo response to an InterceptHello from sudo_intercept.so.
* The client uses the port number and token to connect back to sudo.
*/
struct _HelloResponse
struct HelloResponse
{
ProtobufCMessage base;
uint64_t token_lo;
@ -90,7 +90,7 @@ struct _HelloResponse
* Note that the plugin API only currently supports passing
* the new environment in to the open() function.
*/
struct _PolicyCheckRequest
struct PolicyCheckRequest
{
ProtobufCMessage base;
char *command;
@ -106,7 +106,7 @@ struct _PolicyCheckRequest
, (char *)protobuf_c_empty_string, (char *)protobuf_c_empty_string, 0,NULL, 0,NULL, 0 }
struct _PolicyAcceptMessage
struct PolicyAcceptMessage
{
ProtobufCMessage base;
char *run_command;
@ -120,7 +120,7 @@ struct _PolicyAcceptMessage
, (char *)protobuf_c_empty_string, 0,NULL, 0,NULL }
struct _PolicyRejectMessage
struct PolicyRejectMessage
{
ProtobufCMessage base;
char *reject_message;
@ -130,7 +130,7 @@ struct _PolicyRejectMessage
, (char *)protobuf_c_empty_string }
struct _PolicyErrorMessage
struct PolicyErrorMessage
{
ProtobufCMessage base;
char *error_message;
@ -146,13 +146,13 @@ typedef enum {
INTERCEPT_RESPONSE__TYPE_ACCEPT_MSG = 2,
INTERCEPT_RESPONSE__TYPE_REJECT_MSG = 3,
INTERCEPT_RESPONSE__TYPE_ERROR_MSG = 4
PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(INTERCEPT_RESPONSE__TYPE)
PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(INTERCEPT_RESPONSE__TYPE__CASE)
} InterceptResponse__TypeCase;
/*
* Response sent back to sudo_intercept.so.
*/
struct _InterceptResponse
struct InterceptResponse
{
ProtobufCMessage base;
InterceptResponse__TypeCase type_case;

View File

@ -10,27 +10,27 @@ PROTOBUF_C__BEGIN_DECLS
#if PROTOBUF_C_VERSION_NUMBER < 1003000
# error This file was generated by a newer version of protoc-c which is incompatible with your libprotobuf-c headers. Please update your headers.
#elif 1003003 < PROTOBUF_C_MIN_COMPILER_VERSION
#elif 1004000 < PROTOBUF_C_MIN_COMPILER_VERSION
# error This file was generated by an older version of protoc-c which is incompatible with your libprotobuf-c headers. Please regenerate this file with a newer version of protoc-c.
#endif
typedef struct _ClientMessage ClientMessage;
typedef struct _TimeSpec TimeSpec;
typedef struct _IoBuffer IoBuffer;
typedef struct _InfoMessage InfoMessage;
typedef struct _InfoMessage__StringList InfoMessage__StringList;
typedef struct _InfoMessage__NumberList InfoMessage__NumberList;
typedef struct _AcceptMessage AcceptMessage;
typedef struct _RejectMessage RejectMessage;
typedef struct _ExitMessage ExitMessage;
typedef struct _AlertMessage AlertMessage;
typedef struct _RestartMessage RestartMessage;
typedef struct _ChangeWindowSize ChangeWindowSize;
typedef struct _CommandSuspend CommandSuspend;
typedef struct _ClientHello ClientHello;
typedef struct _ServerMessage ServerMessage;
typedef struct _ServerHello ServerHello;
typedef struct ClientMessage ClientMessage;
typedef struct TimeSpec TimeSpec;
typedef struct IoBuffer IoBuffer;
typedef struct InfoMessage InfoMessage;
typedef struct InfoMessage__StringList InfoMessage__StringList;
typedef struct InfoMessage__NumberList InfoMessage__NumberList;
typedef struct AcceptMessage AcceptMessage;
typedef struct RejectMessage RejectMessage;
typedef struct ExitMessage ExitMessage;
typedef struct AlertMessage AlertMessage;
typedef struct RestartMessage RestartMessage;
typedef struct ChangeWindowSize ChangeWindowSize;
typedef struct CommandSuspend CommandSuspend;
typedef struct ClientHello ClientHello;
typedef struct ServerMessage ServerMessage;
typedef struct ServerHello ServerHello;
/* --- enums --- */
@ -53,14 +53,14 @@ typedef enum {
CLIENT_MESSAGE__TYPE_WINSIZE_EVENT = 11,
CLIENT_MESSAGE__TYPE_SUSPEND_EVENT = 12,
CLIENT_MESSAGE__TYPE_HELLO_MSG = 13
PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(CLIENT_MESSAGE__TYPE)
PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(CLIENT_MESSAGE__TYPE__CASE)
} ClientMessage__TypeCase;
/*
* Client message to the server. Messages on the wire are
* prefixed with a 32-bit size in network byte order.
*/
struct _ClientMessage
struct ClientMessage
{
ProtobufCMessage base;
ClientMessage__TypeCase type_case;
@ -88,7 +88,7 @@ struct _ClientMessage
/*
* Equivalent of POSIX struct timespec
*/
struct _TimeSpec
struct TimeSpec
{
ProtobufCMessage base;
/*
@ -108,7 +108,7 @@ struct _TimeSpec
/*
* I/O buffer with keystroke data
*/
struct _IoBuffer
struct IoBuffer
{
ProtobufCMessage base;
/*
@ -125,7 +125,7 @@ struct _IoBuffer
, NULL, {0,NULL} }
struct _InfoMessage__StringList
struct InfoMessage__StringList
{
ProtobufCMessage base;
size_t n_strings;
@ -136,7 +136,7 @@ struct _InfoMessage__StringList
, 0,NULL }
struct _InfoMessage__NumberList
struct InfoMessage__NumberList
{
ProtobufCMessage base;
size_t n_numbers;
@ -153,14 +153,14 @@ typedef enum {
INFO_MESSAGE__VALUE_STRVAL = 3,
INFO_MESSAGE__VALUE_STRLISTVAL = 4,
INFO_MESSAGE__VALUE_NUMLISTVAL = 5
PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(INFO_MESSAGE__VALUE)
PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(INFO_MESSAGE__VALUE__CASE)
} InfoMessage__ValueCase;
/*
* Key/value pairs, like Privilege Manager struct info.
* The value may be a number, a string, or a list of strings.
*/
struct _InfoMessage
struct InfoMessage
{
ProtobufCMessage base;
char *key;
@ -180,7 +180,7 @@ struct _InfoMessage
/*
* Event log data for command accepted by the policy.
*/
struct _AcceptMessage
struct AcceptMessage
{
ProtobufCMessage base;
/*
@ -205,7 +205,7 @@ struct _AcceptMessage
/*
* Event log data for command rejected by the policy.
*/
struct _RejectMessage
struct RejectMessage
{
ProtobufCMessage base;
/*
@ -230,7 +230,7 @@ struct _RejectMessage
/*
* Might revisit runtime and use end_time instead
*/
struct _ExitMessage
struct ExitMessage
{
ProtobufCMessage base;
/*
@ -262,7 +262,7 @@ struct _ExitMessage
/*
* Alert message, policy module-specific.
*/
struct _AlertMessage
struct AlertMessage
{
ProtobufCMessage base;
/*
@ -287,7 +287,7 @@ struct _AlertMessage
/*
* Used to restart an existing I/O log on the server.
*/
struct _RestartMessage
struct RestartMessage
{
ProtobufCMessage base;
/*
@ -307,7 +307,7 @@ struct _RestartMessage
/*
* Window size change event.
*/
struct _ChangeWindowSize
struct ChangeWindowSize
{
ProtobufCMessage base;
/*
@ -331,7 +331,7 @@ struct _ChangeWindowSize
/*
* Command suspend/resume event.
*/
struct _CommandSuspend
struct CommandSuspend
{
ProtobufCMessage base;
/*
@ -351,7 +351,7 @@ struct _CommandSuspend
/*
* Hello message from client when connecting to server.
*/
struct _ClientHello
struct ClientHello
{
ProtobufCMessage base;
/*
@ -371,14 +371,14 @@ typedef enum {
SERVER_MESSAGE__TYPE_LOG_ID = 3,
SERVER_MESSAGE__TYPE_ERROR = 4,
SERVER_MESSAGE__TYPE_ABORT = 5
PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(SERVER_MESSAGE__TYPE)
PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(SERVER_MESSAGE__TYPE__CASE)
} ServerMessage__TypeCase;
/*
* Server messages to the client. Messages on the wire are
* prefixed with a 32-bit size in network byte order.
*/
struct _ServerMessage
struct ServerMessage
{
ProtobufCMessage base;
ServerMessage__TypeCase type_case;
@ -413,7 +413,7 @@ struct _ServerMessage
/*
* Hello message from server when client connects.
*/
struct _ServerHello
struct ServerHello
{
ProtobufCMessage base;
/*

View File

@ -238,7 +238,11 @@ PROTOBUF_C__BEGIN_DECLS
#define PROTOBUF_C__ENUM_DESCRIPTOR_MAGIC 0x114315af
/* Empty string used for initializers */
#if defined(_WIN32) && defined(PROTOBUF_C_USE_SHARED_LIB)
static const char protobuf_c_empty_string[] = "";
#else
extern const char protobuf_c_empty_string[];
#endif
/**
* \defgroup api Public API
@ -790,13 +794,13 @@ protobuf_c_version_number(void);
* The version of the protobuf-c headers, represented as a string using the same
* format as protobuf_c_version().
*/
#define PROTOBUF_C_VERSION "1.3.3"
#define PROTOBUF_C_VERSION "1.4.0"
/**
* The version of the protobuf-c headers, represented as an integer using the
* same format as protobuf_c_version_number().
*/
#define PROTOBUF_C_VERSION_NUMBER 1003003
#define PROTOBUF_C_VERSION_NUMBER 1004000
/**
* The minimum protoc-c version which works with the current version of the

View File

@ -86,7 +86,9 @@
# define PROTOBUF_C_UNPACK_ERROR(...)
#endif
#if !defined(_WIN32) || !defined(PROTOBUF_C_USE_SHARED_LIB)
const char protobuf_c_empty_string[] = "";
#endif
/**
* Internal `ProtobufCMessage` manipulation macro.
@ -150,12 +152,14 @@ protobuf_c_version_number(void)
static void *
system_alloc(void *allocator_data, size_t size)
{
(void)allocator_data;
return malloc(size);
}
static void
system_free(void *allocator_data, void *data)
{
(void)allocator_data;
free(data);
}
@ -1620,22 +1624,19 @@ required_field_pack_to_buffer(const ProtobufCFieldDescriptor *field,
break;
}
case PROTOBUF_C_TYPE_MESSAGE: {
uint8_t simple_buffer_scratch[256];
size_t sublen;
const ProtobufCMessage *msg = *(ProtobufCMessage * const *) member;
ProtobufCBufferSimple simple_buffer =
PROTOBUF_C_BUFFER_SIMPLE_INIT(simple_buffer_scratch);
scratch[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
if (msg == NULL)
sublen = 0;
else
sublen = protobuf_c_message_pack_to_buffer(msg, &simple_buffer.base);
rv += uint32_pack(sublen, scratch + rv);
buffer->append(buffer, rv, scratch);
buffer->append(buffer, sublen, simple_buffer.data);
rv += sublen;
PROTOBUF_C_BUFFER_SIMPLE_CLEAR(&simple_buffer);
if (msg == NULL) {
rv += uint32_pack(0, scratch + rv);
buffer->append(buffer, rv, scratch);
} else {
size_t sublen = protobuf_c_message_get_packed_size(msg);
rv += uint32_pack(sublen, scratch + rv);
buffer->append(buffer, rv, scratch);
protobuf_c_message_pack_to_buffer(msg, buffer);
rv += sublen;
}
break;
}
default:
@ -2065,7 +2066,7 @@ static size_t
parse_tag_and_wiretype(size_t len,
const uint8_t *data,
uint32_t *tag_out,
ProtobufCWireType *wiretype_out)
uint8_t *wiretype_out)
{
unsigned max_rv = len > 5 ? 5 : len;
uint32_t tag = (data[0] & 0x7f) >> 3;
@ -2097,9 +2098,9 @@ parse_tag_and_wiretype(size_t len,
/* sizeof(ScannedMember) must be <= (1UL<<BOUND_SIZEOF_SCANNED_MEMBER_LOG2) */
#define BOUND_SIZEOF_SCANNED_MEMBER_LOG2 5
typedef struct _ScannedMember ScannedMember;
typedef struct ScannedMember ScannedMember;
/** Field as it's being read. */
struct _ScannedMember {
struct ScannedMember {
uint32_t tag; /**< Field tag. */
uint8_t wire_type; /**< Field type. */
uint8_t length_prefix_len; /**< Prefix length. */
@ -2134,11 +2135,13 @@ scan_length_prefixed_data(size_t len, const uint8_t *data,
// Protobuf messages should always be less than 2 GiB in size.
// We also want to return early here so that hdr_len + val does
// not overflow on 32-bit systems.
PROTOBUF_C_UNPACK_ERROR("length prefix of %lu is too large", val);
PROTOBUF_C_UNPACK_ERROR("length prefix of %lu is too large",
(unsigned long int)val);
return 0;
}
if (hdr_len + val > len) {
PROTOBUF_C_UNPACK_ERROR("data too short after length-prefix of %lu", val);
PROTOBUF_C_UNPACK_ERROR("data too short after length-prefix of %lu",
(unsigned long int)val);
return 0;
}
return hdr_len + val;
@ -2500,7 +2503,7 @@ parse_required_member(ScannedMember *scanned_member,
{
unsigned len = scanned_member->len;
const uint8_t *data = scanned_member->data;
ProtobufCWireType wire_type = scanned_member->wire_type;
uint8_t wire_type = scanned_member->wire_type;
switch (scanned_member->field->type) {
case PROTOBUF_C_TYPE_ENUM:
@ -2581,7 +2584,7 @@ parse_required_member(ScannedMember *scanned_member,
{
do_free(allocator, bd->data);
}
if (len - pref_len > 0) {
if (len > pref_len) {
bd->data = do_alloc(allocator, len - pref_len);
if (bd->data == NULL)
return FALSE;
@ -2749,7 +2752,9 @@ parse_packed_repeated_member(ScannedMember *scanned_member,
const uint8_t *at = scanned_member->data + scanned_member->length_prefix_len;
size_t rem = scanned_member->len - scanned_member->length_prefix_len;
size_t count = 0;
#if defined(WORDS_BIGENDIAN)
unsigned i;
#endif
switch (field->type) {
case PROTOBUF_C_TYPE_SFIXED32:
@ -2842,13 +2847,15 @@ parse_packed_repeated_member(ScannedMember *scanned_member,
}
break;
case PROTOBUF_C_TYPE_BOOL:
count = rem;
for (i = 0; i < count; i++) {
if (at[i] > 1) {
while (rem > 0) {
unsigned s = scan_varint(rem, at);
if (s == 0) {
PROTOBUF_C_UNPACK_ERROR("bad packed-repeated boolean value");
return FALSE;
}
((protobuf_c_boolean *) array)[i] = at[i];
((protobuf_c_boolean *) array)[count++] = parse_boolean(s, at);
at += s;
rem -= s;
}
break;
default:
@ -3082,7 +3089,7 @@ protobuf_c_message_unpack(const ProtobufCMessageDescriptor *desc,
while (rem > 0) {
uint32_t tag;
ProtobufCWireType wire_type;
uint8_t wire_type;
size_t used = parse_tag_and_wiretype(rem, at, &tag, &wire_type);
const ProtobufCFieldDescriptor *field;
ScannedMember tmp;

View File

@ -19,7 +19,7 @@ sub unanon {
# Detect and replace anonymous unions in .h file.
# Assumes there is only one anonymous union in scope.
while ($content =~ s/^(struct\s+_(\w+)[^}]+)(union\s+{([^}]+)}\s*);/$1$3 u;/sm) {
while ($content =~ s/^(struct\s+(\w+)[^}]+)(union\s+{([^}]+)}\s*);/$1$3 u;/sm) {
my $s = $2;
my $u = $4;
$u =~ s:/\*((?!\*/).)*\*/::sg;