pike.git / src / main.c

version» Context lines:

pike.git/src/main.c:84:      #define MASTER_COOKIE1 "(#*&)@(*&$"   #define MASTER_COOKIE2 "Master Cookie:"      #define MASTER_COOKIE MASTER_COOKIE1 MASTER_COOKIE2      #ifndef MAXPATHLEN   #define MAXPATHLEN 32768   #endif    - static char master_location[MAXPATHLEN * 2] = MASTER_COOKIE; + static const char _master_location[MAXPATHLEN+CONSTANT_STRLEN(MASTER_COOKIE)] = MASTER_COOKIE; + static char *master_file_location = _master_location + CONSTANT_STRLEN(MASTER_COOKIE);      static void set_master(const char *file)   { -  if (strlen(file) >= MAXPATHLEN*2 - CONSTANT_STRLEN(MASTER_COOKIE)) { -  fprintf(stderr, "Too long path to master: \"%s\" (limit:%"PRINTPTRDIFFT"d)\n", -  file, MAXPATHLEN*2 - CONSTANT_STRLEN(MASTER_COOKIE)); -  exit(1); +  if( master_file_location > _master_location+CONSTANT_STRLEN(MASTER_COOKIE) +  || master_file_location < _master_location) +  free(master_file_location); +  master_file_location = strdup( file );   } -  strcpy(master_location + CONSTANT_STRLEN(MASTER_COOKIE), file); - } +       #ifdef __NT__   static void get_master_key(HKEY cat)   {    HKEY k;    char buffer[4096];    DWORD len=sizeof(buffer)-1,type=REG_SZ;       if(RegOpenKeyEx(cat,    (LPCTSTR)("SOFTWARE\\Pike\\"
pike.git/src/main.c:129: Inside #if defined(__NT__)
   /* FIXME: Look at len? UNICODE? */    set_master(buffer);    }    RegCloseKey(k);    }   }   #endif /* __NT__ */      static void set_default_master(const char *bin_name)   { -  char *mp = master_location + CONSTANT_STRLEN (MASTER_COOKIE); -  + #define mp master_file_location   #ifdef HAVE_GETENV -  if(!*mp && getenv("PIKE_MASTER")) { +  if(getenv("PIKE_MASTER")) {    set_master(getenv("PIKE_MASTER"));    }   #endif      #ifdef __NT__    if(!*mp) get_master_key(HKEY_CURRENT_USER);    if(!*mp) get_master_key(HKEY_LOCAL_MACHINE);   #endif       if(!*mp && strncmp(DEFAULT_MASTER, "NONE/", 5))    { -  SNPRINTF (mp, sizeof (master_location) - CONSTANT_STRLEN (MASTER_COOKIE), +  char tmp[CONSTANT_STRLEN( DEFAULT_MASTER ) + 10 + 10 + 10]; +  SNPRINTF (tmp, sizeof(tmp)-1,    DEFAULT_MASTER,    PIKE_MAJOR_VERSION,    PIKE_MINOR_VERSION,    PIKE_BUILD_VERSION); -  +  set_master( tmp );    }      #ifdef __NT__    if (!(*mp == '/' || *mp == '\\' || (isalpha (*mp) && mp[1] == ':'))) {    char exepath[MAXPATHLEN];    if (!GetModuleFileName (NULL, exepath, _MAX_PATH))    fprintf (stderr, "Failed to get path to exe file: %d\n",    GetLastError());    else {    char tmp[MAXPATHLEN * 2];    char *p = strrchr (exepath, '\\');    if (p) *p = 0;    SNPRINTF (tmp, sizeof (tmp), "%s/%s", exepath, mp); -  strncpy (mp, tmp, -  sizeof (master_location) - CONSTANT_STRLEN (MASTER_COOKIE)); +  set_master( tmp );    }    }   #else    if (!*mp) {    /* Attempt to find a master via the path to the binary. */    /* Note: We assume that MAXPATHLEN is > 18 characters. */ -  if (strlen(bin_name) < (2*MAXPATHLEN - -  CONSTANT_STRLEN(MASTER_COOKIE "master.pike"))) { +  char tmp[strlen(bin_name)];    char *p; -  strcpy(mp, bin_name); -  p = strrchr(mp, '/'); -  if (!p) p = mp; +  strcpy(tmp, bin_name); +  p = strrchr(tmp, '/'); +  if (!p) p = tmp;    else p++;    strcpy(p, "master.pike"); -  +  set_master( tmp );    } -  } +    #endif       TRACE((stderr, "Default master at \"%s\"...\n", mp)); -  + #undef mp   }      #ifdef LIBPIKE   static char libpike_file[MAXPATHLEN * 2];   static void *libpike;      typedef void (*modfun)(void);   #ifdef NO_CAST_TO_FUN   /* Function pointers can't be casted to scalar pointers according to    * ISO-C (probably to support true Harward achitecture machines).
pike.git/src/main.c:263:    case 'q':    if(!argv[e][2]) e++;    break;    }    }      #ifdef LIBPIKE    {    char *p;    char *dir; -  memcpy(libpike_file, master_location + CONSTANT_STRLEN(MASTER_COOKIE), -  sizeof(master_location) - CONSTANT_STRLEN(MASTER_COOKIE)); +  strcpy(libpike_file, master_file_location);    for (p = dir = libpike_file; *p; p++) {    if ((*p == '/')   #ifdef __NT__    || (*p == '\\')   #endif /* __NT__ */    )    dir = p+1;    }    if ((dir + CONSTANT_STRLEN("pike.so")) >= libpike_file + 2*MAXPATHLEN) {    /* Not likely to happen as long as MASTER_COOKIE is longer than "pike.so".
pike.git/src/main.c:368:   #define init_pike init_pike_var    LOOKUP(init_pike_runtime);   #define init_pike_runtime init_pike_runtime_var    LOOKUP(add_predefine);   #define add_predefine add_predefine_var      #endif /* LIBPIKE */       TRACE((stderr, "init_pike()\n"));    -  init_pike(argv, master_location + CONSTANT_STRLEN(MASTER_COOKIE)); +  init_pike(argv, master_file_location);       for(e=1; e<argc; e++)    {    TRACE((stderr, "Parse argument %d:\"%s\"...\n", e, argv[e]));       if(argv[e][0]=='-')    {    for(p=argv[e]+1; *p;)    {    switch(*p)
pike.git/src/main.c:623: Inside #if defined(HAVE_SETERRORMODE)
   SetErrorMode (0));    }   #endif       init_pike_runtime(exit);       /* NOTE: Reuse master_location here to avoid duplicates of    * the MASTER_COOKIE string in the binary.    */    add_pike_string_constant("__master_cookie", -  master_location, CONSTANT_STRLEN(MASTER_COOKIE)); +  _master_location, CONSTANT_STRLEN(MASTER_COOKIE));       if(SETJMP(back))    {    if(throw_severity == THROW_EXIT || throw_severity == THROW_THREAD_EXIT)    {    num=throw_value.u.integer;    }else{    if (TYPEOF(throw_value) == T_OBJECT &&    throw_value.u.object->prog == master_load_error_program &&    !get_master()) {