summaryrefslogtreecommitdiff
path: root/src/lib/efreet
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2016-09-25 23:50:53 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2016-09-25 23:50:53 +0900
commitf4f5a042a658e5b9101dbdf31abc2b2f1e77c325 (patch)
treefadc2fc170995ded842048242262d8445039785a /src/lib/efreet
parentae739184e10d1ba0f9ffb534cf54cdc7b0a7e061 (diff)
efreet - fix command generation by fixing string buffer expansion
so by chance i discovered efreet is doing bad things(tm) when expanding/appending to string buffers to generate commands based off desktop files. the string append basically was buggy, so fixed it by making it a lot simpler and more obvious and now reliable. @fix
Diffstat (limited to 'src/lib/efreet')
-rw-r--r--src/lib/efreet/efreet_desktop_command.c59
1 files changed, 17 insertions, 42 deletions
diff --git a/src/lib/efreet/efreet_desktop_command.c b/src/lib/efreet/efreet_desktop_command.c
index 2748d0c40b..c98ce0fbdf 100644
--- a/src/lib/efreet/efreet_desktop_command.c
+++ b/src/lib/efreet/efreet_desktop_command.c
@@ -846,53 +846,28 @@ efreet_desktop_command_path_absolute(const char *path)
846static char * 846static char *
847efreet_string_append(char *dest, int *size, int *len, const char *src) 847efreet_string_append(char *dest, int *size, int *len, const char *src)
848{ 848{
849 int l; 849 int append_len = strlen(src);
850 int off = 0; 850
851 851 if ((*len + append_len + 1) > *size)
852 l = eina_strlcpy(dest + *len, src, *size - *len); 852 {
853 853 char *dest2 = realloc(dest, *size + append_len + 1024);
854 while (l > *size - *len) 854 if (!dest2) return NULL;
855 { 855
856 char *tmp; 856 dest = dest2;
857 /* we successfully appended this much */ 857 *size += append_len + 1024;
858 off += *size - *len - 1; 858 }
859 *len = *size - 1; 859 strcpy(dest + *len, src);
860 *size += 1024; 860 *len += append_len;
861 tmp = realloc(dest, *size); 861 return dest;
862 if (!tmp)
863 {
864 free(dest);
865 return NULL;
866 }
867 dest = tmp;
868 *(dest + *len) = '\0';
869
870 l = eina_strlcpy(dest + *len, src + off, *size - *len);
871 }
872 *len += l;
873
874 return dest;
875} 862}
876 863
877static char * 864static char *
878efreet_string_append_char(char *dest, int *size, int *len, char c) 865efreet_string_append_char(char *dest, int *size, int *len, char c)
879{ 866{
880 if (*len >= *size - 1) 867 char str[2];
881 {
882 char *tmp;
883 *size += 1024;
884 tmp = realloc(dest, *size);
885 if (!tmp)
886 {
887 free(dest);
888 return NULL;
889 }
890 dest = tmp;
891 }
892 868
893 dest[(*len)++] = c; 869 str[0] = c;
894 dest[*len] = '\0'; 870 str[1] = 0;
895 871 return efreet_string_append(dest, size, len, str);
896 return dest;
897} 872}
898 873