]> sjero.net Git - wget/commitdiff
Introduce a new function check_encoding_name() for doing a basic check on encoding...
authorSaint Xavier <wget@sxav.eu>
Thu, 19 Jun 2008 22:33:02 +0000 (00:33 +0200)
committerSaint Xavier <wget@sxav.eu>
Thu, 19 Jun 2008 22:33:02 +0000 (00:33 +0200)
src/ChangeLog
src/iri.c
src/iri.h
src/main.c

index 7ad7c8cab77d8af42d3a76bfc1c1347a8b9f09d7..6dcaa279da1d8ddeb230741d6acd9787985c35f9 100644 (file)
@@ -1,3 +1,10 @@
+2008-06-19  Xavier Saint  <wget@sxav.eu>
+
+       * iri.c, iri.h : New function check_encoding_name() as
+       a priliminary encoding name check.
+
+       * main.c, iri.c : Make use of check_encoding_name().
+
 2008-06-19  Xavier Saint  <wget@sxav.eu>
 
        * iri.c : Include missing stringprep.h file and add a
index b87e6ebeb467decb8fba2614033593e5032ad28d..fea7b150e7a5e3163ec642d68c0738b9bad9fbca 100644 (file)
--- a/src/iri.c
+++ b/src/iri.c
@@ -64,6 +64,14 @@ parse_charset (char *str)
 
   /* sXXXav: could strdupdelim return NULL ? */
   charset = strdupdelim (str, charset);
+
+  /* Do a minimum check on the charset value */
+  if (!check_encoding_name (charset))
+    {
+      xfree (charset);
+      return NULL;
+    }
+
   logprintf (LOG_VERBOSE, "parse_charset: %s\n", quote (charset));
 
   return charset;
@@ -79,3 +87,24 @@ find_locale (void)
 }
 
 
+/* Basic check of an encoding name. */
+bool
+check_encoding_name (char *encoding)
+{
+  char *s = encoding;
+
+  while (*s)
+    {
+      if (!c_isascii(*s) || c_isspace(*s))
+        {
+          logprintf (LOG_VERBOSE, "Encoding %s isn't valid\n", quote(encoding));
+          return false;
+        }
+
+      s++;
+    }
+
+  return true;
+}
+
+
index eb344d9fe1d3ef171597dfb5dd99d1f5f3d68b3e..85a7fb7f5260b19e87730c91742d0a05e981e803 100644 (file)
--- a/src/iri.h
+++ b/src/iri.h
@@ -34,11 +34,13 @@ as that of the covered work.  */
 
 char *parse_charset (char *str);
 char *find_locale (void);
+bool check_encoding_name (char *encoding);
 
 #else /* ENABLE_IRI */
 
-#define parse_charset(str)     NULL
-#define find_locale()          NULL
+#define parse_charset(str)             NULL
+#define find_locale()                  NULL
+#define check_encoding_name(str)       false
 
 #endif /* ENABLE_IRI */
 #endif /* IRI_H */
index fc41153b2a862e774f37250e32721aff7dae538b..53ea6b9109baf6245ffd22a272d1abef021caf04 100644 (file)
@@ -1067,10 +1067,14 @@ for details.\n\n"));
 #ifdef ENABLE_IRI
   if (opt.enable_iri)
     {
+      if (opt.locale && !check_encoding_name(opt.locale))
+        opt.locale = NULL;
+
       if (!opt.locale)
         opt.locale = find_locale ();
 
-      /* sXXXav : check given locale and remote encoding */
+      if (opt.encoding_remote && !check_encoding_name(opt.encoding_remote))
+        opt.encoding_remote = NULL;
 
       logprintf (LOG_VERBOSE, "Locale = %s\n", quote (opt.locale));
     }