summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2004-02-04 20:28:51 +0000
committerJeremy Allison <jra@samba.org>2004-02-04 20:28:51 +0000
commitda371e74bb3299fbf951a6b1f373daff7a2c6018 (patch)
treedbb3efea02cf9a0d035c11a817032222f526a9d5
parent471e558b28817018f7f132aa5ef7bb99dec92176 (diff)
downloadsamba-da371e74bb3299fbf951a6b1f373daff7a2c6018.tar.gz
samba-da371e74bb3299fbf951a6b1f373daff7a2c6018.tar.bz2
samba-da371e74bb3299fbf951a6b1f373daff7a2c6018.zip
Fix final valgrind errors with #830. Catch mb conversion error that may not
terminate correctly. Jeremy. (This used to be commit 49142c6352eb3645437ef86bcedca1b1895aef60)
-rw-r--r--source3/lib/util_str.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index 822ab20628..2d1f596c97 100644
--- a/source3/lib/util_str.c
+++ b/source3/lib/util_str.c
@@ -1293,6 +1293,8 @@ char *strnrchr_m(const char *s, char c, unsigned int n)
void strlower_m(char *s)
{
+ size_t len;
+
/* this is quite a common operation, so we want it to be
fast. We optimise for the ascii case, knowing that all our
supported multi-byte character sets are ascii-compatible
@@ -1308,7 +1310,12 @@ void strlower_m(char *s)
/* I assume that lowercased string takes the same number of bytes
* as source string even in UTF-8 encoding. (VIV) */
- unix_strlower(s,strlen(s)+1,s,strlen(s)+1);
+ len = strlen(s) + 1;
+ errno = 0;
+ unix_strlower(s,len,s,len);
+ /* Catch mb conversion errors that may not terminate. */
+ if (errno)
+ s[len-1] = '\0';
}
/**
@@ -1317,6 +1324,8 @@ void strlower_m(char *s)
void strupper_m(char *s)
{
+ size_t len;
+
/* this is quite a common operation, so we want it to be
fast. We optimise for the ascii case, knowing that all our
supported multi-byte character sets are ascii-compatible
@@ -1332,7 +1341,12 @@ void strupper_m(char *s)
/* I assume that lowercased string takes the same number of bytes
* as source string even in multibyte encoding. (VIV) */
- unix_strupper(s,strlen(s)+1,s,strlen(s)+1);
+ len = strlen(s) + 1;
+ errno = 0;
+ unix_strupper(s,len,s,len);
+ /* Catch mb conversion errors that may not terminate. */
+ if (errno)
+ s[len-1] = '\0';
}
/**