[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] branch master updated: -sanitize utf8 api a bit
From: |
gnunet |
Subject: |
[gnunet] branch master updated: -sanitize utf8 api a bit |
Date: |
Tue, 15 Feb 2022 23:36:27 +0100 |
This is an automated email from the git hooks/post-receive script.
martin-schanzenbach pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new e391a0a83 -sanitize utf8 api a bit
e391a0a83 is described below
commit e391a0a83f1336478d2171bbae321689b7fe8d03
Author: Martin Schanzenbach <schanzen@gnunet.org>
AuthorDate: Tue Feb 15 23:36:23 2022 +0100
-sanitize utf8 api a bit
---
src/ats/gnunet-ats-solver-eval.c | 5 ++--
src/gnsrecord/gnsrecord_misc.c | 17 ++---------
src/gnsrecord/gnunet-gnsrecord-tvg.c | 9 ++++--
src/hostlist/gnunet-daemon-hostlist_client.c | 6 +++-
src/identity/gnunet-service-identity.c | 3 +-
src/include/gnunet_gnsrecord_lib.h | 12 ++------
src/include/gnunet_strings_lib.h | 14 ++++-----
src/util/crypto_hash.c | 3 +-
src/util/strings.c | 43 +++++++++++++++++-----------
src/util/test_strings.c | 7 ++---
10 files changed, 59 insertions(+), 60 deletions(-)
diff --git a/src/ats/gnunet-ats-solver-eval.c b/src/ats/gnunet-ats-solver-eval.c
index 25b963532..ba7994686 100644
--- a/src/ats/gnunet-ats-solver-eval.c
+++ b/src/ats/gnunet-ats-solver-eval.c
@@ -442,7 +442,7 @@ GNUNET_ATS_solver_logging_write_to_disk (struct
LoggingHandle *l, int
}
}
-cleanup:
+ cleanup:
next = lf_head;
for (cur = next; NULL != cur; cur = next)
{
@@ -1414,7 +1414,8 @@ load_op_add_address (struct GNUNET_ATS_TEST_Operation *o,
}
else
{
- GNUNET_STRINGS_utf8_toupper (op_network, op_network);
+ GNUNET_break (GNUNET_OK == GNUNET_STRINGS_utf8_toupper (op_network,
+ op_network));
if (0 == strcmp (op_network, "UNSPECIFIED"))
{
o->address_network = GNUNET_NT_UNSPECIFIED;
diff --git a/src/gnsrecord/gnsrecord_misc.c b/src/gnsrecord/gnsrecord_misc.c
index 9b5e47c4c..b63142d5a 100644
--- a/src/gnsrecord/gnsrecord_misc.c
+++ b/src/gnsrecord/gnsrecord_misc.c
@@ -37,24 +37,11 @@
#define LOG(kind, ...) GNUNET_log_from (kind, "gnsrecord", __VA_ARGS__)
-char *
-GNUNET_GNSRECORD_string_to_lowercase (const char *src)
-{
- char *res;
-
- res = GNUNET_strdup (src);
- GNUNET_STRINGS_utf8_tolower (src, res);
- return res;
-}
-
char *
GNUNET_GNSRECORD_string_normalize (const char *src)
{
- char *res;
- res = GNUNET_strdup (src);
- GNUNET_STRINGS_utf8_tolower (src, res);
- GNUNET_STRINGS_utf8_normalize (src, res);
- return res;
+ /*FIXME: We may want to follow RFC3491 a bit more (Nameprep)*/
+ return GNUNET_STRINGS_utf8_normalize (src);
}
/**
diff --git a/src/gnsrecord/gnunet-gnsrecord-tvg.c
b/src/gnsrecord/gnunet-gnsrecord-tvg.c
index 4afa458f1..31a2c5da2 100644
--- a/src/gnsrecord/gnunet-gnsrecord-tvg.c
+++ b/src/gnsrecord/gnunet-gnsrecord-tvg.c
@@ -426,9 +426,14 @@ run (void *cls,
rd[2].flags = GNUNET_GNSRECORD_RF_SUPPLEMENTAL |
GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
run_pkey (&rd_pkey, 1, "testdelegation");
- run_pkey (rd, 3, "\u65b0 Name System");
+ run_pkey (rd, 3, "namesystem");
run_edkey (&rd_pkey, 1, "testdelegation");
- run_edkey (rd, 3, "\u65b0 Name System");
+ run_edkey (rd, 3, "namesystem");
+ /*char *norm_lbl;
+ norm_lbl = GNUNET_GNSRECORD_string_normalize ("q\u0307\u0323namesysteM");
+ print_bytes ("q\u0307\u0323namesysteM", strlen ("q\u0307\u0323namesysteM"),
8);
+ print_bytes (norm_lbl, strlen (norm_lbl), 8);
+ printf ("%s\n", norm_lbl);*/
}
diff --git a/src/hostlist/gnunet-daemon-hostlist_client.c
b/src/hostlist/gnunet-daemon-hostlist_client.c
index 44966d3de..1f7d4cc35 100644
--- a/src/hostlist/gnunet-daemon-hostlist_client.c
+++ b/src/hostlist/gnunet-daemon-hostlist_client.c
@@ -1635,7 +1635,11 @@ GNUNET_HOSTLIST_client_start (const struct
GNUNET_CONFIGURATION_Handle *c,
"PROXY_TYPE",
&proxytype_str))
{
- GNUNET_STRINGS_utf8_toupper (proxytype_str, proxytype_str);
+ if (GNUNET_OK != GNUNET_STRINGS_utf8_toupper (proxytype_str,
+ proxytype_str))
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Unable to convert `%s' to UTF-8 uppercase\n",
+ proxytype_str);
proxy_type = CURLPROXY_HTTP;
if (0 == strcmp (proxytype_str, "HTTP"))
proxy_type = CURLPROXY_HTTP;
diff --git a/src/identity/gnunet-service-identity.c
b/src/identity/gnunet-service-identity.c
index 2bb4b0897..51f897557 100644
--- a/src/identity/gnunet-service-identity.c
+++ b/src/identity/gnunet-service-identity.c
@@ -489,8 +489,7 @@ handle_get_default_message (void *cls,
char *identifier;
name = GNUNET_strdup ((const char *) &gdm[1]);
- GNUNET_STRINGS_utf8_tolower ((const char *) &gdm[1],
- name);
+ GNUNET_STRINGS_utf8_tolower ((const char *) &gdm[1], name);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received GET_DEFAULT for service `%s' from client\n",
name);
diff --git a/src/include/gnunet_gnsrecord_lib.h
b/src/include/gnunet_gnsrecord_lib.h
index cbf7ee15c..590d83476 100644
--- a/src/include/gnunet_gnsrecord_lib.h
+++ b/src/include/gnunet_gnsrecord_lib.h
@@ -431,7 +431,8 @@ GNUNET_GNSRECORD_is_expired (const struct
GNUNET_GNSRECORD_Data *rd);
/**
- * Normalize a UTF-8 string to UTF-8 NFC
+ * Normalize a UTF-8 string to a GNS name
+ *
* @param src source string
* @return converted result
*/
@@ -439,15 +440,6 @@ char *
GNUNET_GNSRECORD_string_normalize (const char *src);
-/**
- * Convert a UTF-8 string to UTF-8 lowercase
- * @param src source string
- * @return converted result
- */
-char *
-GNUNET_GNSRECORD_string_to_lowercase (const char *src);
-
-
/**
* Convert a zone to a string (for printing debug messages).
* This is one of the very few calls in the entire API that is
diff --git a/src/include/gnunet_strings_lib.h b/src/include/gnunet_strings_lib.h
index 9dd2f733e..09c547b09 100644
--- a/src/include/gnunet_strings_lib.h
+++ b/src/include/gnunet_strings_lib.h
@@ -159,14 +159,12 @@ GNUNET_STRINGS_to_utf8 (const char *input,
/**
* Normalize the utf-8 input string to NFC.
- * Output needs to be allocated appropriately.
*
* @param input input string
- * @param output output buffer
+ * @return result (freshly allocated) or NULL on error.
*/
-void
-GNUNET_STRINGS_utf8_normalize (const char *input,
- char *output);
+char*
+GNUNET_STRINGS_utf8_normalize (const char *input);
/**
@@ -192,8 +190,9 @@ GNUNET_STRINGS_from_utf8 (const char *input,
*
* @param input input string
* @param output output buffer
+ * @return GNUNET_OK on success
*/
-void
+enum GNUNET_GenericReturnValue
GNUNET_STRINGS_utf8_tolower (const char *input,
char *output);
@@ -204,8 +203,9 @@ GNUNET_STRINGS_utf8_tolower (const char *input,
*
* @param input input string
* @param output output buffer
+ * @return GNUNET_OK on success
*/
-void
+enum GNUNET_GenericReturnValue
GNUNET_STRINGS_utf8_toupper (const char *input,
char *output);
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c
index dcd46e5f9..f516f5474 100644
--- a/src/util/crypto_hash.c
+++ b/src/util/crypto_hash.c
@@ -76,7 +76,8 @@ GNUNET_CRYPTO_hash_from_string2 (const char *enc,
char upper_enc[enclen];
char *up_ptr = upper_enc;
- GNUNET_STRINGS_utf8_toupper (enc, up_ptr);
+ if (GNUNET_OK != GNUNET_STRINGS_utf8_toupper (enc, up_ptr))
+ return GNUNET_SYSERR;
return GNUNET_STRINGS_string_to_data (upper_enc, enclen,
(unsigned char *) result,
diff --git a/src/util/strings.c b/src/util/strings.c
index c63870e42..75e45ba6d 100644
--- a/src/util/strings.c
+++ b/src/util/strings.c
@@ -390,7 +390,7 @@ GNUNET_STRINGS_conv (const char *input,
ret[encoded_string_length] = '\0';
free (encoded_string);
return ret;
-fail:
+ fail:
LOG (GNUNET_ERROR_TYPE_WARNING,
_ ("Character sets requested were `%s'->`%s'\n"),
"UTF-8",
@@ -426,24 +426,28 @@ GNUNET_STRINGS_from_utf8 (const char *input,
}
-void
-GNUNET_STRINGS_utf8_normalize (const char *input,
- char *output)
+char *
+GNUNET_STRINGS_utf8_normalize (const char *input)
{
uint8_t *tmp;
size_t len;
-
- tmp = u8_normalize (UNINORM_NFKC,
- (uint8_t *) input,
- strlen ((char*) input),
- NULL,
- &len);
+ char *output;
+ tmp = u8_tolower ((uint8_t *) input,
+ strlen ((char *) input),
+ NULL,
+ UNINORM_NFKC,
+ NULL,
+ &len);
+ if (NULL == tmp)
+ return NULL;
+ output = GNUNET_malloc (len + 1);
GNUNET_memcpy (output, tmp, len);
output[len] = '\0';
free (tmp);
+ return output;
}
-void
+enum GNUNET_GenericReturnValue
GNUNET_STRINGS_utf8_tolower (const char *input,
char *output)
{
@@ -456,13 +460,16 @@ GNUNET_STRINGS_utf8_tolower (const char *input,
UNINORM_NFD,
NULL,
&len);
+ if (NULL == tmp_in)
+ return GNUNET_SYSERR;
GNUNET_memcpy (output, tmp_in, len);
output[len] = '\0';
- free (tmp_in);
+ GNUNET_free (tmp_in);
+ return GNUNET_OK;
}
-void
+enum GNUNET_GenericReturnValue
GNUNET_STRINGS_utf8_toupper (const char *input,
char *output)
{
@@ -475,9 +482,13 @@ GNUNET_STRINGS_utf8_toupper (const char *input,
UNINORM_NFD,
NULL,
&len);
+ if (NULL == tmp_in)
+ return GNUNET_SYSERR;
+ /* 0-terminator does not fit */
GNUNET_memcpy (output, tmp_in, len);
output[len] = '\0';
- free (tmp_in);
+ GNUNET_free (tmp_in);
+ return GNUNET_OK;
}
@@ -1604,7 +1615,7 @@ GNUNET_STRINGS_base64_encode (const void *in,
char *opt;
ret = 0;
- GNUNET_assert (len < SIZE_MAX / 4 * 3 );
+ GNUNET_assert (len < SIZE_MAX / 4 * 3);
opt = GNUNET_malloc (2 + (len * 4 / 3) + 8);
for (size_t i = 0; i < len; ++i)
{
@@ -1741,7 +1752,7 @@ GNUNET_STRINGS_base64_decode (const char *data,
output[ret++] = c;
}
}
-END:
+ END:
*out = output;
return ret;
}
diff --git a/src/util/test_strings.c b/src/util/test_strings.c
index 1ecd31464..cccffcaf5 100644
--- a/src/util/test_strings.c
+++ b/src/util/test_strings.c
@@ -114,10 +114,9 @@ main (int argc, char *argv[])
/* Normalization */
r = "q\u0307\u0323"; /* Non-canonical order */
- GNUNET_STRINGS_utf8_normalize (r,
- buf);
- GNUNET_assert (0 == strcmp ("q\u0323\u0307", buf));
-
+ b = GNUNET_STRINGS_utf8_normalize (r);
+ GNUNET_assert (0 == strcmp ("q\u0323\u0307", b));
+ GNUNET_free (b);
b = GNUNET_STRINGS_to_utf8 ("TEST", 4, "ASCII");
WANT ("TEST", b);
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnunet] branch master updated: -sanitize utf8 api a bit,
gnunet <=