mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-02-28 19:13:28 +00:00
Fix very high stack usage in SSL debug code
Use a switch instead of an array. The array was very hollow for some enum types such as mbedtls_ssl_protocol_version (which formerly used small values, but switched to using the protocol encoding as enum values in Mbed TLS 3.2.0). Optimizing compilers know how to compile a switch into a lookup table when the range warrants it. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
44ff5a9208
commit
fd235bc9df
3
ChangeLog.d/ssl_debug_helpers-stack_usage.txt
Normal file
3
ChangeLog.d/ssl_debug_helpers-stack_usage.txt
Normal file
@ -0,0 +1,3 @@
|
||||
Bugfix
|
||||
* Fix very high stack usage in SSL debug code. Reported by Maximilian
|
||||
Gerhardt in #7804.
|
@ -209,24 +209,18 @@ class EnumDefinition:
|
||||
continue
|
||||
member = field.strip().split()[0]
|
||||
translation_table.append(
|
||||
'{space}[{member}] = "{member}",'.format(member=member,
|
||||
space=' '*8)
|
||||
'{space}case {member}:\n{space} return "{member};";'
|
||||
.format(member=member, space=' '*8)
|
||||
)
|
||||
|
||||
body = textwrap.dedent('''\
|
||||
const char *{name}_str( {prototype} in )
|
||||
{{
|
||||
const char * in_to_str[]=
|
||||
{{
|
||||
switch (in) {{
|
||||
{translation_table}
|
||||
}};
|
||||
|
||||
if( in > ( sizeof( in_to_str )/sizeof( in_to_str[0]) - 1 ) ||
|
||||
in_to_str[ in ] == NULL )
|
||||
{{
|
||||
return "UNKNOWN_VALUE";
|
||||
default:
|
||||
return "UNKNOWN_VALUE";
|
||||
}}
|
||||
return in_to_str[ in ];
|
||||
}}
|
||||
''')
|
||||
body = body.format(translation_table='\n'.join(translation_table),
|
||||
|
Loading…
x
Reference in New Issue
Block a user