Просмотр исходного кода

vqsim: Check length of copied optarg

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Christine Caulfield <ccaulfie@redhat.com>
Jan Friesse 6 лет назад
Родитель
Сommit
0390200dd4
1 измененных файлов с 6 добавлено и 2 удалено
  1. 6 2
      vqsim/vqmain.c

+ 6 - 2
vqsim/vqmain.c

@@ -759,7 +759,11 @@ int main(int argc, char **argv)
 	while ((ch = getopt (argc, argv, "c:o:nh")) != EOF) {
 	while ((ch = getopt (argc, argv, "c:o:nh")) != EOF) {
 		switch (ch) {
 		switch (ch) {
 		case 'c':
 		case 'c':
-			strncpy(corosync_config_file, optarg, sizeof(corosync_config_file));
+			if (strlen(optarg) >= sizeof(sizeof(corosync_config_file) - 1)) {
+				fprintf(stderr, "Corosync config file path too long\n");
+				exit(1);
+			}
+			strncpy(corosync_config_file, optarg, sizeof(corosync_config_file) - 1);
 			break;
 			break;
 		case 'o':
 		case 'o':
 			output_file_name = optarg;
 			output_file_name = optarg;
@@ -777,7 +781,7 @@ int main(int argc, char **argv)
 		output_file = fopen(output_file_name, "w");
 		output_file = fopen(output_file_name, "w");
 		if (!output_file) {
 		if (!output_file) {
 			fprintf(stderr, "Unable to open %s for output: %s\n", output_file_name, strerror(errno));
 			fprintf(stderr, "Unable to open %s for output: %s\n", output_file_name, strerror(errno));
-			exit(-1);
+			exit(3);
 		}
 		}
 	}
 	}
 	else {
 	else {