mirror of
https://gitea.osmocom.org/cellular-infrastructure/osmo-mgw.git
synced 2025-11-02 13:03:33 +00:00
Catch unsigned integer MGCP parsing errors with strtoul
Checks to find if strotul failed are taken both from: man strtoul man strtol Change-Id: Ifba1c1e3151d6f92f9da3d4ca2569a5908455ca8
This commit is contained in:
@@ -36,6 +36,8 @@
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
|
||||
#ifndef OSMUX_CID_MAX
|
||||
#define OSMUX_CID_MAX 255 /* FIXME: use OSMUX_CID_MAX from libosmo-netif? */
|
||||
@@ -265,6 +267,7 @@ static bool mgcp_line_is_valid(const char *line)
|
||||
static int mgcp_parse_audio_port_pt(struct mgcp_response *r, char *line)
|
||||
{
|
||||
char *pt_str;
|
||||
char *pt_end;
|
||||
unsigned int pt;
|
||||
unsigned int count = 0;
|
||||
unsigned int i;
|
||||
@@ -289,7 +292,11 @@ static int mgcp_parse_audio_port_pt(struct mgcp_response *r, char *line)
|
||||
pt_str = strtok(NULL, " ");
|
||||
if (!pt_str)
|
||||
break;
|
||||
pt = atoi(pt_str);
|
||||
errno = 0;
|
||||
pt = strtoul(pt_str, &pt_end, 0);
|
||||
if ((errno == ERANGE && pt == ULONG_MAX) || (errno && !pt) ||
|
||||
pt_str == pt_end)
|
||||
goto response_parse_failure_pt;
|
||||
|
||||
/* Do not allow duplicate payload types */
|
||||
for (i = 0; i < count; i++)
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
#include <osmocom/mgcp/mgcp_sdp.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
|
||||
/* Two structs to store intermediate parsing results. The function
|
||||
* mgcp_parse_sdp_data() is using the following two structs as temporary
|
||||
@@ -129,6 +131,7 @@ static int pt_from_sdp(void *ctx, struct sdp_rtp_map *codecs,
|
||||
char *str;
|
||||
char *str_ptr;
|
||||
char *pt_str;
|
||||
char *pt_end;
|
||||
unsigned int pt;
|
||||
unsigned int count = 0;
|
||||
unsigned int i;
|
||||
@@ -154,7 +157,11 @@ static int pt_from_sdp(void *ctx, struct sdp_rtp_map *codecs,
|
||||
if (!pt_str)
|
||||
break;
|
||||
|
||||
pt = atoi(pt_str);
|
||||
errno = 0;
|
||||
pt = strtoul(pt_str, &pt_end, 0);
|
||||
if ((errno == ERANGE && pt == ULONG_MAX) || (errno && !pt) ||
|
||||
pt_str == pt_end)
|
||||
goto error;
|
||||
|
||||
/* Do not allow duplicate payload types */
|
||||
for (i = 0; i < count; i++)
|
||||
|
||||
Reference in New Issue
Block a user