On Tue, 15 May 2007 05:24:06 -0700 "Paul Cochrane via RT" <[EMAIL PROTECTED]> wrote:
> On 14/05/07, via RT Mike Mattie <[EMAIL PROTECTED]> > wrote: > > # New Ticket Created by Mike Mattie > > # Please include the string: [perl #42947] > > # in the subject line of all future correspondence about this issue. > > # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=42947 > > > > > > > Hello, > > > > This patch changes the Parrot_get_runtime_prefix API from > > > > char* Parrot_get_runtime_prefix(Interp *interp, STRING **prefix_str) > > > > to > > > > STRING* Parrot_get_runtime_prefix (Interp *interp ) { > > > > This is done to make the routine safer, it no longer can leak > > memory. Also the useless "." paths are removed from src/library.c. > > some minor changes to Parrot_locate_runtime_file_str are present to > > sync and correct that function. > > > > other callers in src/inter_misc.c , and compilers/imcc/main.c are > > fixed as well. > > > > also a case of a bare free() being used instead of the proper > > mem_sys_free is fixed. > > > > This relies on #42944 to apply. > > > > Cheers, > > Mike Mattie - [EMAIL PROTECTED] > > > > > > Mike, my mistake. this should go through now that I have attached it :) > It seems the patch didn't come through with the email, could you send > it again? > > Paul > >
--- HEAD/src/library.c 2007-05-14 07:00:17.000000000 -0700
+++ path-api/src/library.c 2007-05-14 06:14:04.000000000 -0700
@@ -76,8 +76,6 @@
VTABLE_push_string(interp, paths, entry);
entry = CONST_STRING(interp, "runtime/parrot/");
VTABLE_push_string(interp, paths, entry);
- entry = CONST_STRING(interp, "./");
- VTABLE_push_string(interp, paths, entry);
entry = CONST_STRING(interp, "lib/parrot/include/");
VTABLE_push_string(interp, paths, entry);
entry = CONST_STRING(interp, "lib/parrot/");
@@ -91,8 +89,6 @@
VTABLE_push_string(interp, paths, entry);
entry = CONST_STRING(interp, "runtime/parrot/");
VTABLE_push_string(interp, paths, entry);
- entry = CONST_STRING(interp, "./");
- VTABLE_push_string(interp, paths, entry);
entry = CONST_STRING(interp, "lib/parrot/library/");
VTABLE_push_string(interp, paths, entry);
entry = CONST_STRING(interp, "lib/parrot/");
@@ -260,12 +256,14 @@
else
paths = get_search_paths(interp, PARROT_LIB_PATH_INCLUDE);
- Parrot_get_runtime_prefix(interp, &prefix);
+ prefix = Parrot_get_runtime_prefix(interp);
+
n = VTABLE_elements(interp, paths);
for (i = 0; i < n; ++i) {
path = VTABLE_get_string_keyed_int(interp, paths, i);
- if (string_length(interp, prefix) &&
- !parrot_path_is_abs(interp,path)) {
+ if (prefix
+ && string_length(interp,prefix)
+ && !parrot_path_is_abs(interp,path)) {
full_name = parrot_path_concat(interp, prefix , path);
}
else
@@ -281,7 +279,22 @@
return full_name;
}
- full_name = ( type & PARROT_RUNTIME_FT_DYNEXT )
+ if (prefix && string_length(interp,prefix)) {
+ /* try this after the built-in paths to avoid security
+ issues with the default "." being used before builtin
+ paths */
+
+ full_name = parrot_path_concat(interp, prefix , file);
+
+ full_name = ( type & PARROT_RUNTIME_FT_DYNEXT )
+ ? try_load_path(interp, full_name)
+ : try_bytecode_extensions(interp, full_name);
+
+ if ( full_name )
+ return full_name;
+ }
+
+ full_name = ( type & PARROT_RUNTIME_FT_DYNEXT )
? try_load_path(interp, file)
: try_bytecode_extensions(interp, file);
@@ -308,60 +321,76 @@
*/
return string_to_cstring(interp, result);
}
-/*
-
-=item C<char* Parrot_get_runtime_prefix(Interp *, STRING **prefix_str)>
-If C<prefix_str> is not NULL, set it to the prefix, else return a malloced
-c-string for the runtime prefix. Remember to free the string with
-C<string_cstring_free()>.
-
-=cut
+static STRING*
+query_runtime_prefix ( Interp* interp ) {
-*/
+ STRING* prefix;
-char*
-Parrot_get_runtime_prefix(Interp *interp, STRING **prefix_str)
-{
- STRING *s, *key;
- PMC *config_hash;
int free_it;
char *env;
env = Parrot_getenv("PARROT_RUNTIME", &free_it);
+
if (env) {
- if (prefix_str) {
- *prefix_str = string_from_cstring(interp, env, 0);
- if (free_it)
- free(env);
- return NULL;
- }
- if (!free_it)
- env = strdup(env);
- return env;
+ prefix = string_from_cstring(interp, env, 0);
+ if (free_it)
+ mem_sys_free(env);
+
+ return prefix;
}
+ return NULL;
+}
+
+/*
+
+=item C<STRING* Parrot_get_runtime_prefix(Interp * )>
+
+return the runtime prefix in the PMC string C<prefix>. The
+config hash is consulted first, then the environment variable
+PARROT_RUNTIME. If neither are found NULL is returned.
+=cut
+
+*/
+
+STRING*
+Parrot_get_runtime_prefix (Interp *interp ) {
+
+ PMC *config_hash;
+
+ STRING *key, *can_fail; /* can_fail , for storing string pointers from
+ functions that may fail to return a prefix value
+ */
+
+ /* first look in the config hash for a user specified path */
+
config_hash = VTABLE_get_pmc_keyed_int(interp, interp->iglobals,
(INTVAL) IGLOBALS_CONFIG_HASH);
- key = CONST_STRING(interp, "prefix");
- if (!VTABLE_elements(interp, config_hash)) {
- const char *pwd = ".";
- char *ret;
-
- if (prefix_str) {
- *prefix_str = const_string(interp, pwd);
- return NULL;
+
+ if (VTABLE_elements(interp, config_hash)) {
+ key = CONST_STRING(interp, "prefix");
+ can_fail = VTABLE_get_string_keyed_str(interp, config_hash, key);
+
+ if ( can_fail ) {
+ /*
+ TODO:
+ shouldn't we do some sanity here ? , assuming this can be
+ set by random code/input we should see if it even exists.
+ */
+
+ return can_fail;
}
- ret = (char *)mem_sys_allocate(3);
- strcpy(ret, pwd);
- return ret;
- }
- s = VTABLE_get_string_keyed_str(interp, config_hash, key);
- if (prefix_str) {
- *prefix_str = s;
- return NULL;
}
- return string_to_cstring(interp, s);
+
+ /*
+ fallback:
+
+ no value was found in the config hash so try a system query, if
+ that fails as well return the default.
+ */
+
+ return query_runtime_prefix(interp);
}
/*
--- HEAD/include/parrot/library.h 2007-05-14 07:00:17.000000000 -0700
+++ path-api/include/parrot/library.h 2007-05-14 05:10:12.000000000 -0700
@@ -38,7 +38,7 @@
PARROT_API STRING* Parrot_locate_runtime_file_str(Interp *, STRING *file_name,
enum_runtime_ft);
-PARROT_API char* Parrot_get_runtime_prefix(Interp *, STRING **prefix);
+PARROT_API STRING* Parrot_get_runtime_prefix(Interp *);
void parrot_init_library_paths(Interp *);
#endif /* PARROT_LIBRARY_H_GUARD */
--- HEAD/src/inter_misc.c 2007-05-12 04:26:05.000000000 -0700
+++ path-api/src/inter_misc.c 2007-05-14 05:10:12.000000000 -0700
@@ -341,10 +341,7 @@
return basename;
case RUNTIME_PREFIX:
- fullname_c = Parrot_get_runtime_prefix(interp, NULL);
- fullname = string_from_cstring(interp, fullname_c, 0);
- mem_sys_free(fullname_c);
- return fullname;
+ return Parrot_get_runtime_prefix( interp );
default: /* or a warning only? */
internal_exception(UNIMPLEMENTED,
--- HEAD/compilers/imcc/main.c 2007-05-12 04:26:22.000000000 -0700
+++ path-api/compilers/imcc/main.c 2007-05-14 06:20:01.000000000 -0700
@@ -196,6 +196,8 @@
char *
parseflags(Parrot_Interp interp, int *argc, char **argv[])
{
+ STRING* prefix;
+
struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT;
int status;
if (*argc == 1) {
@@ -272,7 +274,11 @@
exit(EX_USAGE);
break;
case OPT_RUNTIME_PREFIX:
- printf("%s\n", Parrot_get_runtime_prefix(interp, NULL));
+ prefix = Parrot_get_runtime_prefix(interp);
+
+ printf("%s\n", (prefix)
+ ? string_to_cstring(interp,prefix)
+ : "no value for global config \"prefix\" or PARROT_RUNTIME");
exit(0);
break;
case 'V':
signature.asc
Description: PGP signature
