Browse Source

Draw: Fix possible segfault in textw (securize strcpy)

Martin Duquesnoy 14 years ago
parent
commit
321669eb3a
2 changed files with 15 additions and 7 deletions
  1. 1 1
      CMakeLists.txt
  2. 14 6
      src/draw.c

+ 1 - 1
CMakeLists.txt

@@ -55,7 +55,7 @@ add_executable(wmfs ${wmfs_src})
 set(VERSION "WMFS-201003")
 
 # FLAGS
-set(CFLAGS "-g -Wall -ansi")
+set(CFLAGS "-Wall -ansi")
 set(CMAKE_C_FLAGS ${CFLAGS})
 
 # Linker FLAGS

+ 14 - 6
src/draw.c

@@ -57,10 +57,13 @@ draw_text(Drawable d, int x, int y, char* fg, int pad, char *str)
 
      ostr = _strdup(str);
 
-     ni = parse_image_block(im, str);
+     if(strstr(str, "i["))
+     {
+          ni = parse_image_block(im, str);
 
-     for(i = 0; i < ni; ++i)
-          draw_image(d, im[i].x, im[i].y, im[i].w, im[i].h, im[i].name);
+          for(i = 0; i < ni; ++i)
+               draw_image(d, im[i].x, im[i].y, im[i].w, im[i].h, im[i].name);
+     }
 #endif /* HAVE_IMLIB */
 
      /* Transform X Drawable -> Xft Drawable */
@@ -78,7 +81,9 @@ draw_text(Drawable d, int x, int y, char* fg, int pad, char *str)
      XftDrawDestroy(xftd);
 
 #ifdef HAVE_IMLIB
-     strcpy(str, ostr);
+     if(strstr(ostr, "i["))
+          strcpy(str, ostr);
+
      IFREE(ostr);
 #endif /* HAVE_IMLIB */
 
@@ -165,13 +170,16 @@ textw(char *text)
 
      ostr = _strdup(text);
 
-     parse_image_block(im, text);
+     if(strstr(text, "i["))
+          parse_image_block(im, text);
 #endif /* HAVE_IMLIB */
 
      XftTextExtentsUtf8(dpy, font, (FcChar8 *)text, strlen(text), &gl);
 
 #ifdef HAVE_IMLIB
-     strcpy(text, ostr);
+     if(strstr(ostr, "i["))
+          strcpy(text, ostr);
+
      IFREE(ostr);
 #endif /* HAVE_IMLIB */