alpine 3.6
shell weakness #48

4

Weakness Breakdown


Definition:

A shell weakness occurs when a program enables an attacker to execute unexpected commands on the operating system.

Warning code(s):

This causes a new program to execute and is difficult to use safely.

File Name:

gawk/src/gawk-4.1.4/vms/vms_popen.c

Context:

The highlighted line of code below is the trigger point of this particular Alpine 3.6 shell weakness.

 static void push_logicals(void);
static void pop_logicals(void);
static Itm *save_translation(const struct dsc$ descriptor_s *);
static void restore_translation(const struct dsc$ descriptor_s *, const Itm *);

typedef enum { unopened = 0, reading, writing } pipemode;
typedef struct pipe_info {
    char *command;
    char *name;
    pipemode pmode;
} PIPE;
static PIPE *pipes;
static int pipes_lim = 0;

#define psize(n) ((n) * sizeof(PIPE))
#define expand_pipes(k) do {  PIPE *new_p; \
	int new_p_lim = ((k) / _NFILE + 1) * _NFILE; \
	emalloc(new_p, PIPE *, psize(new_p_lim), "expand_pipes"); \
	if (pipes_lim > 0) \
		memcpy(new_p, pipes, psize(pipes_lim)),  free(pipes); \
	memset(new_p + psize(pipes_lim), 0, psize(new_p_lim - pipes_lim)); \
	pipes = new_p,  pipes_lim = new_p_lim;  } while(0)

FILE *
popen( const char *command, const char *mode )
{
    FILE *current;
    char *name;
    int   cur;
    pipemode curmode;

    if (strcmp(mode, "r") == 0)
	curmode = reading;
    else if (strcmp(mode, "w") == 0)
	curmode = writing;
    else
	return NULL;

    /* make a name for the temporary file */
    if ((name = mktemp(strdup("sys$ scratch:gawk-pipe_XXXXXX.tmp"))) == 0)
	return NULL;

    if (curmode == reading) {
	/* an input pipe reads a temporary file created by the command */
	vms_execute(command, (char *)0, name);	/* 'command >tempfile' */
    }
    if ((current = fopen(name, mode, "mbc=24", "mbf=2")) == NULL) {
	free(name);
	return NULL;
    } 

The registered trademark Linux® is used pursuant to a sublicense from the Linux Foundation, the exclusive licensee of Linus Torvalds, owner of the mark on a world­wide basis.