printk: fix buffer overflow when calling log_prefix function from call_console_drivers
[linux-2.6.git] / kernel / printk.c
index b663c2c..e95c662 100644 (file)
@@ -638,8 +638,19 @@ static void call_console_drivers(unsigned start, unsigned end)
        start_print = start;
        while (cur_index != end) {
                if (msg_level < 0 && ((end - cur_index) > 2)) {
+                       /*
+                        * prepare buf_prefix, as a contiguous array,
+                        * to be processed by log_prefix function
+                        */
+                       char buf_prefix[SYSLOG_PRI_MAX_LENGTH+1];
+                       unsigned i;
+                       for (i = 0; i < ((end - cur_index)) && (i < SYSLOG_PRI_MAX_LENGTH); i++) {
+                               buf_prefix[i] = LOG_BUF(cur_index + i);
+                       }
+                       buf_prefix[i] = '\0'; /* force '\0' as last string character */
+
                        /* strip log prefix */
-                       cur_index += log_prefix(&LOG_BUF(cur_index), &msg_level, NULL);
+                       cur_index += log_prefix((const char *)&buf_prefix, &msg_level, NULL);
                        start_print = cur_index;
                }
                while (cur_index != end) {