Blame SOURCES/resize-proc-cmdline-buffer.patch

b1da00
From 6e15c8b20b2ff852fcc638948eb88ea5dfa4a916 Mon Sep 17 00:00:00 2001
b1da00
From: Ray Strode <rstrode@redhat.com>
b1da00
Date: Fri, 10 Oct 2014 16:11:01 -0400
b1da00
Subject: [PATCH] main: fix incorrectly sized buffer for /proc/cmdline
b1da00
b1da00
We assume /proc/cmdline will be no more than 512 bytes (including NUL).
b1da00
It can actually be 4096 bytes (excluding NUL).
b1da00
b1da00
This commit makes sure we allocate enough space for it and its NUL.
b1da00
---
b1da00
 src/main.c | 5 ++---
b1da00
 1 file changed, 2 insertions(+), 3 deletions(-)
b1da00
b1da00
diff --git a/src/main.c b/src/main.c
b1da00
index 4101550..d5f4f4d 100644
b1da00
--- a/src/main.c
b1da00
+++ b/src/main.c
b1da00
@@ -30,61 +30,61 @@
b1da00
 #include <fcntl.h>
b1da00
 #include <stdlib.h>
b1da00
 #include <stdio.h>
b1da00
 #include <sysexits.h>
b1da00
 #include <sys/ioctl.h>
b1da00
 #include <unistd.h>
b1da00
 #include <wchar.h>
b1da00
 #include <paths.h>
b1da00
 #include <assert.h>
b1da00
 #include <values.h>
b1da00
 
b1da00
 #include <linux/kd.h>
b1da00
 #include <linux/vt.h>
b1da00
 
b1da00
 #include "ply-buffer.h"
b1da00
 #include "ply-command-parser.h"
b1da00
 #include "ply-boot-server.h"
b1da00
 #include "ply-boot-splash.h"
b1da00
 #include "ply-device-manager.h"
b1da00
 #include "ply-event-loop.h"
b1da00
 #include "ply-hashtable.h"
b1da00
 #include "ply-list.h"
b1da00
 #include "ply-logger.h"
b1da00
 #include "ply-renderer.h"
b1da00
 #include "ply-terminal-session.h"
b1da00
 #include "ply-trigger.h"
b1da00
 #include "ply-utils.h"
b1da00
 #include "ply-progress.h"
b1da00
 
b1da00
 #ifndef PLY_MAX_COMMAND_LINE_SIZE
b1da00
-#define PLY_MAX_COMMAND_LINE_SIZE 512
b1da00
+#define PLY_MAX_COMMAND_LINE_SIZE 4097
b1da00
 #endif
b1da00
 
b1da00
 #define BOOT_DURATION_FILE     PLYMOUTH_TIME_DIRECTORY "/boot-duration"
b1da00
 #define SHUTDOWN_DURATION_FILE PLYMOUTH_TIME_DIRECTORY "/shutdown-duration"
b1da00
 
b1da00
 typedef enum {
b1da00
   PLY_MODE_BOOT,
b1da00
   PLY_MODE_SHUTDOWN,
b1da00
   PLY_MODE_UPDATES
b1da00
 } ply_mode_t;
b1da00
 
b1da00
 typedef struct 
b1da00
 {
b1da00
   const char    *keys;
b1da00
   ply_trigger_t *trigger;
b1da00
 } ply_keystroke_watch_t;
b1da00
 
b1da00
 typedef struct 
b1da00
 {
b1da00
   enum {PLY_ENTRY_TRIGGER_TYPE_PASSWORD,
b1da00
         PLY_ENTRY_TRIGGER_TYPE_QUESTION}
b1da00
         type;
b1da00
   const char    *prompt;
b1da00
   ply_trigger_t *trigger;
b1da00
 } ply_entry_trigger_t;
b1da00
 
b1da00
 typedef struct
b1da00
 {
b1da00
   ply_event_loop_t *loop;
b1da00
   ply_boot_server_t *boot_server;
b1da00
@@ -1782,68 +1782,67 @@ detach_from_running_session (state_t *state)
b1da00
 
b1da00
   if (!state->is_attached)
b1da00
     return;
b1da00
 
b1da00
   ply_trace ("detaching from terminal session");
b1da00
   ply_terminal_session_detach (state->session);
b1da00
   state->is_redirected = false;
b1da00
   state->is_attached = false;
b1da00
 }
b1da00
 
b1da00
 static bool
b1da00
 get_kernel_command_line (state_t *state)
b1da00
 {
b1da00
   int fd;
b1da00
   const char *remaining_command_line;
b1da00
   char *key;
b1da00
 
b1da00
   if (state->kernel_command_line_is_set)
b1da00
     return true;
b1da00
 
b1da00
   ply_trace ("opening /proc/cmdline");
b1da00
   fd = open ("/proc/cmdline", O_RDONLY);
b1da00
 
b1da00
   if (fd < 0)
b1da00
     {
b1da00
       ply_trace ("couldn't open it: %m");
b1da00
       return false;
b1da00
     }
b1da00
 
b1da00
   ply_trace ("reading kernel command line");
b1da00
-  if (read (fd, state->kernel_command_line, sizeof (state->kernel_command_line)) < 0)
b1da00
+  if (read (fd, state->kernel_command_line, sizeof (state->kernel_command_line) - 1) < 0)
b1da00
     {
b1da00
       ply_trace ("couldn't read it: %m");
b1da00
       close (fd);
b1da00
       return false;
b1da00
     }
b1da00
 
b1da00
-
b1da00
   /* we now use plymouth.argument for kernel commandline arguments.
b1da00
    * It used to be plymouth:argument. This bit just rewrites all : to be .
b1da00
    */
b1da00
   remaining_command_line = state->kernel_command_line;
b1da00
   while ((key = strstr (remaining_command_line, "plymouth:")) != NULL)
b1da00
     {
b1da00
       char *colon;
b1da00
 
b1da00
       colon = key + strlen ("plymouth");
b1da00
       *colon = '.';
b1da00
 
b1da00
       remaining_command_line = colon + 1;
b1da00
     }
b1da00
   ply_trace ("Kernel command line is: '%s'", state->kernel_command_line);
b1da00
 
b1da00
   close (fd);
b1da00
 
b1da00
   state->kernel_command_line_is_set = true;
b1da00
   return true;
b1da00
 }
b1da00
 
b1da00
 static void
b1da00
 check_verbosity (state_t *state)
b1da00
 {
b1da00
   const char *stream;
b1da00
   const char *path;
b1da00
 
b1da00
   ply_trace ("checking if tracing should be enabled");
b1da00
 
b1da00
   stream = command_line_get_string_after_prefix (state->kernel_command_line,
b1da00
-- 
b1da00
1.8.3.1
b1da00