Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Rename 'value' field of struct oc_form_opt to discourage direct access
You shoud now be using openconnect_set_option_value() which will strdup()
for itself, rather than allocating elsewhere and setting it directly.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Oct 9, 2014
1 parent 19fbe2e commit 4b700c5
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 45 deletions.
30 changes: 15 additions & 15 deletions auth.c
Expand Up @@ -50,15 +50,15 @@ int openconnect_set_option_value(struct oc_form_opt *opt, const char *value)

for (i=0; i<sopt->nr_choices; i++) {
if (value == sopt->choices[i]->name) {
opt->value = sopt->choices[i]->name;
opt->_value = sopt->choices[i]->name;
return 0;
}
}
return -EINVAL;
}

opt->value = strdup(value);
if (!opt->value)
opt->_value = strdup(value);
if (!opt->_value)
return -ENOMEM;

return 0;
Expand Down Expand Up @@ -86,7 +86,7 @@ static int append_form_opts(struct openconnect_info *vpninfo,
int ret;

for (opt = form->opts; opt; opt = opt->next) {
ret = append_opt(body, opt->name, opt->value);
ret = append_opt(body, opt->name, opt->_value);
if (ret)
return ret;
}
Expand All @@ -97,7 +97,7 @@ static void free_opt(struct oc_form_opt *opt)
{
/* for SELECT options, opt->value is a pointer to oc_choice->name */
if (opt->type != OC_FORM_OPT_SELECT)
free(opt->value);
free(opt->_value);
else {
struct oc_form_opt_select *sel = (void *)opt;
int i;
Expand Down Expand Up @@ -269,7 +269,7 @@ static int parse_form(struct openconnect_info *vpninfo, struct oc_auth_form *for

if (!strcmp(input_type, "hidden")) {
opt->type = OC_FORM_OPT_HIDDEN;
opt->value = (char *)xmlGetProp(xml_node, (unsigned char *)"value");
opt->_value = (char *)xmlGetProp(xml_node, (unsigned char *)"value");
} else if (!strcmp(input_type, "text")) {
opt->type = OC_FORM_OPT_TEXT;
} else if (!strcmp(input_type, "password")) {
Expand Down Expand Up @@ -700,8 +700,8 @@ void nuke_opt_values(struct oc_form_opt *opt)
for (; opt; opt = opt->next) {
if (opt->type == OC_FORM_OPT_TEXT ||
opt->type == OC_FORM_OPT_PASSWORD) {
free(opt->value);
opt->value = NULL;
free(opt->_value);
opt->_value = NULL;
}
}
}
Expand Down Expand Up @@ -744,8 +744,8 @@ int process_auth_form(struct openconnect_info *vpninfo, struct oc_auth_form *for
opt->flags |= OC_FORM_OPT_IGNORE;
else if (!strcmp(opt->name, "secondary_username") && second_auth) {
if (auth_choice->secondary_username) {
free(opt->value);
opt->value = strdup(auth_choice->secondary_username);
free(opt->_value);
opt->_value = strdup(auth_choice->secondary_username);
}
if (!auth_choice->secondary_username_editable)
opt->flags |= OC_FORM_OPT_IGNORE;
Expand All @@ -756,9 +756,9 @@ int process_auth_form(struct openconnect_info *vpninfo, struct oc_auth_form *for

if (ret == OC_FORM_RESULT_NEWGROUP &&
form->authgroup_opt &&
form->authgroup_opt->form.value) {
form->authgroup_opt->form._value) {
free(vpninfo->authgroup);
vpninfo->authgroup = strdup(form->authgroup_opt->form.value);
vpninfo->authgroup = strdup(form->authgroup_opt->form._value);

if (!vpninfo->xmlpost)
goto retry;
Expand Down Expand Up @@ -1009,7 +1009,7 @@ static int xmlpost_append_form_opts(struct openconnect_info *vpninfo,
for (opt = form->opts; opt; opt = opt->next) {
/* group_list: create a new <group-select> node under <config-auth> */
if (!strcmp(opt->name, "group_list")) {
if (!xmlNewTextChild(root, NULL, XCAST("group-select"), XCAST(opt->value)))
if (!xmlNewTextChild(root, NULL, XCAST("group-select"), XCAST(opt->_value)))
goto bad;
continue;
}
Expand All @@ -1018,7 +1018,7 @@ static int xmlpost_append_form_opts(struct openconnect_info *vpninfo,
if (!strcmp(opt->name, "answer") ||
!strcmp(opt->name, "whichpin") ||
!strcmp(opt->name, "new_password")) {
if (!xmlNewTextChild(node, NULL, XCAST("password"), XCAST(opt->value)))
if (!xmlNewTextChild(node, NULL, XCAST("password"), XCAST(opt->_value)))
goto bad;
continue;
}
Expand All @@ -1030,7 +1030,7 @@ static int xmlpost_append_form_opts(struct openconnect_info *vpninfo,
}

/* everything else: create <foo>user_input</foo> under <auth> */
if (!xmlNewTextChild(node, NULL, XCAST(opt->name), XCAST(opt->value)))
if (!xmlNewTextChild(node, NULL, XCAST(opt->name), XCAST(opt->_value)))
goto bad;
}

Expand Down
8 changes: 4 additions & 4 deletions gnutls.c
Expand Up @@ -2287,14 +2287,14 @@ static P11KitPin *pin_callback(const char *pin_source, P11KitUri *pin_uri,
o.type = OC_FORM_OPT_PASSWORD;
o.name = (char *)"pkcs11_pin";
o.label = (char *)_("Enter PIN:");
o.value = NULL;
o._value = NULL;

ret = process_auth_form(vpninfo, &f);
if (ret || !o.value)
if (ret || !o._value)
return NULL;

pin = p11_kit_pin_new_for_string(o.value);
(*cache)->pin = o.value;
pin = p11_kit_pin_new_for_string(o._value);
(*cache)->pin = o._value;

return pin;
}
Expand Down
12 changes: 6 additions & 6 deletions jni.c
Expand Up @@ -391,7 +391,7 @@ static int add_form_option(struct libctx *ctx, jobject jform, struct oc_form_opt
if (set_int(ctx, jopt, "type", opt->type) ||
set_string(ctx, jopt, "name", opt->name) ||
set_string(ctx, jopt, "label", opt->label) ||
set_string(ctx, jopt, "value", opt->value) ||
set_string(ctx, jopt, "value", opt->_value) ||
set_long(ctx, jopt, "flags", opt->flags))
return -1;

Expand All @@ -406,7 +406,7 @@ static char *lookup_choice_name(struct oc_form_opt_select *opt, const char *name
{
int i;

/* opt->value is NOT a caller-allocated string for OC_FORM_OPT_SELECT */
/* opt->_value is NOT a caller-allocated string for OC_FORM_OPT_SELECT */
for (i = 0; i < opt->nr_choices; i++)
if (!strcmp(opt->choices[i]->name, name))
return opt->choices[i]->name;
Expand Down Expand Up @@ -465,11 +465,11 @@ static int process_auth_form_cb(void *privdata, struct oc_auth_form *form)
goto err;

if (opt->type == OC_FORM_OPT_SELECT)
opt->value = lookup_choice_name((void *)opt, tmp);
opt->_value = lookup_choice_name((void *)opt, tmp);
else {
free(opt->value);
opt->value = strdup(tmp);
if (!opt->value)
free(opt->_value);
opt->_value = strdup(tmp);
if (!opt->_value)
OOM(ctx->jenv);
}
(*ctx->jenv)->ReleaseStringUTFChars(ctx->jenv, jvalue, tmp);
Expand Down
16 changes: 8 additions & 8 deletions main.c
Expand Up @@ -1597,7 +1597,7 @@ static int match_choice_label(struct openconnect_info *vpninfo,

if (!strncasecmp(label, choice->label, input_len)) {
if (strlen(choice->label) == input_len) {
select_opt->form.value = choice->name;
select_opt->form._value = choice->name;
return 0;
} else {
match = choice->name;
Expand All @@ -1607,7 +1607,7 @@ static int match_choice_label(struct openconnect_info *vpninfo,
}

if (partial_matches == 1) {
select_opt->form.value = match;
select_opt->form._value = match;
return 0;
} else if (partial_matches > 1) {
vpn_progress(vpninfo, PRG_ERR,
Expand Down Expand Up @@ -1736,26 +1736,26 @@ static int process_auth_form_cb(void *_vpninfo,
} else if (opt->type == OC_FORM_OPT_TEXT) {
if (username &&
!strcmp(opt->name, "username")) {
opt->value = username;
opt->_value = username;
username = NULL;
} else {
opt->value = prompt_for_input(opt->label, vpninfo, 0);
opt->_value = prompt_for_input(opt->label, vpninfo, 0);
}

if (!opt->value)
if (!opt->_value)
goto err;
empty = 0;

} else if (opt->type == OC_FORM_OPT_PASSWORD) {
if (password &&
!strcmp(opt->name, "password")) {
opt->value = password;
opt->_value = password;
password = NULL;
} else {
opt->value = prompt_for_input(opt->label, vpninfo, 1);
opt->_value = prompt_for_input(opt->label, vpninfo, 1);
}

if (!opt->value)
if (!opt->_value)
goto err;
empty = 0;
}
Expand Down
8 changes: 4 additions & 4 deletions oath.c
Expand Up @@ -304,8 +304,8 @@ int do_gen_totp_code(struct openconnect_info *vpninfo,
}

vpninfo->token_tries++;
opt->value = strdup(tokencode);
return opt->value ? 0 : -ENOMEM;
opt->_value = strdup(tokencode);
return opt->_value ? 0 : -ENOMEM;
}

static void buf_append_base32(struct oc_text_buf *buf, void *data, int len)
Expand Down Expand Up @@ -427,11 +427,11 @@ int do_gen_hotp_code(struct openconnect_info *vpninfo,
}
vpninfo->token_time++;
vpninfo->token_tries++;
opt->value = strdup(tokencode);
opt->_value = strdup(tokencode);
if (vpninfo->unlock_token) {
char *new_tok = regen_hotp_secret(vpninfo);
vpninfo->unlock_token(vpninfo->tok_cbdata, new_tok);
free(new_tok);
}
return opt->value ? 0 : -ENOMEM;
return opt->_value ? 0 : -ENOMEM;
}
2 changes: 1 addition & 1 deletion openconnect.h
Expand Up @@ -153,7 +153,7 @@ struct oc_form_opt {
int type;
char *name;
char *label;
char *value; /* Use openconnect_set_option_value() to set this */
char *_value; /* Use openconnect_set_option_value() to set this */
unsigned int flags;
void *reserved;
};
Expand Down
4 changes: 2 additions & 2 deletions ssl.c
Expand Up @@ -357,11 +357,11 @@ int request_passphrase(struct openconnect_info *vpninfo, const char *label,
o.type = OC_FORM_OPT_PASSWORD;
o.name = (char *)label;
o.label = buf;
o.value = NULL;
o._value = NULL;

ret = process_auth_form(vpninfo, &f);
if (!ret) {
*response = o.value;
*response = o._value;
return 0;
}

Expand Down
10 changes: 5 additions & 5 deletions stoken.c
Expand Up @@ -80,14 +80,14 @@ static int decrypt_stoken(struct openconnect_info *vpninfo)
opt->type = OC_FORM_OPT_TEXT;
opt->name = (char *)"devid";
opt->label = _("Device ID:");
devid = &opt->value;
devid = &opt->_value;
opt++;
}
if (stoken_pass_required(vpninfo->stoken_ctx)) {
opt->type = OC_FORM_OPT_PASSWORD;
opt->name = (char *)"password";
opt->label = _("Password:");
pass = &opt->value;
pass = &opt->_value;
opt++;
}

Expand All @@ -108,7 +108,7 @@ static int decrypt_stoken(struct openconnect_info *vpninfo)
break;

for (opt = opts; opt; opt = opt->next) {
if (!opt->value || !strlen(opt->value))
if (!opt->_value || !strlen(opt->_value))
some_empty = 1;
else
all_empty = 0;
Expand Down Expand Up @@ -199,7 +199,7 @@ static int request_stoken_pin(struct openconnect_info *vpninfo)
if (ret)
break;

pin = opt->value;
pin = opt->_value;
if (!pin || !strlen(pin)) {
/* in some cases there really is no PIN */
if (vpninfo->stoken_concat_pin)
Expand Down Expand Up @@ -307,7 +307,7 @@ int do_gen_stoken_code(struct openconnect_info *vpninfo,

vpninfo->token_tries++;

if (asprintf(&opt->value, "%s%s",
if (asprintf(&opt->_value, "%s%s",
(vpninfo->stoken_concat_pin && vpninfo->stoken_pin) ? vpninfo->stoken_pin : "",
tokencode) < 0)
return -ENOMEM;
Expand Down

0 comments on commit 4b700c5

Please sign in to comment.