Ticket #886: cage.patch
File cage.patch, 11.3 KB (added by jimmy, 12 years ago) |
---|
-
config/gen/platform/generic/exec.c
55 55 } 56 56 else { 57 57 /* child */ 58 char * cmd = Parrot_str_to_cstring(interp, command);59 int status = execlp("sh", "sh", "-c", cmd, (void *)NULL);58 char * const cmd = Parrot_str_to_cstring(interp, command); 59 int status = execlp("sh", "sh", "-c", cmd, (void *)NULL); 60 60 61 61 /* if we get here, something's horribly wrong, but free anyway... */ 62 mem_sys_free(cmd);62 Parrot_str_free_cstring(cmd); 63 63 64 64 if (status) 65 65 exit(status); … … 97 97 if (child) { 98 98 /* parent */ 99 99 int status; 100 pid_t returnstat; 101 returnstat = waitpid(child, &status, 0); 100 pid_t returnstat = waitpid(child, &status, 0); 102 101 UNUSED(returnstat); 103 102 return status; 104 103 } … … 106 105 /* child. Be horribly profligate with memory, since we're 107 106 about to be something else */ 108 107 int status, i; 109 char **argv;110 108 STRING *s; 111 char *cmd; 109 char *cmd; 110 char **argv = (char **)mem_sys_allocate((len+1)*sizeof (char *)); 112 111 113 argv = (char **)mem_sys_allocate((len+1)*sizeof (char *));114 112 for (i = 0; i < len; ++i) { 115 113 s = VTABLE_get_string_keyed_int(interp, cmdargs, i); 116 114 argv[i] = Parrot_str_to_cstring(interp, s); 117 115 } 116 118 117 cmd = argv[0]; 119 argv[i] = NULL;120 118 121 119 status = execvp(cmd, argv); 122 120 /* if we get here, something's horribly wrong... */ … … 140 138 { 141 139 /* Be horribly profligate with memory, since we're 142 140 about to be something else */ 143 char * cmd= Parrot_str_to_cstring(interp, command);144 int status = execlp("sh", "sh", "-c", cmd, (void *)NULL);141 char * const cmd = Parrot_str_to_cstring(interp, command); 142 int status = execlp("sh", "sh", "-c", cmd, (void *)NULL); 145 143 146 144 /* if we get here, something's horribly wrong... */ 147 145 if (status) -
config/gen/platform/win32/exec.c
41 41 DWORD status = 0; 42 42 STARTUPINFO si; 43 43 PROCESS_INFORMATION pi; 44 int free_it= 0;45 char* cmd= (char *)mem_sys_allocate(command->strlen + 4);46 char* shell= Parrot_getenv("ComSpec", &free_it);47 char* c mdin= Parrot_str_to_cstring(interp, command);44 int free_it = 0; 45 char* cmd = (char *)mem_sys_allocate(command->strlen + 4); 46 char* shell = Parrot_getenv("ComSpec", &free_it); 47 char* const cmdin = Parrot_str_to_cstring(interp, command); 48 48 49 49 strcpy(cmd, "/c "); 50 50 strcat(cmd, cmdin); … … 95 95 DWORD status = 0; 96 96 STARTUPINFO si; 97 97 PROCESS_INFORMATION pi; 98 int pmclen ;98 int pmclen, i; 99 99 int cmdlinelen = 1000; 100 100 int cmdlinepos = 0; 101 char *cmdline = (char *)mem_sys_allocate(cmdlinelen); 102 int i; 101 char *cmdline = (char *)mem_sys_allocate(cmdlinelen); 103 102 104 103 /* Ensure there's something in the PMC array. */ 105 104 pmclen = VTABLE_elements(interp, cmdargs); … … 109 108 110 109 /* Now build command line. */ 111 110 for (i = 0; i < pmclen; i++) { 112 STRING * s= VTABLE_get_string_keyed_int(interp, cmdargs, i);113 char * cs = Parrot_str_to_cstring(interp, s);111 STRING * s = VTABLE_get_string_keyed_int(interp, cmdargs, i); 112 char * const cs = Parrot_str_to_cstring(interp, s); 114 113 if (cmdlinepos + (int)s->strlen + 3 > cmdlinelen) { 115 114 cmdlinelen += s->strlen + 4; 116 115 cmdline = (char *)mem_sys_realloc(cmdline, cmdlinelen); … … 119 118 strcpy(cmdline + cmdlinepos + 1, cs); 120 119 strcpy(cmdline + cmdlinepos + 1 + s->strlen, "\" "); 121 120 cmdlinepos += s->strlen + 3; 121 Parrot_str_free_cstring(cs); 122 122 } 123 123 124 124 /* Start the child process. */ … … 162 162 Parrot_Exec_OS_Command(PARROT_INTERP, STRING *command) 163 163 { 164 164 int status; 165 char * in= Parrot_str_to_cstring(interp, command);166 char * cmd = NULL;165 char * const in = Parrot_str_to_cstring(interp, command); 166 char * cmd = NULL; 167 167 const char **argv = (const char **)mem_sys_allocate_zeroed(2 * sizeof (int)); 168 168 169 169 /* Grab string, extract command and parameters. */ … … 223 223 curPos ++; 224 224 } 225 225 226 Parrot_str_free_cstring(in); 227 226 228 /* If we still have a seek char, then the input was improper. */ 227 229 if (seekChar) 228 230 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_NOSPAWN, -
src/debug.c
1256 1256 tmp_stdin, readline, 1257 1257 "S->S", prompt, & s); 1258 1258 { 1259 char * aux = Parrot_str_to_cstring(interpdeb, s);1259 char * const aux = Parrot_str_to_cstring(interpdeb, s); 1260 1260 strcpy(c, aux); 1261 1261 Parrot_str_free_cstring(aux); 1262 1262 } -
src/dynext.c
232 232 { 233 233 ASSERT_ARGS(dlopen_string) 234 234 235 char * pathstr = Parrot_str_to_cstring(interp, path);236 void * handle= Parrot_dlopen(pathstr);235 char * const pathstr = Parrot_str_to_cstring(interp, path); 236 void * handle = Parrot_dlopen(pathstr); 237 237 Parrot_str_free_cstring(pathstr); 238 238 return handle; 239 239 } -
src/interp/inter_misc.c
346 346 347 347 else { 348 348 /* Need to strip back to what follows the final / or \. */ 349 STRING * fullname = VTABLE_get_string(interp, exe_name);350 char * fullname_c = Parrot_str_to_cstring(interp, fullname);351 int pos = strlen(fullname_c) - 1;349 STRING * fullname = VTABLE_get_string(interp, exe_name); 350 char * const fullname_c = Parrot_str_to_cstring(interp, fullname); 351 int pos = strlen(fullname_c) - 1; 352 352 353 353 while (pos > 0 354 354 && fullname_c[pos] != '/' … … 359 359 pos++; 360 360 361 361 basename = Parrot_str_new(interp, fullname_c + pos, 0); 362 mem_sys_free(fullname_c);362 Parrot_str_free_cstring(fullname_c); 363 363 364 364 return basename; 365 365 } -
src/io/socket_unix.c
105 105 PMC * const sockaddr = pmc_new(interp, enum_class_Sockaddr); 106 106 107 107 get_sockaddr_in(interp, sockaddr, s, port); 108 free(s);108 Parrot_str_free_cstring(s); 109 109 return sockaddr; 110 110 } 111 111 -
src/io/socket_win32.c
444 444 { 445 445 ASSERT_ARGS(Parrot_io_sockaddr_in) 446 446 PMC * sockaddr; 447 char * s;447 char * const s = Parrot_str_to_cstring(interp, addr); 448 448 449 s = Parrot_str_to_cstring(interp, addr);450 449 sockaddr = pmc_new(interp, enum_class_Sockaddr); 451 450 get_sockaddr_in(interp, sockaddr, s, port); 452 free(s);451 Parrot_str_free_cstring(s); 453 452 return sockaddr; 454 453 } 455 454 -
src/io/unix.c
756 756 } 757 757 758 758 # else 759 UNUSED( l);759 UNUSED(filehandle); 760 760 UNUSED(command); 761 761 UNUSED(flags); 762 762 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNIMPLEMENTED, -
src/io/win32.c
693 693 NULL, NULL, TRUE, 0, 694 694 NULL, NULL, &start, &procinfo) == 0) 695 695 goto fail; 696 Parrot_str_free_cstring(cmd); 697 cmd = NULL; 696 698 697 if (f_read) { 699 698 Parrot_io_set_os_handle(interp, io, hread); 700 699 CloseHandle(hwrite); … … 703 702 Parrot_io_set_os_handle(interp, io, hwrite); 704 703 CloseHandle(hread); 705 704 } 705 706 Parrot_str_free_cstring(cmd); 706 707 CloseHandle(procinfo.hThread); 707 708 VTABLE_set_integer_keyed_int(interp, io, 0, (INTVAL)procinfo.hProcess); 708 709 return io; -
src/pmc/codestring.pmc
286 286 287 287 METHOD charname_to_ord(STRING *name) { 288 288 #if PARROT_HAS_ICU 289 UChar32 codepoint;290 UErrorCode err= U_ZERO_ERROR;291 char *cstr = Parrot_str_to_cstring(INTERP, name);289 UChar32 codepoint; 290 UErrorCode err = U_ZERO_ERROR; 291 char * const cstr = Parrot_str_to_cstring(INTERP, name); 292 292 codepoint = u_charFromName(U_EXTENDED_CHAR_NAME, cstr, &err); 293 293 Parrot_str_free_cstring(cstr); 294 294 if (U_SUCCESS(err)) { -
src/pmc/env.pmc
340 340 =head1 SEE ALS0 341 341 342 342 PDD - 343 L<http:// www.parrotcode.org/docs/pdd/pdd17_pdd.html#Hash_types>343 L<http://docs.parrot.org/parrot/latest/html/docs/pdds/pdd17_pmc.pod.html#Hash_types> 344 344 345 345 Environment in Perl 6 - L<http://dev.perl.org/perl6/rfc/318.html> 346 346 -
src/pmc/os.pmc
476 476 */ 477 477 METHOD readdir(STRING *path) { 478 478 #ifndef _MSC_VER 479 char * const cpath = Parrot_str_to_cstring(interp, path); 480 DIR *dir = opendir(cpath); 479 481 struct dirent *dirent; 480 482 PMC *array; 481 char *cpath = Parrot_str_to_cstring(interp, path);482 483 STRING *retval; 483 DIR *dir = opendir(cpath);484 484 485 485 Parrot_str_free_cstring(cpath); 486 486 -
src/pmc/string.pmc
241 241 VTABLE void set_string_native(STRING *value) { 242 242 /* Only allow constant PMCs to embed constant strings */ 243 243 if (PObj_constant_TEST(SELF) && !PObj_constant_TEST(value)) { 244 char * copy = Parrot_str_to_cstring(INTERP, value);245 value = Parrot_str_new_init(INTERP, copy, strlen(copy),244 char * const copy = Parrot_str_to_cstring(INTERP, value); 245 value = Parrot_str_new_init(INTERP, copy, strlen(copy), 246 246 PARROT_DEFAULT_ENCODING, PARROT_DEFAULT_CHARSET, PObj_constant_FLAG); 247 247 Parrot_str_free_cstring(copy); 248 248 }