Hi!

I stumbled across an array overflow in the dmenu history patch:
dmenu sometimes crashed when the history file had more than HIST_SIZE
entries.  The attached patch fixes that.

The patch also removes the blank lines that got written to the history
file when a dmenu selection was aborted.

Regards,
Christian
-- 
....Christian.Garbs.....................................http://www.cgarbs.de

Gib Gates keine Chance!
diff -Narup 00_dmenu-2.8_history/main.c 01_dmenu-2.8_fixemptylines/main.c
--- 00_dmenu-2.8_history/main.c 2007-04-03 20:52:57.000000000 +0200
+++ 01_dmenu-2.8_fixemptylines/main.c   2007-04-03 20:57:17.000000000 +0200
@@ -83,8 +83,9 @@ writehistory(char *command) {
     if( (f = fopen(histfile, "w")) ) {
         fputs(command, f); fputc('\n', f);
         for(; i<HIST_SIZE && i<j; i++) {
-            if(strcmp(command, hist[i]) != 0) 
+            if(strcmp(command, hist[i]) != 0) {
                 fputs(hist[i], f); fputc('\n', f);
+           }
         }
         fclose(f);
         return 1;
@@ -103,7 +104,7 @@ readhistory (void) {
         return 0;
 
     if( (f = fopen(histfile, "r+")) ) {
-        while(fgets(buf, sizeof buf, f))  
+        while(fgets(buf, sizeof buf, f) && (hcnt < HIST_SIZE))  
             strncpy(hist[hcnt++], buf, (strlen(buf) <= 1024) ? strlen(buf): 
1024 );
         fclose(f);
     }

Attachment: signature.asc
Description: Digital signature

Reply via email to