Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bugzilla DB migration completed. Please report issues to Infra team via email via infra@gentoo.org or IRC
View | Details | Raw Unified | Return to bug 523742 | Differences between
and this patch

Collapse All | Expand All

(-)a/bash/variables.c (-21 / +62 lines)
Lines 268-274 Link Here
268
static void propagate_temp_var __P((PTR_T));
268
static void propagate_temp_var __P((PTR_T));
269
static void dispose_temporary_env __P((sh_free_func_t *));     
269
static void dispose_temporary_env __P((sh_free_func_t *));     
270
270
271
static inline char *mk_env_string __P((const char *, const char *));
271
static inline char *mk_env_string __P((const char *, const char *, int));
272
static char **make_env_array_from_var_list __P((SHELL_VAR **));
272
static char **make_env_array_from_var_list __P((SHELL_VAR **));
273
static char **make_var_export_array __P((VAR_CONTEXT *));
273
static char **make_var_export_array __P((VAR_CONTEXT *));
274
static char **make_func_export_array __P((void));
274
static char **make_func_export_array __P((void));
Lines 301-306 Link Here
301
#endif
301
#endif
302
}
302
}
303
303
304
/* Prefix and suffix for environment variable names which contain
305
   shell functions. */
306
#define FUNCDEF_PREFIX "BASH_FUNC_"
307
#define FUNCDEF_PREFIX_LEN (strlen (FUNCDEF_PREFIX))
308
#define FUNCDEF_SUFFIX "()"
309
#define FUNCDEF_SUFFIX_LEN (strlen (FUNCDEF_SUFFIX))
310
311
304
/* Initialize the shell variables from the current environment.
312
/* Initialize the shell variables from the current environment.
305
   If PRIVMODE is nonzero, don't import functions from ENV or
313
   If PRIVMODE is nonzero, don't import functions from ENV or
306
   parse $SHELLOPTS. */
314
   parse $SHELLOPTS. */
Lines 338-364 Link Here
338
346
339
      /* If exported function, define it now.  Don't import functions from
347
      /* If exported function, define it now.  Don't import functions from
340
	 the environment in privileged mode. */
348
	 the environment in privileged mode. */
341
      if (privmode == 0 && read_but_dont_execute == 0 && STREQN ("() {", string, 4))
349
      if (privmode == 0 && read_but_dont_execute == 0
342
	{
350
	  && STREQN (FUNCDEF_PREFIX, name, FUNCDEF_PREFIX_LEN)
343
	  string_length = strlen (string);
351
	  && STREQ (name + char_index - FUNCDEF_SUFFIX_LEN, FUNCDEF_SUFFIX)
344
	  temp_string = (char *)xmalloc (3 + string_length + char_index);
352
	  && STREQN ("() {", string, 4))
353
	{
354
	  size_t name_length
355
	    = char_index - (FUNCDEF_PREFIX_LEN + FUNCDEF_SUFFIX_LEN);
356
	  char *temp_name = name + FUNCDEF_PREFIX_LEN;
357
	  /* Temporarily remove the suffix. */
358
	  temp_name[name_length] = '\0';
345
359
346
	  strcpy (temp_string, name);
360
	  string_length = strlen (string);
347
	  temp_string[char_index] = ' ';
361
	  temp_string = (char *)xmalloc (name_length + 1 + string_length + 1);
348
	  strcpy (temp_string + char_index + 1, string);
362
	  memcpy (temp_string, temp_name, name_length);
363
	  temp_string[name_length] = ' ';
364
	  memcpy (temp_string + name_length + 1, string, string_length + 1);
349
365
350
	  /* Don't import function names that are invalid identifiers from the
366
	  /* Don't import function names that are invalid identifiers from the
351
	     environment. */
367
	     environment. */
352
	  if (legal_identifier (name))
368
	  if (legal_identifier (temp_name))
353
	    parse_and_execute (temp_string, name, SEVAL_NONINT|SEVAL_NOHIST|SEVAL_FUNCDEF|SEVAL_ONECMD);
369
	    parse_and_execute (temp_string, temp_name,
370
			       SEVAL_NONINT|SEVAL_NOHIST|SEVAL_FUNCDEF|SEVAL_ONECMD);
354
371
355
	  if (temp_var = find_function (name))
372
	  if (temp_var = find_function (temp_name))
356
	    {
373
	    {
357
	      VSETATTR (temp_var, (att_exported|att_imported));
374
	      VSETATTR (temp_var, (att_exported|att_imported));
358
	      array_needs_making = 1;
375
	      array_needs_making = 1;
359
	    }
376
	    }
360
	  else
377
	  else
361
	    report_error (_("error importing function definition for `%s'"), name);
378
	    report_error (_("error importing function definition for `%s'"), name);
379
380
	  /* Restore the original suffix. */
381
	  temp_name[name_length] = FUNCDEF_SUFFIX[0];
362
	}
382
	}
363
#if defined (ARRAY_VARS)
383
#if defined (ARRAY_VARS)
364
#  if 0
384
#  if 0
Lines 2537-2543 Link Here
2537
  var->context = variable_context;	/* XXX */
2557
  var->context = variable_context;	/* XXX */
2538
2558
2539
  INVALIDATE_EXPORTSTR (var);
2559
  INVALIDATE_EXPORTSTR (var);
2540
  var->exportstr = mk_env_string (name, value);
2560
  var->exportstr = mk_env_string (name, value, 0);
2541
2561
2542
  array_needs_making = 1;
2562
  array_needs_making = 1;
2543
2563
Lines 3388-3409 Link Here
3388
/*								    */
3408
/*								    */
3389
/* **************************************************************** */
3409
/* **************************************************************** */
3390
3410
3411
/* Returns the string NAME=VALUE if !FUNCTIONP or if VALUE == NULL (in
3412
   which case it is treated as empty).  Otherwise, decorate NAME with
3413
   FUNCDEF_PREFIX and FUNCDEF_SUFFIX, and return a string of the form
3414
   FUNCDEF_PREFIX NAME FUNCDEF_SUFFIX = VALUE (without spaces).  */
3391
static inline char *
3415
static inline char *
3392
mk_env_string (name, value)
3416
mk_env_string (name, value, functionp)
3393
     const char *name, *value;
3417
     const char *name, *value;
3418
     int functionp;
3394
{
3419
{
3395
  int name_len, value_len;
3420
  size_t name_len, value_len;
3396
  char	*p;
3421
  char *p, *q;
3397
3422
3398
  name_len = strlen (name);
3423
  name_len = strlen (name);
3399
  value_len = STRLEN (value);
3424
  value_len = STRLEN (value);
3400
  p = (char *)xmalloc (2 + name_len + value_len);
3425
  if (functionp && value != NULL)
3401
  strcpy (p, name);
3426
    {
3402
  p[name_len] = '=';
3427
      p = (char *)xmalloc (FUNCDEF_PREFIX_LEN + name_len + FUNCDEF_SUFFIX_LEN
3428
			   + 1 + value_len + 1);
3429
      q = p;
3430
      memcpy (q, FUNCDEF_PREFIX, FUNCDEF_PREFIX_LEN);
3431
      q += FUNCDEF_PREFIX_LEN;
3432
      memcpy (q, name, name_len);
3433
      q += name_len;
3434
      memcpy (q, FUNCDEF_SUFFIX, FUNCDEF_SUFFIX_LEN);
3435
      q += FUNCDEF_SUFFIX_LEN;
3436
    }
3437
  else
3438
    {
3439
      p = (char *)xmalloc (name_len + 1 + value_len + 1);
3440
      memcpy (p, name, name_len);
3441
      q = p + name_len;
3442
    }
3443
  q[0] = '=';
3403
  if (value && *value)
3444
  if (value && *value)
3404
    strcpy (p + name_len + 1, value);
3445
    memcpy (q + 1, value, value_len + 1);
3405
  else
3446
  else
3406
    p[name_len + 1] = '\0';
3447
    q[1] = '\0';
3407
  return (p);
3448
  return (p);
3408
}
3449
}
3409
3450
Lines 3489-3495 Link Here
3489
	  /* Gee, I'd like to get away with not using savestring() if we're
3530
	  /* Gee, I'd like to get away with not using savestring() if we're
3490
	     using the cached exportstr... */
3531
	     using the cached exportstr... */
3491
	  list[list_index] = USE_EXPORTSTR ? savestring (value)
3532
	  list[list_index] = USE_EXPORTSTR ? savestring (value)
3492
					   : mk_env_string (var->name, value);
3533
	    : mk_env_string (var->name, value, function_p (var));
3493
3534
3494
	  if (USE_EXPORTSTR == 0)
3535
	  if (USE_EXPORTSTR == 0)
3495
	    SAVE_EXPORTSTR (var, list[list_index]);
3536
	    SAVE_EXPORTSTR (var, list[list_index]);

Return to bug 523742