so, we've already been there, strl* met with great resistance, and then suddenly nothing happened, so it's back on the (well, my) table, this time backed with hard implementation.
so far only wings is done (mostly), no ill effects seen in a couple of hours of use. >From 993d8e6708320fcad4069ffee07227550d51e9af Mon Sep 17 00:00:00 2001 From: Tamas TEVESZ <[email protected]> Date: Mon, 20 Sep 2010 22:25:34 +0200 Subject: [PATCH] Introduce bounded string ops in WINGs The majority of this patch is introducing bounded string ops in WINGs only so far, plus a small number of items encountered along the way: - simplify path normalization in createDir and thereabouts - plug one bof in i18n'd text, but this is just the tip of the iceberg - tweak configure.ac with things discovered Signed-off-by: Tamas TEVESZ <[email protected]> --- WINGs/WINGs/WUtil.h | 7 ++- WINGs/dragsource.c | 2 +- WINGs/findfile.c | 55 ++++++++++++++-------- WINGs/string.c | 127 +++++++++++++++++++++++++++++++++++++++++++++++-- WINGs/userdefaults.c | 10 +++- WINGs/wapplication.c | 46 +++++++++++++----- WINGs/wbrowser.c | 57 ++++++++++++++++++----- WINGs/wfilepanel.c | 113 +++++++++++++++++++++++++++------------------ WINGs/wfontpanel.c | 6 +- WINGs/wtextfield.c | 4 +- configure.ac | 11 +++-- 11 files changed, 329 insertions(+), 109 deletions(-) diff --git a/WINGs/WINGs/WUtil.h b/WINGs/WINGs/WUtil.h index 6849f52..bff5d14 100644 --- a/WINGs/WINGs/WUtil.h +++ b/WINGs/WINGs/WUtil.h @@ -875,7 +875,12 @@ extern int WCErrorCode; /*-------------------------------------------------------------------------*/ - +#ifndef HAVE_STRLCPY +size_t strlcpy(char *, const char *, size_t); +#endif +#ifndef HAVE_STRLCAT +size_t strlcat(char *, const char *, size_t); +#endif #ifdef __cplusplus } diff --git a/WINGs/dragsource.c b/WINGs/dragsource.c index eea0ef5..c1ea68a 100644 --- a/WINGs/dragsource.c +++ b/WINGs/dragsource.c @@ -478,7 +478,7 @@ static void registerDescriptionList(WMScreen * scr, WMView * view, WMArray * ope /* size of XA_STRING info */ for (i = 0; i < count; i++) { - size += strlen(WMGetDragOperationItemText(WMGetFromArray(operationArray, i))) + 1; /* +1 = +NULL */ + size += strlen(WMGetDragOperationItemText(WMGetFromArray(operationArray, i))) + 1 /* NULL */; } /* create text list */ diff --git a/WINGs/findfile.c b/WINGs/findfile.c index 9aad1d7..e528b81 100644 --- a/WINGs/findfile.c +++ b/WINGs/findfile.c @@ -84,9 +84,8 @@ char *wexpandpath(char *path) path++; if (*path == '/' || *path == 0) { home = wgethomedir(); - if (strlen(home) > PATH_MAX) + if (strlcpy(buffer, home, sizeof(buffer)) >= sizeof(buffer)) goto error; - strcat(buffer, home); } else { int j; j = 0; @@ -98,9 +97,8 @@ char *wexpandpath(char *path) path++; } home = getuserhomedir(buffer2); - if (!home || strlen(home) > PATH_MAX) + if (!home || strlcat(buffer, home, sizeof(buffer)) >= sizeof(buffer)) goto error; - strcat(buffer, home); } } @@ -131,17 +129,20 @@ char *wexpandpath(char *path) if ((i += strlen(buffer2) + 2) > PATH_MAX) goto error; buffer[i] = 0; - strcat(buffer, "$("); - strcat(buffer, buffer2); + if (strlcat(buffer, "$(", sizeof(buffer)) >= sizeof(buffer) || + strlcat(buffer, buffer2, sizeof(buffer)) >= sizeof(buffer)) + goto error; if (*(path-1)==')') { if (++i > PATH_MAX) goto error; - strcat(buffer, ")"); + if (strlcat(buffer, ")", sizeof(buffer)) >= sizeof(buffer)) + goto error; } } else { if ((i += strlen(tmp)) > PATH_MAX) goto error; - strcat(buffer, tmp); + if (strlcat(buffer, tmp, sizeof(buffer)) >= sizeof(buffer)) + goto error; } } else { while (*path != 0 && *path != '/') { @@ -154,12 +155,14 @@ char *wexpandpath(char *path) if (!tmp) { if ((i += strlen(buffer2) + 1) > PATH_MAX) goto error; - strcat(buffer, "$"); - strcat(buffer, buffer2); + if (strlcat(buffer, "$", sizeof(buffer)) >= sizeof(buffer) || + strlcat(buffer, buffer2, sizeof(buffer)) >= sizeof(buffer)) + goto error; } else { if ((i += strlen(tmp)) > PATH_MAX) goto error; - strcat(buffer, tmp); + if (strlcat(buffer, tmp, sizeof(buffer)) >= sizeof(buffer)) + goto error; } } } else { @@ -176,8 +179,7 @@ char *wexpandpath(char *path) error: errno = ENAMETOOLONG; wsyserror(_("could not expand %s"), origpath); - /* FIXME: too many functions handle a return value of NULL incorrectly */ - exit(1); + return NULL; } /* return address of next char != tok or end of string whichever comes first */ @@ -251,9 +253,16 @@ char *wfindfile(char *paths, char *file) path = wmalloc(len + flen + 2); path = memcpy(path, tmp, len); path[len] = 0; - if (path[len - 1] != '/') - strcat(path, "/"); - strcat(path, file); + if (path[len - 1] != '/') { + if (strlcat(path, "/", len + flen + 2) >= len + flen + 2) { + wfree(path); + return NULL; + } + } + if (strlcat(path, file, len + flen + 2) >= len + flen + 2) { + wfree(path); + return NULL; + } fullpath = wexpandpath(path); wfree(path); if (fullpath) { @@ -301,8 +310,11 @@ char *wfindfileinlist(char **path_list, char *file) path = wmalloc(len + flen + 2); path = memcpy(path, path_list[i], len); path[len] = 0; - strcat(path, "/"); - strcat(path, file); + if (strlcat(path, "/", len + flen + 2) >= len + flen + 2 || + strlcat(path, file, len + flen + 2) >= len + flen + 2) { + wfree(path); + return NULL; + } /* expand tilde */ fullpath = wexpandpath(path); wfree(path); @@ -358,8 +370,11 @@ char *wfindfileinarray(WMPropList * array, char *file) path = wmalloc(len + flen + 2); path = memcpy(path, p, len); path[len] = 0; - strcat(path, "/"); - strcat(path, file); + if (strlcat(path, "/", len + flen + 2) >= len + flen + 2 || + strlcat(path, file, len + flen + 2) >= len + flen + 2) { + wfree(path); + return NULL; + } /* expand tilde */ fullpath = wexpandpath(path); wfree(path); diff --git a/WINGs/string.c b/WINGs/string.c index d4c426d..45dd62a 100644 --- a/WINGs/string.c +++ b/WINGs/string.c @@ -184,29 +184,144 @@ char *wstrndup(const char *str, size_t len) char *wstrconcat(char *str1, char *str2) { char *str; + size_t slen; if (!str1) return wstrdup(str2); else if (!str2) return wstrdup(str1); - str = wmalloc(strlen(str1) + strlen(str2) + 1); - strcpy(str, str1); - strcat(str, str2); + slen = strlen(str1) + strlen(str2) + 1; + str = wmalloc(slen); + if (strlcpy(str, str1, slen) >= slen || + strlcat(str, str2, slen) >= slen) { + wfree(str); + return NULL; + } return str; } char *wstrappend(char *dst, char *src) { + size_t slen; + if (!dst) return wstrdup(src); else if (!src || *src == 0) return dst; - dst = wrealloc(dst, strlen(dst) + strlen(src) + 1); - strcat(dst, src); - + slen = strlen(dst) + strlen(src) + 1; + dst = wrealloc(dst, slen); + if (strlcat(dst, src, slen) >= slen) + return NULL; return dst; } +#ifndef HAVE_STRLCAT +/* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */ + +/* + * Copyright (c) 1998 Todd C. Miller <[email protected]> + * + * 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 THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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. + */ + +/* + * 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 */ +} +#endif /* HAVE_STRLCAT */ + +#ifndef HAVE_STRLCPY + +/* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */ + +/* + * Copyright (c) 1998 Todd C. Miller <[email protected]> + * + * 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 THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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. + */ + +/* + * Copy src to string dst of size siz. At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns strlen(src); if retval >= siz, truncation occurred. + */ +size_t +strlcpy(char *dst, const char *src, size_t siz) +{ + char *d = dst; + const char *s = src; + size_t n = siz; + + /* Copy as many bytes as will fit */ + if (n != 0) { + while (--n != 0) { + if ((*d++ = *s++) == '\0') + break; + } + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + + return(s - src - 1); /* count does not include NUL */ +} +#endif /* HAVE_STRLCPY */ + diff --git a/WINGs/userdefaults.c b/WINGs/userdefaults.c index ee3a3b7..b1825cf 100644 --- a/WINGs/userdefaults.c +++ b/WINGs/userdefaults.c @@ -60,10 +60,14 @@ char *wusergnusteppath() strcpy(path, gspath); wfree(gspath); } else { - pathlen = strlen(wgethomedir()) + 10; + char *h = wgethomedir(); + if (!h) + return NULL; + pathlen = strlen(h) + 8 /* /GNUstep */ + 1; path = wmalloc(pathlen); - strcpy(path, wgethomedir()); - strcat(path, "/GNUstep"); + if (strlcpy(path, h, pathlen) >= pathlen || + strlcat(path, "/GNUstep", pathlen) >= pathlen) + return NULL; } } diff --git a/WINGs/wapplication.c b/WINGs/wapplication.c index 620e378..a485ce3 100644 --- a/WINGs/wapplication.c +++ b/WINGs/wapplication.c @@ -65,24 +65,41 @@ static char *checkFile(char *path, char *folder, char *ext, char *resource) { char *ret; int extralen; + size_t slen; - extralen = (ext ? strlen(ext) : 0) + (folder ? strlen(folder) : 0) + 4; - ret = wmalloc(strlen(path) + strlen(resource) + extralen + 8); - strcpy(ret, path); + if (!path) + return NULL; + + extralen = (ext ? strlen(ext) + 1 : 0) + (folder ? strlen(folder) + 1 : 0) + 1; + slen = strlen(path) + strlen(resource) + 1 + extralen; + ret = wmalloc(slen); + if (strlcpy(ret, path, slen) >= slen) { + wfree(ret); + return NULL; + } if (folder) { - strcat(ret, "/"); - strcat(ret, folder); + if (strlcat(ret, "/", slen) >= slen || + strlcat(ret, folder, slen) >= slen) { + wfree(ret); + return NULL; + } } if (ext) { - strcat(ret, "/"); - strcat(ret, ext); + if (strlcat(ret, "/", slen) >= slen || + strlcat(ret, ext, slen) >= slen) { + wfree(ret); + return NULL; + } + } + if (strlcat(ret, "/", slen) >= slen || + strlcat(ret, resource, slen) >= slen) { + wfree(ret); + return NULL; } - strcat(ret, "/"); - strcat(ret, resource); if (access(ret, F_OK) != 0) { wfree(ret); - ret = NULL; + return NULL; } return ret; @@ -93,6 +110,7 @@ char *WMPathForResourceOfType(char *resource, char *ext) char *path = NULL; char *tmp, *appdir; int i; + size_t slen; /* * Paths are searched in this order: @@ -128,8 +146,12 @@ char *WMPathForResourceOfType(char *resource, char *ext) return path; } - appdir = wmalloc(strlen(WMApplication.applicationName) + 20); - sprintf(appdir, "Applications/%s.app", WMApplication.applicationName); + slen = strlen(WMApplication.applicationName) + sizeof("Applications/.app"); + appdir = wmalloc(slen); + if (snprintf(appdir, slen, "Applications/%s.app", WMApplication.applicationName) >= slen) { + wfree(appdir); + return NULL; + } if (getenv("GNUSTEP_USER_ROOT")) { path = checkFile(getenv("GNUSTEP_USER_ROOT"), appdir, ext, resource); diff --git a/WINGs/wbrowser.c b/WINGs/wbrowser.c index b539543..ffc1a55 100644 --- a/WINGs/wbrowser.c +++ b/WINGs/wbrowser.c @@ -690,6 +690,7 @@ char *WMGetBrowserPathToColumn(WMBrowser * bPtr, int column) { int i, size; char *path; + size_t slen; WMListItem *item; if (column >= bPtr->usedColumnCount) @@ -709,15 +710,22 @@ char *WMGetBrowserPathToColumn(WMBrowser * bPtr, int column) } /* get the path */ - path = wmalloc(size + (column + 1) * strlen(bPtr->pathSeparator) + 1); + slen = size + (column + 1) * strlen(bPtr->pathSeparator) + 1; + path = wmalloc(slen); /* ignore first / */ *path = 0; for (i = 0; i <= column; i++) { - strcat(path, bPtr->pathSeparator); + if (strlcat(path, bPtr->pathSeparator, slen) >= slen) { + wfree(path); + return NULL; + } item = WMGetListSelectedItem(bPtr->columns[i]); if (!item) break; - strcat(path, item->text); + if (strlcat(path, item->text, slen) >= slen) { + wfree(path); + return NULL; + } } return path; @@ -727,6 +735,7 @@ WMArray *WMGetBrowserPaths(WMBrowser * bPtr) { int column, i, k, size, selNo; char *path; + size_t slen; WMListItem *item, *lastItem; WMArray *paths, *items; @@ -761,11 +770,15 @@ WMArray *WMGetBrowserPaths(WMBrowser * bPtr) for (k = 0; k < selNo; k++) { /* get the path */ lastItem = WMGetFromArray(items, k); - path = wmalloc(size + (lastItem != NULL ? strlen(lastItem->text) : 0)); + slen = size + (lastItem != NULL ? strlen(lastItem->text) : 0); + path = wmalloc(slen); /* ignore first / */ *path = 0; for (i = 0; i <= column; i++) { - strcat(path, bPtr->pathSeparator); + if (strlcat(path, bPtr->pathSeparator, slen) >= slen) { + wfree(path); + return NULL; + } if (i == column) { item = lastItem; } else { @@ -773,7 +786,10 @@ WMArray *WMGetBrowserPaths(WMBrowser * bPtr) } if (!item) break; - strcat(path, item->text); + if (strlcat(path, item->text, slen) >= slen) { + wfree(path); + return NULL; + } } WMAddToArray(paths, path); } @@ -1102,23 +1118,40 @@ static void destroyBrowser(WMBrowser * bPtr) static char *createTruncatedString(WMFont * font, char *text, int *textLen, int width) { - int dLen = WMWidthOfString(font, ".", 1); - char *textBuf = (char *)wmalloc((*textLen) + 4); + size_t slen; + int dLen; + char *textBuf; + + dLen = WMWidthOfString(font, ".", 1); + slen = *textLen + 4; + textBuf = wmalloc(slen); if (width >= 3 * dLen) { int dddLen = 3 * dLen; int tmpTextLen = *textLen; - strcpy(textBuf, text); + if (strlcpy(textBuf, text, slen) >= slen) { + wfree(textBuf); + return NULL; + } while (tmpTextLen && (WMWidthOfString(font, textBuf, tmpTextLen) + dddLen > width)) tmpTextLen--; - strcpy(textBuf + tmpTextLen, "..."); + if (strlcpy(textBuf + tmpTextLen, "...", slen) >= slen) { + wfree(textBuf); + return NULL; + } *textLen = tmpTextLen + 3; } else if (width >= 2 * dLen) { - strcpy(textBuf, ".."); + if (strlcpy(textBuf, "..", slen) >= slen) { + wfree(textBuf); + return NULL; + } *textLen = 2; } else if (width >= dLen) { - strcpy(textBuf, "."); + if (strlcpy(textBuf, ".", slen) >= slen) { + wfree(textBuf); + return NULL; + } *textLen = 1; } else { *textBuf = '\0'; diff --git a/WINGs/wfilepanel.c b/WINGs/wfilepanel.c index 29de7b5..3be297b 100644 --- a/WINGs/wfilepanel.c +++ b/WINGs/wfilepanel.c @@ -69,6 +69,7 @@ static void fillColumn(WMBrowserDelegate * self, WMBrowser * bPtr, int column, W static void deleteFile(); +static void normalizePath(char *s); static void createDir(); static void goHome(); @@ -521,10 +522,15 @@ static void listDirectoryOnColumn(WMFilePanel * panel, int column, char *path) if (strcmp(dentry->d_name, ".") == 0 || strcmp(dentry->d_name, "..") == 0) continue; - strcpy(pbuf, path); + if (strlcpy(pbuf, path, sizeof(pbuf)) >= sizeof(pbuf)) + goto out; + if (strcmp(path, "/") != 0) - strcat(pbuf, "/"); - strcat(pbuf, dentry->d_name); + if (strlcat(pbuf, "/", sizeof(pbuf)) >= sizeof(pbuf)) + goto out; + + if (strlcat(pbuf, dentry->d_name, sizeof(pbuf)) >= sizeof(pbuf)) + goto out; if (stat(pbuf, &stat_buf) != 0) { #ifdef VERBOSE @@ -542,6 +548,7 @@ static void listDirectoryOnColumn(WMFilePanel * panel, int column, char *path) } WMSortBrowserColumnWithComparer(bPtr, column, comparer); +out: closedir(dir); } @@ -592,9 +599,39 @@ static void showError(WMScreen * scr, WMWindow * owner, char *s, char *file) wfree(errStr); } +/* + *---------------------------------------------------------------------- + * normalizePath-- + * Remove multiple consecutive and any trailing slashes from + * a path. + *---------------------------------------------------------------------- + */ +static void normalizePath(char *s) +{ + int i, j, found; + + found = 0; + for(i = 0; s[i]; !found && i++) { + found = 0; + if (s[i] == '/' && s[i+1] == '/') { + int nslash = 1; + found = 1; + i++; + while(s[i+nslash] == '/') + nslash++; + for(j = 0; s[i+j+nslash]; j++) + s[i+j] = s[i+j+nslash]; + s[i+j] = '\0'; + } + } + if (i > 1 && s[--i] == '/') + s[i] = '\0'; +} + static void createDir(WMButton * bPre, WMFilePanel * panel) { char *dirName, *directory, *file, *s; + size_t slen; WMScreen *scr = WMWidgetScreen(panel->win); dirName = WMRunInputPanel(scr, panel->win, _("Create Directory"), @@ -602,39 +639,30 @@ static void createDir(WMButton * bPre, WMFilePanel * panel) if (!dirName) return; - directory = getCurrentFileName(panel); - s = strrchr(directory, '/'); - if (s) - s[1] = 0; + /* if `dirName' is an absolute path, don't mind `directory'. + * normalize as needed (possibly not needed at all?) */ - if (dirName[0] == '/') { - directory[0] = 0; + normalizePath(dirName); + if (*dirName != '/') { + directory = getCurrentFileName(panel); + normalizePath(directory); } else { - while ((s = strstr(directory, "//"))) { - int i; - for (i = 2; s[i] == '/'; i++) ; - strcpy(s, &s[i - 1]); - } - if ((s = strrchr(directory, '/')) && !s[1]) - s[0] = 0; - } - while ((s = strstr(dirName, "//"))) { - int i; - for (i = 2; s[i] == '/'; i++) ; - strcpy(s, &s[i - 1]); + directory = NULL; } - if ((s = strrchr(dirName, '/')) && !s[1]) - s[0] = 0; - - file = wmalloc(strlen(dirName) + strlen(directory) + 4); - sprintf(file, "%s/%s", directory, dirName); - while ((s = strstr(file, "//"))) { - int i; - for (i = 2; s[i] == '/'; i++) ; - strcpy(s, &s[i - 1]); + + slen = strlen(dirName) + (directory ? strlen(directory) + 1 /* "/" */ : 0) + 1 /* NULL */; + file = wmalloc(slen); + memset(file, 0, slen); + if (directory) { + if (strlcat(file, directory, slen) >= slen || + strlcat(file, "/", slen) >= slen) { + goto out; + } } + if (strlcat(file, dirName, slen) >= slen) + goto out; - if (mkdir(file, 0xfff) != 0) { + if (mkdir(file, 00777) != 0) { switch (errno) { case EACCES: showError(scr, panel->win, _("Permission denied."), NULL); @@ -648,8 +676,10 @@ static void createDir(WMButton * bPre, WMFilePanel * panel) } else WMSetFilePanelDirectory(panel, file); +out: wfree(dirName); - wfree(directory); + if (directory) + wfree(directory); wfree(file); } @@ -661,16 +691,9 @@ static void deleteFile(WMButton * bPre, WMFilePanel * panel) WMScreen *scr = WMWidgetScreen(panel->win); file = getCurrentFileName(panel); + normalizePath(file); - while ((s = strstr(file, "//"))) { - int i; - for (i = 2; s[i] == '/'; i++) ; - strcpy(s, &s[i - 1]); - } - if (strlen(file) > 1 && (s = strrchr(file, '/')) && !s[1]) - s[0] = 0; - - if (stat(file, &filestat)) { + if (stat(file, &filestat) != 0) { switch (errno) { case ENOENT: showError(scr, panel->win, _("'%s' does not exist."), file); @@ -690,13 +713,13 @@ static void deleteFile(WMButton * bPre, WMFilePanel * panel) wfree(file); return; } else if (S_ISDIR(filestat.st_mode)) { - int len = strlen(file) + 20; + int len = strlen(_("Delete directory %s?")) + strlen(file) /* %, s covers +1 */; buffer = wmalloc(len); - snprintf(buffer, len, _("Delete directory %s ?"), file); + snprintf(buffer, len, _("Delete directory %s?"), file); } else { - int len = strlen(file) + 15; + int len = strlen(_("Delete file %s?")) + strlen(file) /* %, s covers +1 */; buffer = wmalloc(len); - snprintf(buffer, len, _("Delete file %s ?"), file); + snprintf(buffer, len, _("Delete file %s?"), file); } if (!WMRunAlertPanel(WMWidgetScreen(panel->win), panel->win, diff --git a/WINGs/wfontpanel.c b/WINGs/wfontpanel.c index 0cca5d6..24ee1c5 100644 --- a/WINGs/wfontpanel.c +++ b/WINGs/wfontpanel.c @@ -548,7 +548,7 @@ static void listFamilies(WMScreen * scr, WMFontPanel * panel) WMListItem *item; WM_ITERATE_ARRAY(array, fam, i) { - strcpy(buffer, fam->name); + strlcpy(buffer, fam->name, sizeof(buffer)); /* if it gets truncated, so be it */ item = WMAddListItem(panel->famLs, buffer); item->clientData = fam; @@ -630,7 +630,7 @@ static void familyClick(WMWidget * w, void *data) int top = 0; WMListItem *fitem; - strcpy(buffer, face->typeface); + strlcpy(buffer, face->typeface, sizeof(buffer)); /* if it gets truncated, so be it */ if (strcasecmp(face->typeface, "Roman") == 0) top = 1; if (strcasecmp(face->typeface, "Regular") == 0) @@ -755,7 +755,7 @@ static void setFontPanelFontName(FontPanel * panel, char *family, char *style, d int top = 0; WMListItem *fitem; - strcpy(buffer, face->typeface); + strlcpy(buffer, face->typeface, sizeof(buffer)); if (strcasecmp(face->typeface, "Roman") == 0) top = 1; if (top) diff --git a/WINGs/wtextfield.c b/WINGs/wtextfield.c index e353ee6..db771cc 100644 --- a/WINGs/wtextfield.c +++ b/WINGs/wtextfield.c @@ -399,7 +399,7 @@ void WMInsertTextFieldText(WMTextField * tPtr, char *text, int position) if (position < 0 || position >= tPtr->textLen) { /* append the text at the end */ - strcat(tPtr->text, text); + strlcat(tPtr->text, text, tPtr->bufferSize); tPtr->textLen += len; tPtr->cursorPosition += len; incrToFit(tPtr); @@ -468,7 +468,7 @@ void WMSetTextFieldText(WMTextField * tPtr, char *text) tPtr->bufferSize = tPtr->textLen + TEXT_BUFFER_INCR; tPtr->text = wrealloc(tPtr->text, tPtr->bufferSize); } - strcpy(tPtr->text, text); + strlcpy(tPtr->text, text, tPtr->bufferSize); } tPtr->cursorPosition = tPtr->selection.position = tPtr->textLen; diff --git a/configure.ac b/configure.ac index 516154c..05525be 100644 --- a/configure.ac +++ b/configure.ac @@ -150,6 +150,9 @@ AC_FUNC_VPRINTF AC_CHECK_FUNCS(gethostname select poll strerror strcasecmp strncasecmp \ setsid atexit mallinfo mkstemp) +AC_CHECK_FUNC(strlcat, AC_DEFINE(HAVE_STRLCAT, 1, Check for strlcat)) +AC_CHECK_FUNC(strlcpy, AC_DEFINE(HAVE_STRLCPY, 1, Check for strlcpy)) + dnl Check for inotify dnl ================= AC_CHECK_HEADERS(sys/inotify.h, AC_DEFINE(HAVE_INOTIFY, 1, Check for inotify)) @@ -197,8 +200,8 @@ dnl Checks for typedefs, structures, and compiler characteristics. dnl ============================================================== AC_DECL_SYS_SIGLIST AC_C_CONST -#AC_TYPE_SIZE_T -#AC_TYPE_PID_T +AC_TYPE_SIZE_T +AC_TYPE_PID_T AC_TYPE_SIGNAL @@ -448,7 +451,7 @@ if test "$shape" = yes; then fi dnl XRandR support -dnl ============= +dnl ============== xrandr=yes AC_ARG_ENABLE(XRandR, AS_HELP_STRING([--disable-xrandr], [disable XRandR window extension support]), xrandr=$enableval, xrandr=yes) @@ -835,7 +838,7 @@ AC_SUBST(wprefs_bindir) dnl Enable User Defined Menu thing -dnl ================================== +dnl ============================== AC_ARG_ENABLE(usermenu, AS_HELP_STRING([--enable-usermenu], [user defined menus for applications]), if test "$enableval" = yes; then AC_DEFINE(USER_MENU, 1, [define if you want user defined menus for applications]) -- 1.7.0.4 -- [-] mkdir /nonexistent -- To unsubscribe, send mail to [email protected].
