Преглед на файлове

[slam] Fix multicast address parsing

slam_parse_multicast_address() was failing to strip the initial "/"
from the URI path.
tags/v0.9.4
Michael Brown преди 17 години
родител
ревизия
81d92d5181
променени са 1 файла, в които са добавени 11 реда и са изтрити 8 реда
  1. 11
    8
      src/net/udp/slam.c

+ 11
- 8
src/net/udp/slam.c Целия файл

632
 static int slam_parse_multicast_address ( struct slam_request *slam,
632
 static int slam_parse_multicast_address ( struct slam_request *slam,
633
 					  const char *path,
633
 					  const char *path,
634
 					  struct sockaddr_in *address ) {
634
 					  struct sockaddr_in *address ) {
635
-	char path_dup[ strlen ( path ) + 1 ];
635
+	char path_dup[ strlen ( path ) /* no +1 */ ];
636
 	char *sep;
636
 	char *sep;
637
+	char *end;
637
 
638
 
638
-	/* Create temporary copy of path */
639
-	memcpy ( path_dup, path, sizeof ( path_dup ) );
639
+	/* Create temporary copy of path, minus the leading '/' */
640
+	assert ( *path == '/' );
641
+	memcpy ( path_dup, ( path + 1 ) , sizeof ( path_dup ) );
640
 
642
 
641
 	/* Parse port, if present */
643
 	/* Parse port, if present */
642
 	sep = strchr ( path_dup, ':' );
644
 	sep = strchr ( path_dup, ':' );
643
 	if ( sep ) {
645
 	if ( sep ) {
644
 		*(sep++) = '\0';
646
 		*(sep++) = '\0';
645
-		address->sin_port = htons ( strtoul ( sep, &sep, 0 ) );
646
-		if ( *sep != '\0' ) {
647
-			DBGC ( slam, "SLAM %p invalid multicast port\n",
648
-			       slam );
647
+		address->sin_port = htons ( strtoul ( sep, &end, 0 ) );
648
+		if ( *end != '\0' ) {
649
+			DBGC ( slam, "SLAM %p invalid multicast port "
650
+			       "\"%s\"\n", slam, sep );
649
 			return -EINVAL;
651
 			return -EINVAL;
650
 		}
652
 		}
651
 	}
653
 	}
652
 
654
 
653
 	/* Parse address */
655
 	/* Parse address */
654
 	if ( inet_aton ( path_dup, &address->sin_addr ) == 0 ) {
656
 	if ( inet_aton ( path_dup, &address->sin_addr ) == 0 ) {
655
-		DBGC ( slam, "SLAM %p invalid multicast address\n", slam );
657
+		DBGC ( slam, "SLAM %p invalid multicast address \"%s\"\n",
658
+		       slam, path_dup );
656
 		return -EINVAL;
659
 		return -EINVAL;
657
 	}
660
 	}
658
 
661
 

Loading…
Отказ
Запис