common: move strlen(apn) check into is_valid_apn()

This commit is contained in:
Alexander Couzens 2017-09-05 16:27:21 +02:00 committed by Denis Kenzior
parent 67b097124c
commit 7d27ccea5e
3 changed files with 7 additions and 12 deletions

View File

@ -31,6 +31,7 @@
#include <ofono/types.h>
#include "common.h"
#include "gprs-context.h"
#include "util.h"
struct error_entry {
@ -702,9 +703,15 @@ gboolean is_valid_apn(const char *apn)
int i;
int last_period = 0;
if (apn == NULL)
return FALSE;
if (apn[0] == '.' || apn[0] == '\0')
return FALSE;
if (strlen(apn) > OFONO_GPRS_MAX_APN_LENGTH)
return FALSE;
for (i = 0; apn[i] != '\0'; i++) {
if (g_ascii_isalnum(apn[i]))
continue;

View File

@ -1027,9 +1027,6 @@ static DBusMessage *pri_set_apn(struct pri_context *ctx, DBusConnection *conn,
{
GKeyFile *settings = ctx->gprs->settings;
if (strlen(apn) > OFONO_GPRS_MAX_APN_LENGTH)
return __ofono_error_invalid_format(msg);
if (g_str_equal(apn, ctx->context.apn))
return dbus_message_new_method_return(msg);
@ -2376,9 +2373,6 @@ static void provision_context(const struct ofono_gprs_provision_data *ap,
if (ap->name && strlen(ap->name) > MAX_CONTEXT_NAME_LENGTH)
return;
if (ap->apn == NULL || strlen(ap->apn) > OFONO_GPRS_MAX_APN_LENGTH)
return;
if (is_valid_apn(ap->apn) == FALSE)
return;
@ -3228,9 +3222,6 @@ static gboolean load_context(struct ofono_gprs *gprs, const char *group)
if (apn == NULL)
goto error;
if (strlen(apn) > OFONO_GPRS_MAX_APN_LENGTH)
goto error;
if (type == OFONO_GPRS_CONTEXT_TYPE_MMS) {
msgproxy = g_key_file_get_string(gprs->settings, group,
"MessageProxy", NULL);

View File

@ -152,9 +152,6 @@ static DBusMessage *lte_set_default_apn(struct ofono_lte *lte,
if (lte->pending)
return __ofono_error_busy(msg);
if (strlen(apn) > OFONO_GPRS_MAX_APN_LENGTH)
return __ofono_error_invalid_format(msg);
if (g_str_equal(apn, lte->info.apn))
return dbus_message_new_method_return(msg);