Short: terminal_colour() exceeds buffer limits Date: Mon, 11 Oct 1999 13:03:24 +0200 From: Christian Mudra <c_mudra@informatik.uni-kl.de> To: lars@bearnip.com Type: Bug State: Done - corrected in 3.2.8-dev.151 > Ich muesste wissen, was genau in m, width und indent drinsteht. str = "The smell of horses is very strong in here. You see many closed boxes from which you hear the neigh and stomping of several horses. If you want to rent a horse, call for the groom. A sign is nailed to the door of one of the boxes. There is one obvious exit: north. " // nach "closed" in der ersten Zeile ist ein \n m = ([ // mit den entsprechenden Farbcode in den strings, // der debug-output war sehr farbig fuer mich :-) // ich hab die Farbcodes hier reinkopiert, wobei // ESC als "\e" definiert ist. "BG_CYAN": ESC"[46m", "BOLD": ESC"[1m", "CHANNEL": ESC"[34m", "BG_BLUE": ESC"[44m", "YELLOW": ESC"[33m", "BG_GREEN": ESC"[42m", "NORMAL": ESC"[0m", "INVERSE": ESC"[7m", "MAGENTA": ESC"[45m", "BG_BLACK": ESC"[40m", "BG_RED": ESC"[41m", "BG_YELLOW": ESC"[43m", "BG_WHITE": ESC"[47m", "BLINK": ESC"[5m", "RED": ESC"[31m", "BLACK": ESC"[30m", "UNDERSCORE": ESC"[4m", "BG_MAGENTA": ESC"[35m", "GREEN": ESC"[32m", "BLUE": ESC"[34m", "CYAN": ESC"[36m", "WHITE": ESC"[37m", "TELL": "", ]) width = 78 indent = 10 Damit ein terminal_colour(str,m,width-indent), und man erhaelt Partial string too long (> 268). program: kernel/simul/string.c, object: kernel/simul_efun line 105 ------ Analysis ------ The crucial fact is that the string to format containes extraneous spaces. These spaces are not counted for the result, but are still present when the string is formatted. And because the temporary string is allocated to just the length of the result, we get an overflow. ------ Solution ------ Count the number of characters to omit from the incoming string and add this count to the size of the allocated temporary string.