This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch: Fix for PR 2369
- From: Tom Tromey <tromey at redhat dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Cc: Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Date: 25 Nov 2001 13:12:04 -0700
- Subject: Patch: Fix for PR 2369
- Reply-to: tromey at redhat dot com
This fixes PR 2369. It adds some up-front checking to --main, so that
gcj will give an error if the argument isn't a valid name.
This patch is a bit hacky. It duplicates some code from lex.h. The
alternative would require introducing a new file; I'm willing to
rewrite this way if required.
Also right now this patch assumes that command-line arguments are
plain ASCII. This is an incorrect assumption, but it is compatible
with what the rest of gcc currently assumes.
Ok to commit?
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
Fix for PR java/2369:
* jvspec.c (verify_class_name): New function.
(lang_specific_driver): Call it.
(JAVA_START_CHAR_P): New macro.
(JAVA_PART_CHAR_P9c): Likewise.
Index: jvspec.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/jvspec.c,v
retrieving revision 1.47
diff -u -r1.47 jvspec.c
--- jvspec.c 2001/09/07 18:40:26 1.47
+++ jvspec.c 2001/11/25 20:06:02
@@ -46,6 +46,7 @@
#define RESOURCE_FILE_ARG (1<<7)
static char *find_spec_file PARAMS ((const char *));
+static int verify_class_name PARAMS ((const char *));
static const char *main_class_name = NULL;
int lang_specific_extra_outfiles = 0;
@@ -97,6 +98,45 @@
return NULL;
}
+/* FIXME: these should come from lex.h. */
+#define JAVA_START_CHAR_P(c) (c < 128 && (ISIDST (c) || c == '$'))
+#define JAVA_PART_CHAR_P(c) (c < 128 \
+ && (ISIDNUM (c) \
+ || c == '$' \
+ || (c >= 0x00 && c <= 0x08) \
+ || (c >= 0x0e && c <= 0x1b) \
+ || c == 0x7f))
+
+/* Verify that NAME is a valid Java class name that might contain
+ `main'. Return 0 on failure. */
+static int
+verify_class_name (name)
+ const char *name;
+{
+ /* FIXME: what encoding do we use for command-line arguments? For
+ now we assume plain ASCII, which of course is wrong. */
+ while (*name)
+ {
+ int ch = *name++;
+ if (ch < 0 || ! JAVA_START_CHAR_P (ch))
+ return 0;
+ while (*name)
+ {
+ ch = *name++;
+ if (ch < 0)
+ return 0;
+ /* We found a break between class names. Next character
+ must be an identifier start again. */
+ if (ch == '.')
+ break;
+ if (! JAVA_PART_CHAR_P (ch))
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
void
lang_specific_driver (in_argc, in_argv, in_added_libraries)
int *in_argc;
@@ -381,6 +421,9 @@
if (saw_D && ! main_class_name)
fatal ("can't specify `-D' without `--main'\n");
+
+ if (main_class_name && ! verify_class_name (main_class_name))
+ fatal ("`%s' is not a valid class name", main_class_name);
num_args = argc + added;
if (saw_R)