linaro-swg / optee_examples

OP-TEE Sample Applications
Other
163 stars 140 forks source link

plugins: fix formatting string of the syslog() #93

Closed imlk0 closed 2 years ago

imlk0 commented 2 years ago

There is a over-print in current version of syslog_plugin.c, since (const char*) data is not NULL terminated.

# optee_example_plugins 
Work logic: REE --> plugin TA --> syslog plugin in REE --> syslog
See the log from TEE through 'journalctl'

Attempt #1: TEEC_InvokeCommand() success; res=0 orig=0x4
Attempt #2: TEEC_InvokeCommand() success; res=0 orig=0x4
Attempt #3: TEEC_InvokeCommand() success; res=0 orig=0x4
Attempt #4: TEEC_InvokeCommand() success; res=0 orig=0x4
Attempt #5: TEEC_InvokeCommand() success; res=0 orig=0x4
# tail -f /var/log/messages 
Apr 29 00:53:16 buildroot daemon.info tee-supplicant[137]: Hello, plugin! value = 0x0^RX_^H~^B
Apr 29 00:53:18 buildroot daemon.info tee-supplicant[137]: Hello, plugin! value = 0x1
Apr 29 00:53:20 buildroot daemon.info tee-supplicant[137]: Hello, plugin! value = 0x2y0^Y7m^U^A
Apr 29 00:53:22 buildroot daemon.info tee-supplicant[137]: Hello, plugin! value = 0x3
Apr 29 00:53:24 buildroot daemon.info tee-supplicant[137]: Hello, plugin! value = 0x4^Mji*

https://www.cplusplus.com/reference/cstdio/printf/

.number:

For s: this is the maximum number of characters to be printed. By default all characters are printed until the ending null character is encountered.

Can be fixed by replace %*s with %.*s :)

# optee_example_plugins 
Work logic: REE --> plugin TA --> syslog plugin in REE --> syslog
See the log from TEE through 'journalctl'

Attempt #1: TEEC_InvokeCommand() success; res=0 orig=0x4
Attempt #2: TEEC_InvokeCommand() success; res=0 orig=0x4
Attempt #3: TEEC_InvokeCommand() success; res=0 orig=0x4
Attempt #4: TEEC_InvokeCommand() success; res=0 orig=0x4
Attempt #5: TEEC_InvokeCommand() success; res=0 orig=0x4
# tail -f /var/log/messages 
Apr 29 01:54:07 buildroot daemon.info tee-supplicant[138]: Hello, plugin! value = 0x0
Apr 29 01:54:09 buildroot daemon.info tee-supplicant[138]: Hello, plugin! value = 0x1
Apr 29 01:54:11 buildroot daemon.info tee-supplicant[138]: Hello, plugin! value = 0x2
Apr 29 01:54:13 buildroot daemon.info tee-supplicant[138]: Hello, plugin! value = 0x3
Apr 29 01:54:15 buildroot daemon.info tee-supplicant[138]: Hello, plugin! value = 0x4
etienne-lms commented 2 years ago

Acked-by: Etienne Carriere <etienne.carriere@linaro.org> with commit message fixed. @KB5201314, could you add a description line + s-o-b and review tags, as expected in optee changes, e.g.:

plugins: fix formatting string of the syslog()

Fixes over-print in current version of syslog_plugin.c due to passed string maybe not
being NULL terminated. Using %.*s format specifier fixes the issue.

Signed-off-by: ...
Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
Acked-by: Etienne Carriere <etienne.carriere@linaro.org>
imlk0 commented 2 years ago

@etienne-lms Description line added and tags applied. Thank you.