Branch: Tag:

2014-06-19

2014-06-19 14:30:42 by Per Hedbor <ph@opera.com>

Made _master_location read-only.

91:   #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)
136:      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
151:       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__
169: Inside #if defined(__NT__)
   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
270: Inside #if defined(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__
375:       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++)    {
630:    * 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))    {