Skip to content

Commit

Permalink
Fix use of uninitialized values
Browse files Browse the repository at this point in the history
  • Loading branch information
gilles-chanteperdrix committed Nov 28, 2015
1 parent f62f405 commit adf9352
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 14 deletions.
9 changes: 7 additions & 2 deletions common.h
Expand Up @@ -143,7 +143,7 @@ static inline int split_ip_netmask(int family,
char *tmp;
unsigned long ul;

int netmask_length;
int netmask_length, err;

/* IPv4 */
if (family == AF_INET)
Expand All @@ -159,10 +159,15 @@ static inline int split_ip_netmask(int family,
if (tmp != NULL) {
*tmp = '\0';
++tmp;
if (mystrtoul(&ul, tmp, netmask_length) == -ERANGE) {
err = mystrtoul(&ul, tmp, netmask_length);
if (err == -ERANGE) {
log_error("%s", "CIDR netmask out of range");
return -ERANGE;
}
if (err == -EINVAL) {
log_error("Error parsing %s as a number", tmp);
return -EINVAL;
}
if (netmask != NULL)
*netmask = (uint8_t) ul;
}
Expand Down
58 changes: 46 additions & 12 deletions vrrp_options.c
Expand Up @@ -70,7 +70,7 @@ static void vrrp_usage(void)
int vrrp_options(struct vrrp *vrrp, struct vrrp_net *vnet, int argc,
char *argv[])
{
int optc;
int optc, err;
unsigned long opt; /* strtoul */

static struct option const opts[] = {
Expand All @@ -97,13 +97,21 @@ int vrrp_options(struct vrrp *vrrp, struct vrrp_net *vnet, int argc,

/* vrid */
case 'v':
if ((mystrtoul(&opt, optarg, VRID_MAX) == -ERANGE)
|| (opt == 0)) {
err = mystrtoul(&opt, optarg, VRID_MAX);
if (err == -ERANGE || (err == 0 && opt == 0)) {
fprintf(stderr, "1 < vrid < 255\n");
vrrp_usage();
return -1;
return err;
}
vrrp->vrid = vnet->vrid = (uint8_t) opt;
if (err == -EINVAL) {
fprintf(stderr,
"Error parsing \"%s\" as a number\n",
optarg);
vrrp_usage();
return err;
}

vrrp->vrid = vnet->vrid = (uint8_t)opt;
break;

/* interface */
Expand All @@ -117,21 +125,39 @@ int vrrp_options(struct vrrp *vrrp, struct vrrp_net *vnet, int argc,

/* priority */
case 'p':
if (mystrtoul(&opt, optarg, VRRP_PRIO_MAX) == -ERANGE) {
err = mystrtoul(&opt, optarg, VRRP_PRIO_MAX);
if (err == -ERANGE) {
fprintf(stderr, "0 < priority < 255\n");
vrrp_usage();
return -1;
}
vrrp->priority = (uint8_t) opt;
if (err == -EINVAL) {
fprintf(stderr,
"Error parsing \"%s\" as a number\n",
optarg);
vrrp_usage();
return err;
}

vrrp->priority = (uint8_t)opt;
break;

/* delay */
case 't':
if (mystrtoul(&opt, optarg, ADVINT_MAX) == -ERANGE) {
err = mystrtoul(&opt, optarg, ADVINT_MAX);
if (err == -ERANGE) {
vrrp_usage();
return -1;
}
vrrp->adv_int = (uint16_t) opt;
if (err == -EINVAL) {
fprintf(stderr,
"Error parsing \"%s\" as a number\n",
optarg);
vrrp_usage();
return err;
}

vrrp->adv_int = (uint16_t)opt;
break;

/* preempt mode */
Expand All @@ -150,12 +176,20 @@ int vrrp_options(struct vrrp *vrrp, struct vrrp_net *vnet, int argc,

/* RFC - version */
case 'r':
if ((mystrtoul(&opt, optarg, RFC5798) == -ERANGE)
|| (opt < RFC3768)) {
fprintf(stderr, "Version 2 or 3 : %ld\n", opt);
err = mystrtoul(&opt, optarg, RFC5798);
if (err == -ERANGE || (err == 0 && opt < RFC3768)) {
fprintf(stderr, "Version 2 or 3 : %s\n", optarg);
vrrp_usage();
return -1;
}
if (err == -EINVAL) {
fprintf(stderr,
"Error parsing \"%s\" as a number\n",
optarg);
vrrp_usage();
return err;
}

vrrp->version = (uint8_t) opt;
break;

Expand Down

0 comments on commit adf9352

Please sign in to comment.