linux
An uninitialized string may be displayed if !CONFIG_RCU_FAST_NO_HZ.
Bug fixed by commit 1c17e4d4437
Type | UninitializedVariable |
Config | "TREE_RCU && RCU_CPU_STALL_INFO && !RCU_FAST_NO_HZ" (3rd degree) |
Fix-in | code |
Location | kernel/ |
extern int printf (const char *__restrict __format, ...); extern int sprintf (char *__restrict __s, const char *__restrict __format, ...) __attribute__ ((__nothrow__)); #ifdef CONFIG_RCU_CPU_STALL_INFO #ifdef CONFIG_RCU_FAST_NO_HZ void print_cpu_stall_fast_no_hz(char *cp, int cpu) { sprintf(cp, "foobar"); } #else /* #ifdef CONFIG_RCU_FAST_NO_HZ */ void print_cpu_stall_fast_no_hz(char *cp, int cpu) { // (3) } #endif /* #else #ifdef CONFIG_RCU_FAST_NO_HZ */ void print_cpu_stall_info(int cpu) { char fast_no_hz[72]; print_cpu_stall_fast_no_hz(fast_no_hz, cpu); // (2) printf("\t%d: %s\n", cpu, fast_no_hz); // ERROR (4) } #else /* #ifdef CONFIG_RCU_CPU_STALL_INFO */ void print_cpu_stall_info(int cpu) { printf(" %d", cpu); } #endif /* #else #ifdef CONFIG_RCU_CPU_STALL_INFO */ int main(void) { #ifdef CONFIG_RCU_CPU_STALL_INFO print_cpu_stall_info(0); // (1) #endif return 0; }
diff --git a/simple/1c17e4d.c b/simple/1c17e4d.c --- a/simple/1c17e4d.c +++ b/simple/1c17e4d.c @@ -14,6 +14,7 @@ #else /* #ifdef CONFIG_RCU_FAST_NO_HZ */ void print_cpu_stall_fast_no_hz(char *cp, int cpu) { // (3) + *cp = '\0'; } #endif /* #else #ifdef CONFIG_RCU_FAST_NO_HZ */
#include <stdio.h> int main(int argc, char** argv) { #ifdef CONFIG_RCU_CPU_STALL_INFO // print_cpu_stall_info(0); char fast_no_hz[72]; int cpu = 0; #ifdef CONFIG_RCU_FAST_NO_HZ sprintf(fast_no_hz, "foobar"); #else #endif printf("\t%d: %s\n", cpu, fast_no_hz); // ERROR #else printf(" %d", cpu); #endif return 0; }
. call kernel/rcutree_plugin.h:2249: print_cpu_stall_info() . 2264: print_cpu_stall_fast_no_hz(fast_no_hz, cpu); .. call kernel/rcutree_plugin.h:2225:print_cpu_stall_fast_no_hz() .. 2227: } // fast_no_hz is left uninitialized . ERROR 2265: printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",