Enlightenment CVS committal
Author : mej
Project : eterm
Module : libast
Dir : eterm/libast/src
Modified Files:
conf.c file.c mem.c strings.c
Log Message:
Tue Jun 29 17:14:13 2004 Michael Jennings (mej)
Some small fixes suggested by Charlie Gordon <[EMAIL PROTECTED]>.
Minor build tweaks...updated to new release number.
----------------------------------------------------------------------
===================================================================
RCS file: /cvsroot/enlightenment/eterm/libast/src/conf.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -3 -r1.20 -r1.21
--- conf.c 29 Jun 2004 18:32:20 -0000 1.20
+++ conf.c 29 Jun 2004 21:18:08 -0000 1.21
@@ -31,7 +31,7 @@
* @author Michael Jennings <[EMAIL PROTECTED]>
*/
-static const char cvs_ident[] = "$Id: conf.c,v 1.20 2004/06/29 18:32:20 mej Exp $";
+static const char cvs_ident[] = "$Id: conf.c,v 1.21 2004/06/29 21:18:08 mej Exp $";
#ifdef HAVE_CONFIG_H
# include <config.h>
@@ -502,9 +502,10 @@
switch (*pbuff) {
case '~':
D_CONF(("Tilde detected.\n"));
- if (!in_single && !in_double && getenv("HOME")) {
- strncpy(newbuff + j, getenv("HOME"), max - j);
- cnt1 = strlen(getenv("HOME")) - 1;
+ EnvVar = getenv("HOME");
+ if (!in_single && !in_double && EnvVar && *EnvVar) {
+ spiftool_safe_strncpy(newbuff + j, getenv("HOME"), max - j);
+ cnt1 = strlen(EnvVar) - 1;
cnt2 = max - j - 1;
j += MIN(cnt1, cnt2);
} else {
@@ -588,8 +589,8 @@
FREE(Command);
if (Output) {
if (*Output) {
+ spiftool_safe_strncpy(newbuff + j, Output, max - j);
l = strlen(Output) - 1;
- strncpy(newbuff + j, Output, max - j);
cnt2 = max - j - 1;
j += MIN(l, cnt2);
} else {
@@ -618,8 +619,8 @@
FREE(Command);
if (Output) {
if (*Output) {
+ spiftool_safe_strncpy(newbuff + j, Output, max - j);
l = strlen(Output) - 1;
- strncpy(newbuff + j, Output, max - j);
cnt2 = max - j - 1;
j += MIN(l, cnt2);
} else {
@@ -656,8 +657,8 @@
break;
}
EnvVar[k] = 0;
- if ((tmp = getenv(EnvVar))) {
- strncpy(newbuff, tmp, max - j);
+ if ((tmp = getenv(EnvVar)) && *tmp) {
+ spiftool_safe_strncpy(newbuff, tmp, max - j);
cnt1 = strlen(tmp) - 1;
cnt2 = max - j - 1;
j += MIN(cnt1, cnt2);
@@ -759,7 +760,7 @@
/* Don't try if it's too long */
if (n > 0 && n <= maxpathlen) {
/* Compose the /path/file combo */
- strncpy(full_path, path, n);
+ memcpy(full_path, path, n);
if (full_path[n - 1] != '/') {
full_path[n++] = '/';
}
===================================================================
RCS file: /cvsroot/enlightenment/eterm/libast/src/file.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -3 -r1.8 -r1.9
--- file.c 3 Feb 2004 23:16:59 -0000 1.8
+++ file.c 29 Jun 2004 21:18:08 -0000 1.9
@@ -28,11 +28,11 @@
* This file contains file-related functions.
*
* @author Michael Jennings <[EMAIL PROTECTED]>
- * $Revision: 1.8 $
- * $Date: 2004/02/03 23:16:59 $
+ * $Revision: 1.9 $
+ * $Date: 2004/06/29 21:18:08 $
*/
-static const char cvs_ident[] = "$Id: file.c,v 1.8 2004/02/03 23:16:59 mej Exp $";
+static const char cvs_ident[] = "$Id: file.c,v 1.9 2004/06/29 21:18:08 mej Exp $";
#ifdef HAVE_CONFIG_H
# include <config.h>
@@ -84,8 +84,7 @@
}
if (len) {
- strncpy(ftemplate, buff, len);
- ftemplate[len - 1] = 0;
+ spiftool_safe_strncpy(ftemplate, buff, len);
}
return (fd);
}
===================================================================
RCS file: /cvsroot/enlightenment/eterm/libast/src/mem.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -3 -r1.20 -r1.21
--- mem.c 10 Mar 2004 22:50:21 -0000 1.20
+++ mem.c 29 Jun 2004 21:18:09 -0000 1.21
@@ -28,11 +28,11 @@
* This file contains the memory management subsystem.
*
* @author Michael Jennings <[EMAIL PROTECTED]>
- * $Revision: 1.20 $
- * $Date: 2004/03/10 22:50:21 $
+ * $Revision: 1.21 $
+ * $Date: 2004/06/29 21:18:09 $
*/
-static const char cvs_ident[] = "$Id: mem.c,v 1.20 2004/03/10 22:50:21 mej Exp $";
+static const char cvs_ident[] = "$Id: mem.c,v 1.21 2004/06/29 21:18:09 mej Exp $";
#ifdef HAVE_CONFIG_H
# include <config.h>
@@ -156,7 +156,7 @@
D_MEM(("Storing as pointer #%lu at %10p (from %10p).\n", memrec->cnt, p,
memrec->ptrs));
p->ptr = ptr;
p->size = size;
- strncpy(p->file, filename, LIBAST_FNAME_LEN);
+ spiftool_safe_strncpy(p->file, filename, LIBAST_FNAME_LEN);
p->file[LIBAST_FNAME_LEN] = 0;
p->line = line;
}
@@ -267,7 +267,7 @@
D_MEM(("Changing variable %s (%10p, %lu -> %10p, %lu)\n", var, oldp, p->size,
newp, size));
p->ptr = newp;
p->size = size;
- strncpy(p->file, filename, LIBAST_FNAME_LEN);
+ spiftool_safe_strncpy(p->file, filename, LIBAST_FNAME_LEN);
p->line = line;
}
@@ -581,6 +581,7 @@
register char *newstr;
register size_t len;
+ ASSERT_RVAL(!SPIF_PTR_ISNULL(str), SPIF_NULL_TYPE_C(char *));
USE_VAR(var);
D_MEM(("Variable %s (%10p) at %s:%lu\n", var, str, NONULL(filename), line));
===================================================================
RCS file: /cvsroot/enlightenment/eterm/libast/src/strings.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -3 -r1.18 -r1.19
--- strings.c 29 Jun 2004 18:32:20 -0000 1.18
+++ strings.c 29 Jun 2004 21:18:09 -0000 1.19
@@ -30,7 +30,7 @@
* @author Michael Jennings <[EMAIL PROTECTED]>
*/
-static const char cvs_ident[] = "$Id: strings.c,v 1.18 2004/06/29 18:32:20 mej Exp $";
+static const char cvs_ident[] = "$Id: strings.c,v 1.19 2004/06/29 21:18:09 mej Exp $";
#ifdef HAVE_CONFIG_H
# include <config.h>
@@ -53,6 +53,7 @@
REQUIRE_RVAL(haystack != SPIF_NULL_TYPE(ptr), SPIF_NULL_TYPE(ptr));
REQUIRE_RVAL(needlelen > 0, SPIF_NULL_TYPE(ptr));
REQUIRE_RVAL(haystacklen > 0, SPIF_NULL_TYPE(ptr));
+ REQUIRE_RVAL(haystacklen > needlelen, SPIF_NULL_TYPE(ptr));
for (i = 0; i < len; i++) {
if (!memcmp(hs + i, n, needlelen)) {
return (hs + i);
@@ -195,6 +196,47 @@
#endif
/**
+ * Safer strncpy() with no NUL padding or wasted calculations.
+ */
+spif_bool_t
+spiftool_safe_strncpy(spif_charptr_t dest, const spif_charptr_t src, spif_int32_t
size)
+{
+ spif_char_t c;
+ spif_charptr_t s = src, pbuff = dest;
+ spif_charptr_t max_pbuff = dest + size - 1;
+
+ ASSERT_RVAL(!SPIF_PTR_ISNULL(dest), FALSE);
+ REQUIRE_RVAL(!SPIF_PTR_ISNULL(src), FALSE);
+ REQUIRE_RVAL(size > 0, FALSE);
+
+ for (; (c = *s) && (pbuff < max_pbuff); s++, pbuff++) {
+ *pbuff = c;
+ }
+ *pbuff = 0;
+ return ((c == 0) ? (TRUE) : (FALSE));
+}
+
+/**
+ * Variant of strncat() which uses the safe strncpy() replacement above.
+ */
+spif_bool_t
+spiftool_safe_strncat(spif_charptr_t dest, const spif_charptr_t src, spif_int32_t
size)
+{
+ spif_int32_t len;
+
+ ASSERT_RVAL(!SPIF_PTR_ISNULL(dest), FALSE);
+ REQUIRE_RVAL(!SPIF_PTR_ISNULL(src), FALSE);
+ REQUIRE_RVAL(size > 0, FALSE);
+
+ len = strnlen(dest, size);
+ if ((len < 0) || (len >= size)) {
+ return FALSE;
+ } else {
+ return spiftool_safe_strncpy(dest + len, size - len, src);
+ }
+}
+
+/**
* Returns a portion of a larger string.
*/
spif_charptr_t
-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
digital self defense, top technical experts, no vendor pitches,
unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs