Ticket #886: cage.3.patch
File cage.3.patch, 10.5 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(interp, Parrot_str_new(interp, "ComSpec", strlen("ComSpec")));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(interp, Parrot_str_new(interp, "ComSpec", strlen("ComSpec"))); 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; 99 int cmdlinelen = 1000; 100 int cmdlinepos = 0; 101 char *cmdline = (char *)mem_sys_allocate(cmdlinelen); 102 int i; 98 int pmclen, i; 99 int cmdlinelen = 1000; 100 int cmdlinepos = 0; 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); … … 162 161 Parrot_Exec_OS_Command(PARROT_INTERP, STRING *command) 163 162 { 164 163 int status; 165 char * in= Parrot_str_to_cstring(interp, command);166 char * cmd= NULL;164 char * const in = Parrot_str_to_cstring(interp, command); 165 char * cmd = NULL; 167 166 const char **argv = (const char **)mem_sys_allocate_zeroed(2 * sizeof (int)); 168 167 169 168 /* Grab string, extract command and parameters. */ … … 223 222 curPos ++; 224 223 } 225 224 225 Parrot_str_free_cstring(in); 226 226 227 /* If we still have a seek char, then the input was improper. */ 227 228 if (seekChar) 228 229 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_NOSPAWN, -
src/debug.c
1277 1277 tmp_stdin, readline, 1278 1278 "S->S", prompt, & s); 1279 1279 { 1280 char * aux = Parrot_str_to_cstring(interpdeb, s);1280 char * const aux = Parrot_str_to_cstring(interpdeb, s); 1281 1281 strcpy(c, aux); 1282 1282 Parrot_str_free_cstring(aux); 1283 1283 } -
src/dynext.c
233 233 { 234 234 ASSERT_ARGS(dlopen_string) 235 235 236 char * pathstr = Parrot_str_to_cstring(interp, path);237 void * handle= Parrot_dlopen(pathstr);236 char * const pathstr = Parrot_str_to_cstring(interp, path); 237 void * handle = Parrot_dlopen(pathstr); 238 238 Parrot_str_free_cstring(pathstr); 239 239 return handle; 240 240 } -
src/interp/inter_misc.c
341 341 342 342 else { 343 343 /* Need to strip back to what follows the final / or \. */ 344 STRING * fullname = VTABLE_get_string(interp, exe_name);345 char * fullname_c = Parrot_str_to_cstring(interp, fullname);346 int pos = strlen(fullname_c) - 1;344 STRING * fullname = VTABLE_get_string(interp, exe_name); 345 char * const fullname_c = Parrot_str_to_cstring(interp, fullname); 346 int pos = strlen(fullname_c) - 1; 347 347 348 348 while (pos > 0 349 349 && fullname_c[pos] != '/' … … 354 354 pos++; 355 355 356 356 basename = Parrot_str_new(interp, fullname_c + pos, 0); 357 mem_sys_free(fullname_c);357 Parrot_str_free_cstring(fullname_c); 358 358 359 359 return basename; 360 360 } -
src/io/socket_win32.c
443 443 Parrot_io_sockaddr_in(PARROT_INTERP, ARGIN(STRING *addr), INTVAL port) 444 444 { 445 445 ASSERT_ARGS(Parrot_io_sockaddr_in) 446 PMC * sockaddr; 447 char * s; 448 449 s = Parrot_str_to_cstring(interp, addr); 446 PMC * sockaddr; 447 char * const s = Parrot_str_to_cstring(interp, addr); 450 448 sockaddr = pmc_new(interp, enum_class_Sockaddr); 451 449 get_sockaddr_in(interp, sockaddr, s, port); 452 450 Parrot_str_free_cstring(s); -
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;698 696 if (f_read) { 699 697 Parrot_io_set_os_handle(interp, io, hread); 700 698 CloseHandle(hwrite); … … 703 701 Parrot_io_set_os_handle(interp, io, hwrite); 704 702 CloseHandle(hread); 705 703 } 704 705 Parrot_str_free_cstring(cmd); 706 706 CloseHandle(procinfo.hThread); 707 707 VTABLE_set_integer_keyed_int(interp, io, 0, (INTVAL)procinfo.hProcess); 708 708 return io; -
src/pmc/codestring.pmc
278 278 279 279 METHOD charname_to_ord(STRING *name) { 280 280 #if PARROT_HAS_ICU 281 U Char32 codepoint;282 UErrorCode err = U_ZERO_ERROR;283 char *cstr = Parrot_str_to_cstring(INTERP, name);284 codepoint = u_charFromName(U_EXTENDED_CHAR_NAME, cstr, &err); 281 UErrorCode err = U_ZERO_ERROR; 282 char * const cstr = Parrot_str_to_cstring(INTERP, name); 283 UChar32 codepoint = u_charFromName(U_EXTENDED_CHAR_NAME, cstr, &err); 284 285 285 Parrot_str_free_cstring(cstr); 286 286 287 if (U_SUCCESS(err)) { 287 288 RETURN(INTVAL codepoint); 288 289 } 290 289 291 RETURN(INTVAL -1); 290 292 #else 291 293 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_LIBRARY_ERROR, -
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
202 202 203 203 /* Only allow constant PMCs to embed constant strings */ 204 204 if (PObj_constant_TEST(SELF) && !PObj_constant_TEST(value)) { 205 char * copy = Parrot_str_to_cstring(INTERP, value);206 value = Parrot_str_new_init(INTERP, copy, strlen(copy),205 char * const copy = Parrot_str_to_cstring(INTERP, value); 206 value = Parrot_str_new_init(INTERP, copy, strlen(copy), 207 207 PARROT_DEFAULT_ENCODING, PARROT_DEFAULT_CHARSET, 208 208 PObj_constant_FLAG); 209 209 Parrot_str_free_cstring(copy);