Skip to contentSkip to conversation

Fix core dump on huge switch

PATCH Applied Christopher Li 2 participants 2 messages Feb 10, 2007 – Feb 26, 2007 Sparse checker

lore
Share & tools
lore

Christopher Li

author maintainer
#0 lore raw

PATCH 1/1 Fix core dump on huge switch

Bump up the size of the instruction buffer. vt_ioctl.c has a huge switch statement causing sparse over flow the instruction buffer.

linearize.c +4 -1
Index: sparse/linearize.c
===================================================================
@@ -272,7 +272,7 @@ static char *show_asm(char *buf, struct 
 const char *show_instruction(struct instruction *insn)
 {
 	int opcode = insn->opcode;
-	static char buffer[1024];
+	static char buffer[4096];
 	char *buf;
 
 	buf = buffer;
@@ -457,6 +457,9 @@ const char *show_instruction(struct inst
 	default:
 		break;
 	}
+
+	if (buf >= buffer + sizeof buffer)
+		die("instruction buffer overflowed %d\n", buf - buffer);
 	do { --buf; } while (*buf == ' ');
 	*++buf = 0;
 	return buffer;
#1 lore raw
Quoted 5 lines · Christopher Li

Bump up the size of the instruction buffer. vt_ioctl.c has a huge switch statement causing sparse over flow the instruction buffer.

I've applied this fix for now, to solve the immediate problem; thanks for the patch.

Ideally I'd like to see some solution that grows the buffer as needed.

I also committed one minor style fix after your patch:

linearize.c const char *show_instruction(struct inst · line 461

Quoted 1 line
linearize.c +1 -0
+	if (buf >= buffer + sizeof buffer)

Please use parentheses with sizeof, per the Linux Documentation/CodingStyle.

- Josh Triplett