Explorar el Código

* Fixed buffer overflow in replace function (still need to be fixed in a more clever way)

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/cacamoo/trunk@1251 92316355-f0b4-4df1-b90c-862c8a59935f
master
jylam hace 18 años
padre
commit
5a751b4408
Se han modificado 1 ficheros con 10 adiciones y 3 borrados
  1. +10
    -3
      src/main.c

+ 10
- 3
src/main.c Ver fichero

@@ -282,6 +282,11 @@ int main (int argc, char **argv)
if(buffer) if(buffer)
free(buffer); free(buffer);


cucul_free_buffer(input_buffer);
cucul_free_buffer(output_buffer);
cucul_free_canvas(canvas);


return 0; return 0;
} }


@@ -510,15 +515,16 @@ char *replace(char *str, char *oldpiece, const char *newpiece)
new_len, old_len, cpy_len; new_len, old_len, cpy_len;
char *c = NULL; char *c = NULL;
char *newstr = NULL; char *newstr = NULL;
char *orig = str;


if(oldpiece==NULL || newpiece==NULL) if(oldpiece==NULL || newpiece==NULL)
return NULL; return NULL;


if ((c = (char *) strstr(str, oldpiece)) == NULL) {
if ((c = (char *) strstr(str, oldpiece)) == NULL)
return str; return str;
}


newstr = malloc(1024);

newstr = malloc(8192); // FIXME


if(newstr == NULL) if(newstr == NULL)
{ {
@@ -552,6 +558,7 @@ char *replace(char *str, char *oldpiece, const char *newpiece)
/* Copy remaining characters from the right of last matched pattern */ /* Copy remaining characters from the right of last matched pattern */
strcpy(newstr+newstr_index, str+str_index); strcpy(newstr+newstr_index, str+str_index);


str = orig;
return newstr; return newstr;
} }




Cargando…
Cancelar
Guardar