Bug 1584473 - Fix wrong arguments to memset(), snprintf(), strncmp() in libical. r=darktrojan
authorJorg K <jorgk@jorgk.com>
Sat, 28 Sep 2019 22:13:45 +0200
changeset 37021 c2fa91efcf51c4c42ed07ec591c63e08899a58f5
parent 37020 f4e434bb94fb300ff689511a964598c9644ac440
child 37022 382c8c0732f066c38525cf870c474707ac820582
push id395
push userclokep@gmail.com
push dateMon, 02 Dec 2019 19:38:57 +0000
reviewersdarktrojan
bugs1584473
Bug 1584473 - Fix wrong arguments to memset(), snprintf(), strncmp() in libical. r=darktrojan
calendar/libical/src/libical/icalmime.c
calendar/libical/src/libical/icalparameter.c
calendar/libical/src/libical/icaltimezone.c
calendar/libical/src/libical/sspm.c
--- a/calendar/libical/src/libical/icalmime.c
+++ b/calendar/libical/src/libical/icalmime.c
@@ -187,17 +187,17 @@ icalcomponent* icalmime_parse(char* (*ge
     icalcomponent *root=0, *parent=0, *comp=0, *last = 0;
 
     if ( (parts = (struct sspm_part *)
 	  malloc(NUM_PARTS*sizeof(struct sspm_part)))==0) {
 	icalerror_set_errno(ICAL_NEWFAILED_ERROR);
 	return 0;
     }
 
-    memset(parts,0,sizeof(parts));
+    memset(parts,0,sizeof(NUM_PARTS*sizeof(struct sspm_part)));
 
     sspm_parse_mime(parts, 
 		    NUM_PARTS, /* Max parts */
 		    icalmime_local_action_map, /* Actions */ 
 		    get_string,
 		    data, /* data for get_string*/
 		    0 /* First header */);
 
@@ -377,17 +377,17 @@ int icalmime_test(char* (*get_string)(ch
     int i;
 
     if ( (parts = (struct sspm_part *)
 	  malloc(NUM_PARTS*sizeof(struct sspm_part)))==0) {
 	icalerror_set_errno(ICAL_NEWFAILED_ERROR);
 	return 0;
     }
 
-    memset(parts,0,sizeof(parts));
+    memset(parts,0,sizeof(NUM_PARTS*sizeof(struct sspm_part)));
 
     sspm_parse_mime(parts, 
 		    NUM_PARTS, /* Max parts */
 		    icalmime_local_action_map, /* Actions */ 
 		    get_string,
 		    data, /* data for get_string*/
 		    0 /* First header */);
 
--- a/calendar/libical/src/libical/icalparameter.c
+++ b/calendar/libical/src/libical/icalparameter.c
@@ -106,17 +106,17 @@ icalparameter_free (icalparameter* param
     if (param->string != 0){
 	free ((void*)param->string);
     }
     
     if (param->x_name != 0){
 	free ((void*)param->x_name);
     }
     
-    memset(param,0,sizeof(param));
+    memset(param,0,sizeof(icalparameter));
 
     param->parent = 0;
     param->id[0] = 'X';
     free(param);
 }
 
 
 
--- a/calendar/libical/src/libical/icaltimezone.c
+++ b/calendar/libical/src/libical/icaltimezone.c
@@ -159,17 +159,17 @@ static void  icaltimezone_parse_zone_tab
 
 #ifdef USE_BUILTIN_TZDATA
 static char* icaltimezone_load_get_line_fn	(char		*s,
 						 size_t		 size,
 						 void		*data);
 #endif
 
 static void  format_utc_offset			(int		 utc_offset,
-						 char		*buffer);
+						 char		*buffer, size_t buffer_size);
 static const char* get_zone_directory(void);
 
 /** Creates a new icaltimezone. */
 icaltimezone*
 icaltimezone_new			(void)
 {
     icaltimezone *zone;
 
@@ -1863,30 +1863,30 @@ icaltimezone_dump_changes		(icaltimezone
 
 	fprintf (fp, "%s\t%2i %s %04i\t%2i:%02i:%02i",
 		zone->location,
 		zone_change->day, months[zone_change->month - 1],
 		zone_change->year,
 		zone_change->hour, zone_change->minute, zone_change->second);
 
 	/* Wall Clock Time offset from UTC. */
-	format_utc_offset (zone_change->utc_offset, buffer);
+	format_utc_offset (zone_change->utc_offset, buffer, sizeof(buffer));
 	fprintf (fp, "\t%s", buffer);
 
 	fprintf (fp, "\n");
     }
 	return 1;
 }
 
 
 /** This formats a UTC offset as "+HHMM" or "+HHMMSS".
    buffer should have space for 8 characters. */
 static void
 format_utc_offset			(int		 utc_offset,
-					 char		*buffer)
+					 char		*buffer, size_t buffer_size)
 {
   const char *sign = "+";
   int hours, minutes, seconds;
 
   if (utc_offset < 0) {
     utc_offset = -utc_offset;
     sign = "-";
   }
@@ -1900,19 +1900,19 @@ format_utc_offset			(int		 utc_offset,
      (The maximum offset is 15 hours 56 minutes at present.) */
   if (hours < 0 || hours >= 24 || minutes < 0 || minutes >= 60
       || seconds < 0 || seconds >= 60) {
     fprintf (stderr, "Warning: Strange timezone offset: H:%i M:%i S:%i\n",
 	     hours, minutes, seconds);
   }
 
   if (seconds == 0)
-    snprintf (buffer, sizeof(buffer), "%s%02i%02i", sign, hours, minutes);
+    snprintf (buffer, buffer_size, "%s%02i%02i", sign, hours, minutes);
   else
-    snprintf (buffer, sizeof(buffer), "%s%02i%02i%02i", sign, hours, minutes, seconds);
+    snprintf (buffer, buffer_size, "%s%02i%02i%02i", sign, hours, minutes, seconds);
 }
 
 static const char* get_zone_directory(void)
 {
 #ifndef WIN32
 	return zone_files_directory == NULL ? ZONEINFO_DIRECTORY : zone_files_directory;
 #else
 	wchar_t wbuffer[1000];
--- a/calendar/libical/src/libical/sspm.c
+++ b/calendar/libical/src/libical/sspm.c
@@ -699,18 +699,17 @@ void* sspm_make_part(struct mime_impl *i
 			break;
 		    }
 		}
 		free(boundary);
 
 		break;
 	    }
 	    
-	    if(strncmp((line+2),parent_header->boundary,
-		       sizeof(parent_header->boundary)) == 0){
+	    if(strcmp((line+2),parent_header->boundary) == 0) {
 		*end_part = action.end_part(part);
 
 		if(sspm_is_mime_boundary(line)){
 		    impl->state = END_OF_PART;
 		} else if ( sspm_is_mime_terminating_boundary(line)){
 		    impl->state = TERMINAL_END_OF_PART;
 		}
 		end = 1;
@@ -805,18 +804,17 @@ void* sspm_make_multipart_subpart(struct
     if(get_line_type(impl->temp) != BOUNDARY){
 	while((line=sspm_get_next_line(impl)) != 0 ){
 	    if(sspm_is_mime_boundary(line)){
 
 		assert(parent_header != 0);
 
 		/* Check if it is the right boundary */
 		if(!sspm_is_mime_terminating_boundary(line) &&
-		   strncmp((line+2),parent_header->boundary, 
-			   sizeof(parent_header->boundary)) 
+		   strcmp((line+2),parent_header->boundary)
 		   == 0){
 		    /* The +2 in strncmp skips over the leading "--" */
 		    
 		    break;
 		} else {
 		    /* Got the wrong boundary, so read and discard
                        until we get the right boundary.  */
 		    char* boundary;