#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <ctype.h>
#define __STDC_FORMAT_MACROS 1
#include <inttypes.h>
std::list<QuotaInfo>::iterator it;
std::string quotaCmd;
+ if (!isNameLegal(iface)) {
+ ALOGE("setInterfaceQuota: Invalid iface \"%s\"", iface);
+ return -1;
+ }
+
if (!maxBytes) {
/* Don't talk about -1, deprecate it. */
ALOGE("Invalid bytes value. 1..max_int64.");
return getInterfaceQuota("shared", bytes);
}
+bool BandwidthController::isNameLegal(const char* name) {
+ size_t i;
+ size_t name_len = strlen(name);
+ if (name_len == 0) {
+ return false;
+ }
+
+ /* First character must be alphanumeric */
+ if (!isalnum(name[0])) {
+ return false;
+ }
+
+ for (i = 1; i < name_len; i++) {
+ if (!isalnum(name[i]) && (name[i] != '_') && (name[i] != '-') && (name[i] != ':')) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
int BandwidthController::getInterfaceQuota(const char *costName, int64_t *bytes) {
FILE *fp;
char *fname;
int scanRes;
+ if (!isNameLegal(costName)) {
+ ALOGE("getInterfaceQuota: Invalid costName \"%s\"", costName);
+ return -1;
+ }
+
asprintf(&fname, "/proc/net/xt_quota/%s", costName);
fp = fopen(fname, "r");
free(fname);
const char *costName;
std::list<QuotaInfo>::iterator it;
+ if (!isNameLegal(iface)) {
+ ALOGE("removeInterfaceQuota: Invalid iface \"%s\"", iface);
+ return -1;
+ }
+
if (StrncpyAndCheck(ifn, iface, sizeof(ifn))) {
ALOGE("Interface name longer than %d", MAX_IFACENAME_LEN);
return -1;
FILE *fp;
char *fname;
+ if (!isNameLegal(quotaName)) {
+ ALOGE("updateQuota: Invalid quotaName \"%s\"", quotaName);
+ return -1;
+ }
+
asprintf(&fname, "/proc/net/xt_quota/%s", quotaName);
fp = fopen(fname, "w");
free(fname);
int BandwidthController::setInterfaceAlert(const char *iface, int64_t bytes) {
std::list<QuotaInfo>::iterator it;
+ if (!isNameLegal(iface)) {
+ ALOGE("setInterfaceAlert: Invalid iface \"%s\"", iface);
+ return -1;
+ }
+
if (!bytes) {
ALOGE("Invalid bytes value. 1..max_int64.");
return -1;
int BandwidthController::removeInterfaceAlert(const char *iface) {
std::list<QuotaInfo>::iterator it;
+ if (!isNameLegal(iface)) {
+ ALOGE("removeInterfaceAlert: Invalid iface \"%s\"", iface);
+ return -1;
+ }
+
for (it = quotaIfaces.begin(); it != quotaIfaces.end(); it++) {
if (it->ifaceName == iface)
break;
int res = 0;
char *alertName;
+ if (!isNameLegal(costName)) {
+ ALOGE("setCostlyAlert: Invalid costName \"%s\"", costName);
+ return -1;
+ }
+
if (!bytes) {
ALOGE("Invalid bytes value. 1..max_int64.");
return -1;
char *alertName;
int res = 0;
+ if (!isNameLegal(costName)) {
+ ALOGE("removeCostlyAlert: Invalid costName \"%s\"", costName);
+ return -1;
+ }
+
asprintf(&alertName, "%sAlert", costName);
if (!*alertBytes) {
ALOGE("No prior alert set for %s alert", costName);