- break;
- }
- }
- }
- ealias = htons(base_alias + (RTSP_PORT_GROUP - 1));
- }
-
- if (salias && rtsp_link) {
-
- pkt_updated = 1;
-
- /* Copy into IP packet */
- sprintf(stemp, "%d", ntohs(salias));
- memcpy(port_newdata, stemp, strlen(stemp));
- port_newdata += strlen(stemp);
-
- if (eport != 0) {
- *port_newdata = '-';
- port_newdata++;
-
- /* Copy into IP packet */
- sprintf(stemp, "%d", ntohs(ealias));
- memcpy(port_newdata, stemp, strlen(stemp));
- port_newdata += strlen(stemp);
- }
-
- *port_newdata = ';';
- port_newdata++;
+ break;
+ }
+ }
+ }
+ ealias = htons(base_alias + (RTSP_PORT_GROUP - 1));
+ }
+
+ if (salias && rtsp_link) {
+ size_t lentmp;
+
+ /* Copy into IP packet */
+ sprintf(stemp, "%d", ntohs(salias));
+ lentmp = strlen(stemp);
+ /* account for ending ';' */
+ if (port_newdata + lentmp + 1 > newdata + sizeof(newdata)) {
+#if DEBUG
+ fprintf(stderr, "PacketAlias/RTSP: salias too far\n");
+#endif
+ break;
+ }
+ memcpy(port_newdata, stemp, lentmp);
+ port_newdata += lentmp;
+
+ if (eport != 0) {
+ sprintf(stemp, "%d", ntohs(ealias));
+ lentmp = strlen(stemp);
+
+ /* account for middle '-' and for ending ';' */
+ if (port_newdata + lentmp + 2 > newdata + sizeof(newdata)) {
+#if DEBUG
+ fprintf(stderr, "PacketAlias/RTSP: ealias too far\n");
+#endif
+ break;
+ }
+ *port_newdata = '-';
+ port_newdata++;
+
+ /* Copy into IP packet */
+ memcpy(port_newdata, stemp, lentmp);
+ port_newdata += lentmp;
+ }
+ pkt_updated = 1;
+
+ *port_newdata = ';';
+ port_newdata++;
+ }
+ state++;
+ break;
+ }
+ if (state > 3) {
+ break;
+ }