diff --git a/radmsg.c b/radmsg.c index 7bcbabb..750b166 100644 --- a/radmsg.c +++ b/radmsg.c @@ -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: */ diff --git a/radmsg.h b/radmsg.h index 1fc4d3b..fadc375 100644 --- a/radmsg.h +++ b/radmsg.h @@ -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*/ diff --git a/rewrite.c b/rewrite.c index 58e6aff..13921db 100644 --- a/rewrite.c +++ b/rewrite.c @@ -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; @@ -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; } diff --git a/rewrite.h b/rewrite.h index b7ead27..7176898 100644 --- a/rewrite.h +++ b/rewrite.h @@ -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); diff --git a/tlv11.c b/tlv11.c index 7516d6c..d570b39 100644 --- a/tlv11.c +++ b/tlv11.c @@ -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: */ diff --git a/tlv11.h b/tlv11.h index 5384481..84db3d7 100644 --- a/tlv11.h +++ b/tlv11.h @@ -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" */