Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
move resizeattr/resizetlv to respective knowledge owners
  • Loading branch information
Fabian Mauchle committed Apr 15, 2019
1 parent a3e64eb commit 4a3361f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
9 changes: 9 additions & 0 deletions radmsg.c
Expand Up @@ -405,6 +405,15 @@ struct tlv *makevendortlv(uint32_t vendor, struct tlv *attr){
return newtlv;
}

int resizeattr(struct tlv *attr, uint8_t newlen) {
if (newlen > RAD_Max_Attr_Value_Length)
return 0;

if (resizetlv(attr, newlen))
return 1;
return 0;
}

/* Local Variables: */
/* c-file-style: "stroustrup" */
/* End: */
1 change: 1 addition & 0 deletions radmsg.h
Expand Up @@ -58,6 +58,7 @@ uint8_t attrname2val(char *attrname);
int vattrname2val(char *attrname, uint32_t *vendor, uint32_t *type);
int attrvalidate(unsigned char *attrs, int length);
struct tlv *makevendortlv(uint32_t vendor, struct tlv *attr);
int resizeattr(struct tlv *attr, uint8_t newlen);

#endif /*_RADMSG_H*/

Expand Down
23 changes: 1 addition & 22 deletions rewrite.c
Expand Up @@ -278,22 +278,6 @@ struct rewrite *getrewrite(char *alt1, char *alt2) {
return NULL;
}

int resizeattr(struct tlv *attr, uint8_t newlen) {
uint8_t *newv;

if (newlen > RAD_Max_Attr_Value_Length)
return 0;

if (newlen != attr->l) {
newv = realloc(attr->v, newlen);
if (newlen && !newv)
return 0;
attr->v = newv;
attr->l = newlen;
}
return 1;
}

int findvendorsubattr(uint32_t *attrs, uint32_t vendor, uint32_t subattr) {
if (!attrs)
return 0;
Expand Down Expand Up @@ -393,13 +377,8 @@ int dorewritemodattr(struct tlv *attr, struct modattr *modattr) {
}
}
reslen += i - start;
if (reslen > 253) {
debug(DBG_INFO, "rewritten attribute length would be %d, max possible is 253, discarding message", reslen);
free(in);
return 0;
}

if (!resizeattr(attr, reslen)) {
debug(DBG_INFO, "rewritten attribute to length %d failed, discarding message", reslen);
free(in);
return 0;
}
Expand Down
1 change: 0 additions & 1 deletion rewrite.h
Expand Up @@ -27,7 +27,6 @@ void addrewrite(char *value, char **rmattrs, char **rmvattrs, char **addattrs,
int dorewrite(struct radmsg *msg, struct rewrite *rewrite);
struct modattr *extractmodattr(char *nameval);
struct rewrite *getrewrite(char *alt1, char *alt2);
int resizeattr(struct tlv *attr, uint8_t newlen);

int dorewritemodattr(struct tlv *attr, struct modattr *modattr);
int addvendorattr(struct radmsg *msg, uint32_t vendor, struct tlv *attr);
Expand Down
12 changes: 12 additions & 0 deletions tlv11.c
Expand Up @@ -105,6 +105,18 @@ uint8_t *tlv2str(struct tlv *tlv) {
return s;
}

struct tlv *resizetlv(struct tlv *tlv, uint8_t newlen) {
uint8_t *newv;
if (newlen != tlv->l) {
newv = realloc(tlv->v, newlen);
if (newlen && !newv)
return NULL;
tlv->v = newv;
tlv->l = newlen;
}
return tlv;
}

/* Local Variables: */
/* c-file-style: "stroustrup" */
/* End: */
1 change: 1 addition & 0 deletions tlv11.h
Expand Up @@ -16,6 +16,7 @@ struct list *copytlvlist(struct list *);
void freetlvlist(struct list *);
void rmtlv(struct list *, uint8_t);
uint8_t *tlv2str(struct tlv *tlv);
struct tlv *resizetlv(struct tlv *, uint8_t);

/* Local Variables: */
/* c-file-style: "stroustrup" */
Expand Down

0 comments on commit 4a3361f

Please sign in to comment.