all repos — tint2 @ 67e25b8102c4c0beabb5ec20fcfad5303b5519b2

fork of the tint2 desktop panel for my custom setup - only minimized windows across all desktops for the taskbar

Replace strcat with strlcat
o9000 mrovi9000@gmail.com
commit

67e25b8102c4c0beabb5ec20fcfad5303b5519b2

parent

c96201930b816ff33db23fac8aadba079dc7bf4f

M CMakeLists.txtCMakeLists.txt

@@ -157,6 +157,7 @@ src/util/strnatcmp.c

src/util/timer.c src/util/cache.c src/util/color.c + src/util/strlcat.c src/util/print.c src/util/gradient.c src/util/test.c
M src/tint2conf/CMakeLists.txtsrc/tint2conf/CMakeLists.txt

@@ -25,6 +25,7 @@ ../util/cache.c

../util/timer.c ../config.c ../util/server.c + ../util/strlcat.c ../launcher/apps-common.c ../launcher/icon-theme-common.c md4.c
M src/tint2conf/properties.csrc/tint2conf/properties.c

@@ -20,6 +20,7 @@

#include "gui.h" #include "background_gui.h" #include "gradient_gui.h" +#include "strlcat.h" GtkWidget *panel_width, *panel_height, *panel_margin_x, *panel_margin_y, *panel_padding_x, *panel_padding_y, *panel_spacing;

@@ -1256,7 +1257,8 @@ }

char *get_panel_items() { - char *result = calloc(1, 256 * sizeof(char)); + size_t buf_size = 256; + char *result = calloc(buf_size, 1); GtkTreeModel *model = GTK_TREE_MODEL(panel_items); GtkTreeIter i;

@@ -1267,7 +1269,7 @@

while (1) { gchar *v; gtk_tree_model_get(model, &i, itemsColValue, &v, -1); - strcat(result, v); + strlcat(result, v, buf_size); if (!gtk_tree_model_iter_next(model, &i)) { break;
M src/tint2conf/properties_rw.csrc/tint2conf/properties_rw.c

@@ -69,23 +69,23 @@

if (!config_has_panel_items) { char panel_items[256]; panel_items[0] = 0; - strcat(panel_items, "T"); + strlcat(panel_items, "T", sizeof(panel_items)); if (config_has_battery) { if (config_battery_enabled) - strcat(panel_items, "B"); + strlcat(panel_items, "B", sizeof(panel_items)); } else { if (no_items_battery_enabled) - strcat(panel_items, "B"); + strlcat(panel_items, "B", sizeof(panel_items)); } if (config_has_systray) { if (config_systray_enabled) - strcat(panel_items, "S"); + strlcat(panel_items, "S", sizeof(panel_items)); } else { if (no_items_systray_enabled) - strcat(panel_items, "S"); + strlcat(panel_items, "S", sizeof(panel_items)); } if (no_items_clock_enabled) - strcat(panel_items, "C"); + strlcat(panel_items, "C", sizeof(panel_items)); set_panel_items(panel_items); } }

@@ -242,13 +242,13 @@

char sides[10]; sides[0] = '\0'; if (sideTop) - strcat(sides, "T"); + strlcat(sides, "T", sizeof(sides)); if (sideBottom) - strcat(sides, "B"); + strlcat(sides, "B", sizeof(sides)); if (sideLeft) - strcat(sides, "L"); + strlcat(sides, "L", sizeof(sides)); if (sideRight) - strcat(sides, "R"); + strlcat(sides, "R", sizeof(sides)); fprintf(fp, "border_sides = %s\n", sides); fprintf(fp, "border_content_tint_weight = %d\n", (int)(border_weight));
M src/tint2conf/theme_view.csrc/tint2conf/theme_view.c

@@ -207,7 +207,7 @@ gtk_tree_model_get(model, &iter, COL_THEME_FILE, &path, COL_FORCE_REFRESH, &force_refresh, -1);

char hash[MD4_HEX_SIZE + 4]; md4hexf(path, hash); - strcat(hash, ".png"); + strlcat(hash, ".png", sizeof(hash)); gchar *snap = g_build_filename(g_get_user_cache_dir(), "tint2", hash, NULL); pixbuf = force_refresh ? NULL : gdk_pixbuf_new_from_file(snap, NULL);
M src/util/common.csrc/util/common.c

@@ -461,9 +461,10 @@ char *expand_tilde(const char *s)

{ const gchar *home = g_get_home_dir(); if (home && (strcmp(s, "~") == 0 || strstr(s, "~/") == s)) { - char *result = calloc(strlen(home) + strlen(s), 1); - strcat(result, home); - strcat(result, s + 1); + size_t buf_size = strlen(home) + strlen(s); + char *result = calloc(buf_size, 1); + strlcat(result, home, buf_size); + strlcat(result, s + 1, buf_size); return result; } else { return strdup(s);

@@ -476,14 +477,16 @@ const gchar *home = g_get_home_dir();

if (!home) return strdup(s); - char *home_slash = calloc(strlen(home) + 2, 1); - strcat(home_slash, home); - strcat(home_slash, "/"); + size_t buf_size = strlen(home) + 2; + char *home_slash = calloc(buf_size, 1); + strlcat(home_slash, home, buf_size); + strlcat(home_slash, "/", buf_size); if ((strcmp(s, home) == 0 || strstr(s, home_slash) == s)) { - char *result = calloc(strlen(s) - strlen(home) + 2, 1); - strcat(result, "~"); - strcat(result, s + strlen(home)); + size_t buf_size = strlen(s) - strlen(home) + 2; + char *result = calloc(buf_size, 1); + strlcat(result, "~", buf_size); + strlcat(result, s + strlen(home), buf_size); free(home_slash); return result; } else {
M src/util/common.hsrc/util/common.h

@@ -13,6 +13,7 @@ #include <Imlib2.h>

#include <pango/pangocairo.h> #include "area.h" #include "colors.h" +#include "strlcat.h" #define MAX3(a, b, c) MAX(MAX(a, b), c) #define MIN3(a, b, c) MIN(MIN(a, b), c)
A src/util/strlcat.c

@@ -0,0 +1,59 @@

+/* $NetBSD: strlcat.c,v 1.4 2005/05/16 06:55:48 lukem Exp $ */ +/* from NetBSD: strlcat.c,v 1.16 2003/10/27 00:12:42 lukem Exp */ +/* from OpenBSD: strlcat.c,v 1.10 2003/04/12 21:56:39 millert Exp */ + +/* + * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER BE LIABLE + * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <stddef.h> +#include <stdint.h> + +#include "strlcat.h" + +/* + * Appends src to string dst of size siz (unlike strncat, siz is the + * full size of dst, not space left). At most siz-1 characters + * will be copied. Always NUL terminates (unless siz <= strlen(dst)). + * Returns strlen(src) + MIN(siz, strlen(initial dst)). + * If retval >= siz, truncation occurred. + */ +size_t +strlcat(char *dst, const char *src, size_t siz) +{ + char *d = dst; + const char *s = src; + size_t n = siz; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end */ + while (n-- != 0 && *d != '\0') + d++; + dlen = d - dst; + n = siz - dlen; + + if (n == 0) + return(dlen + strlen(s)); + while (*s != '\0') { + if (n != 1) { + *d++ = *s; + n--; + } + s++; + } + *d = '\0'; + + return(dlen + (s - src)); /* count does not include NUL */ +}
A src/util/strlcat.h

@@ -0,0 +1,16 @@

+#ifndef STRLCAT_H +#define STRLCAT_H + +#include <stddef.h> +#include <stdint.h> + +/* + * Appends src to string dst of size siz (unlike strncat, siz is the + * full size of dst, not space left). At most siz-1 characters + * will be copied. Always NUL terminates (unless siz <= strlen(dst)). + * Returns strlen(src) + MIN(siz, strlen(initial dst)). + * If retval >= siz, truncation occurred. + */ +size_t strlcat(char *dst, const char *src, size_t siz); + +#endif
M tint2.filestint2.files

@@ -58,6 +58,8 @@ src/util/blur.c

src/util/blur.h src/util/common.c src/util/common.h +src/util/strlcat.c +src/util/strlcat.h src/util/timer.c src/util/timer.h src/util/window.c
M tint2.includestint2.includes

@@ -22,6 +22,11 @@ /usr/include/libpng12

/usr/include/librsvg-2.0 /usr/include/gdk-pixbuf-2.0 /usr/include/startup-notification-1.0 +/usr/include/gtk-2.0 +/usr/lib/x86_64-linux-gnu/gtk-2.0/include +/usr/include/atk-1.0 +/usr/include/gio-unix-2.0 +/usr/include/harfbuzz /usr/include po src/tint2conf/po