Mercurial > pidgin
changeset 18148:f160b6e84d0c
Use dynamicly allocated string manipulation here as well to avoid a
MAXPATHLEN. This is untested, as I don't use Zephyr. This also leaks a
string at libpurple uninit. If that's bad, I can add a callback to this
file and call it from the prpl's unload callback.
References #1635
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Sun, 17 Jun 2007 03:00:15 +0000 |
parents | 5653692dcf79 |
children | 4bd4756dc727 |
files | libpurple/core.c libpurple/internal.h libpurple/protocols/zephyr/ZLocations.c |
diffstat | 3 files changed, 39 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/core.c Sun Jun 17 02:52:24 2007 +0000 +++ b/libpurple/core.c Sun Jun 17 03:00:15 2007 +0000 @@ -489,13 +489,33 @@ /* We're only going to duplicate a logs symlink. */ if (!strcmp(entry, "logs")) { + char *link; +#if GLIB_CHECK_VERSION(2,4,0) + GError *err = NULL; + + if ((link = g_file_read_link(name, &err)) == NULL) + { + char *name_utf8 = g_filename_to_utf8(name, -1, NULL, NULL, NULL); + purple_debug_error("core", "Error reading symlink %s: %s. Please report this at http://developer.pidgin.im\n", + name_utf8 ? name_utf8 : name, err->message); + g_free(name_utf8); + g_error_free(err); + g_free(name); + g_dir_close(dir); + g_free(status_file); + g_free(old_user_dir); + return FALSE; + } +#else char buf[MAXPATHLEN]; size_t linklen; if ((linklen = readlink(name, buf, sizeof(buf) - 1) == -1)) { + char *name_utf8 = g_filename_to_utf8(name); purple_debug_error("core", "Error reading symlink %s: %s. Please report this at http://developer.pidgin.im\n", - name, strerror(errno)); + name_utf8, strerror(errno)); + g_free(name_utf8); g_free(name); g_dir_close(dir); g_free(status_file); @@ -504,13 +524,18 @@ } buf[linklen] = '\0'; - logs_dir = g_strconcat(user_dir, G_DIR_SEPARATOR_S "logs", NULL); + /* This way we don't have to GLIB_VERSION_CHECK every g_free(link) below. */ + link = g_strdup(buf); +#endif - if (!strcmp(buf, "../.purple/logs") || !strcmp(buf, logs_dir)) + logs_dir = g_build_filename(user_dir, "logs", NULL); + + if (!strcmp(link, "../.purple/logs") || !strcmp(link, logs_dir)) { /* If the symlink points to the new directory, we're * likely just trying again after a failed migration, * so there's no need to fail here. */ + g_free(link); g_free(logs_dir); continue; } @@ -522,12 +547,13 @@ g_unlink(logs_dir); /* Relative links will most likely still be - * valid from ~/.purple, though not it's not + * valid from ~/.purple, though it's not * guaranteed. Oh well. */ - if (symlink(buf, logs_dir)) + if (symlink(link, logs_dir)) { purple_debug_error("core", "Error symlinking %s to %s: %s. Please report this at http://developer.pidgin.im\n", - logs_dir, buf, strerror(errno)); + logs_dir, link, strerror(errno)); + g_free(link); g_free(name); g_free(logs_dir); g_dir_close(dir); @@ -536,6 +562,7 @@ return FALSE; } + g_free(link); g_free(logs_dir); continue; }
--- a/libpurple/internal.h Sun Jun 17 02:52:24 2007 +0000 +++ b/libpurple/internal.h Sun Jun 17 03:00:15 2007 +0000 @@ -111,16 +111,10 @@ # include <unistd.h> #endif -#ifndef MAXPATHLEN -# define MAXPATHLEN 1024 -#endif - #ifndef HOST_NAME_MAX # define HOST_NAME_MAX 255 #endif -#define PATHSIZE 1024 - #include <glib.h> #if !GLIB_CHECK_VERSION(2,4,0) # define G_MAXUINT32 ((guint32) 0xffffffff)
--- a/libpurple/protocols/zephyr/ZLocations.c Sun Jun 17 02:52:24 2007 +0000 +++ b/libpurple/protocols/zephyr/ZLocations.c Sun Jun 17 03:00:15 2007 +0000 @@ -36,7 +36,8 @@ return (Z_SendLocation(LOGIN_CLASS, LOGIN_USER_FLUSH, ZAUTH, "")); } -static char host[MAXHOSTNAMELEN], mytty[MAXPATHLEN]; +static char host[MAXHOSTNAMELEN]; +static char *mytty = NULL; static int reenter = 0; Code_t Z_SendLocation(class, opcode, auth, format) @@ -87,21 +88,20 @@ } #ifndef X_DISPLAY_MISSING if ((display = getenv("DISPLAY")) && *display) { - (void) strncpy(mytty, display, sizeof(mytty)); + mytty = g_strdup(display); } else { #endif #ifdef WIN32 - strncpy(mytty, "WinPurple", sizeof(mytty)); + mytty = g_strdup("WinPurple"); #else ttyp = ttyname(0); if (ttyp && *ttyp) { p = strchr(ttyp + 1, '/'); - strcpy(mytty, (p) ? p + 1 : ttyp); + mytty = g_strdup((p) ? p + 1 : ttyp); } else { - strncpy(mytty, "unknown", sizeof(mytty)); + mytty = g_strdup("unknown"); } #endif - mytty[sizeof(mytty)-1] = '\0'; #ifndef X_DISPLAY_MISSING } #endif @@ -114,7 +114,6 @@ bptr[1][strlen(bptr[1])-1] = '\0'; bptr[2] = mytty; - if ((retval = ZSendList(¬ice, bptr, 3, auth)) != ZERR_NONE) return (retval);