forked from osmocom/wireshark
Fail somewhat gracefully if malloc() fails.
svn path=/trunk/; revision=15701
This commit is contained in:
parent
b9b159713a
commit
33d72d3b9d
|
@ -823,8 +823,8 @@ new_format_oid(subid_t *oid, guint oid_length,
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_SOME_SNMP
|
#ifdef HAVE_SOME_SNMP
|
||||||
static guchar *
|
static gboolean
|
||||||
check_var_length(guint vb_length, guint required_length)
|
check_var_length(guint vb_length, guint required_length, guchar **errmsg)
|
||||||
{
|
{
|
||||||
gchar *buf;
|
gchar *buf;
|
||||||
static const char badlen_fmt[] = "Length is %u, should be %u";
|
static const char badlen_fmt[] = "Length is %u, should be %u";
|
||||||
|
@ -834,10 +834,14 @@ check_var_length(guint vb_length, guint required_length)
|
||||||
should be XXX" message - 10 digits for each
|
should be XXX" message - 10 digits for each
|
||||||
XXX. */
|
XXX. */
|
||||||
buf = malloc(sizeof badlen_fmt + 10 + 10);
|
buf = malloc(sizeof badlen_fmt + 10 + 10);
|
||||||
g_snprintf(buf, sizeof badlen_fmt + 10 + 10, badlen_fmt, vb_length, required_length);
|
if (buf != NULL) {
|
||||||
return buf;
|
g_snprintf(buf, sizeof badlen_fmt + 10 + 10,
|
||||||
|
badlen_fmt, vb_length, required_length);
|
||||||
}
|
}
|
||||||
return NULL; /* length is OK */
|
*errmsg = buf;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return TRUE; /* length is OK */
|
||||||
}
|
}
|
||||||
|
|
||||||
static gchar *
|
static gchar *
|
||||||
|
@ -852,8 +856,7 @@ format_var(struct variable_list *variable, subid_t *variable_oid,
|
||||||
|
|
||||||
case SNMP_IPADDR:
|
case SNMP_IPADDR:
|
||||||
/* Length has to be 4 bytes. */
|
/* Length has to be 4 bytes. */
|
||||||
buf = check_var_length(val_len, 4);
|
if (!check_var_length(val_len, 4, &buf))
|
||||||
if (buf != NULL)
|
|
||||||
return buf; /* it's not 4 bytes */
|
return buf; /* it's not 4 bytes */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -861,8 +864,7 @@ format_var(struct variable_list *variable, subid_t *variable_oid,
|
||||||
/* not all counters are encoded as a full 64bit integer */
|
/* not all counters are encoded as a full 64bit integer */
|
||||||
case SNMP_COUNTER64:
|
case SNMP_COUNTER64:
|
||||||
/* Length has to be 8 bytes. */
|
/* Length has to be 8 bytes. */
|
||||||
buf = check_var_length(val_len, 8);
|
if (!check_var_length(val_len, 8, &buf))
|
||||||
if (buf != NULL)
|
|
||||||
return buf; /* it's not 8 bytes */
|
return buf; /* it's not 8 bytes */
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue