From f274097fdaf58231e385bec338e155a54d240ebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Sun, 15 Jan 2017 02:05:24 +0100 Subject: [PATCH] Version 16.114.1 --- swad_changelog.h | 3 +- swad_chat.c | 140 +++++++++-------------------------------------- swad_string.c | 9 +++ swad_string.h | 2 + swad_user.c | 10 ++-- 5 files changed, 44 insertions(+), 120 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index 5dbdf504..f0af810c 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -189,13 +189,14 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 16.114 (2017-01-14)" +#define Log_PLATFORM_VERSION "SWAD 16.114.1 (2017-01-15)" #define CSS_FILE "swad16.111.5.css" #define JS_FILE "swad16.114.js" // Number of lines (includes comments but not blank lines) has been got with the following command: // nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*?.h sql/swad*.sql | tail -1 /* + Version 16.114.1: Jan 15, 2017 Fixed bug in string concatenation. (211411 lines) Version 16.114: Jan 14, 2017 Fixed bug in dates, reported by José Luis Bernier Villamor. Javascript code refactoring related to dates. (211490 lines) Version 16.113: Jan 13, 2017 Some strcpy changed to strncpy. (211497 lines) diff --git a/swad_chat.c b/swad_chat.c index 4c51244c..b2b86464 100644 --- a/swad_chat.c +++ b/swad_chat.c @@ -420,11 +420,11 @@ void Cht_OpenChatWindow (void) UsrName[Usr_MAX_BYTES_NAME] = '\0'; if (Gbl.Usrs.Me.UsrDat.Surname2[0]) { - strncat (UsrName," ",1); - strncat (UsrName,Gbl.Usrs.Me.UsrDat.Surname2,Usr_MAX_BYTES_NAME); + Str_Concat (UsrName," ",Usr_MAX_BYTES_NAME); + Str_Concat (UsrName,Gbl.Usrs.Me.UsrDat.Surname2,Usr_MAX_BYTES_NAME); } - strncat (UsrName,", ",2); - strncat (UsrName,Gbl.Usrs.Me.UsrDat.FirstName,Usr_MAX_BYTES_NAME); + Str_Concat (UsrName,", ",Usr_MAX_BYTES_NAME); + Str_Concat (UsrName,Gbl.Usrs.Me.UsrDat.FirstName,Usr_MAX_BYTES_NAME); /***** Build the lists of available rooms *****/ sprintf (ListRoomCodes,"#%s",RoomCode); @@ -437,76 +437,40 @@ void Cht_OpenChatWindow (void) if (strcmp (RoomCode,"GBL_USR")) { - strncat (ListRoomCodes,"|#GBL_USR", - MAX (0, - sizeof (ListRoomCodes) - 1 - - strlen (ListRoomCodes) - - strlen ("|#GBL_USR"))); + Str_Concat (ListRoomCodes,"|#GBL_USR",sizeof (ListRoomCodes) - 1); sprintf (RoomShortName,"|%s",Txt_SEX_PLURAL_Abc[Usr_SEX_ALL]); - strncat (ListRoomShortNames,RoomShortName, - MAX (0, - sizeof (ListRoomShortNames) - 1 - - strlen (ListRoomShortNames) - - strlen (RoomShortName))); + Str_Concat (ListRoomShortNames,RoomShortName,sizeof (ListRoomShortNames) - 1); sprintf (RoomFullName,"|%s (%s)", Txt_General,Txt_SEX_PLURAL_abc[Usr_SEX_ALL]); - strncat (ListRoomFullNames,RoomFullName, - MAX (0, - sizeof (ListRoomFullNames) - 1 - - strlen (ListRoomFullNames) - - strlen (RoomFullName))); + Str_Concat (ListRoomFullNames,RoomFullName,sizeof (ListRoomFullNames) - 1); } if (Gbl.Usrs.Me.LoggedRole == Rol_STUDENT) if (strcmp (RoomCode,"GBL_STD")) { - strncat (ListRoomCodes,"|#GBL_STD", - MAX (0, - sizeof (ListRoomCodes) - 1 - - strlen (ListRoomCodes) - - strlen ("|#GBL_STD"))); + Str_Concat (ListRoomCodes,"|#GBL_STD",sizeof (ListRoomCodes) - 1); sprintf (RoomShortName,"|%s",Txt_Students_ABBREVIATION); - strncat (ListRoomShortNames,RoomShortName, - MAX (0, - sizeof (ListRoomShortNames) - 1 - - strlen (ListRoomShortNames) - - strlen (RoomShortName))); + Str_Concat (ListRoomShortNames,RoomShortName,sizeof (ListRoomShortNames) - 1); sprintf (RoomFullName,"|%s (%s)",Txt_General, Txt_ROLES_PLURAL_abc[Rol_STUDENT][Usr_SEX_ALL]); - strncat (ListRoomFullNames,RoomFullName, - MAX (0, - sizeof (ListRoomFullNames) - 1 - - strlen (ListRoomFullNames) - - strlen (RoomFullName))); + Str_Concat (ListRoomFullNames,RoomFullName,sizeof (ListRoomFullNames) - 1); } if (Gbl.Usrs.Me.LoggedRole == Rol_TEACHER) if (strcmp (RoomCode,"GBL_TCH")) { - strncat (ListRoomCodes,"|#GBL_TCH", - MAX (0, - sizeof (ListRoomCodes) - 1 - - strlen (ListRoomCodes) - - strlen ("|#GBL_TCH"))); + Str_Concat (ListRoomCodes,"|#GBL_TCH",sizeof (ListRoomCodes) - 1); sprintf (RoomShortName,"|%s",Txt_Teachers_ABBREVIATION); - strncat (ListRoomShortNames,RoomShortName, - MAX (0, - sizeof (ListRoomShortNames) - 1 - - strlen (ListRoomShortNames) - - strlen (RoomShortName))); + Str_Concat (ListRoomShortNames,RoomShortName,sizeof (ListRoomShortNames) - 1); sprintf (RoomFullName,"|%s (%s)", Txt_General,Txt_ROLES_PLURAL_abc[Rol_TEACHER][Usr_SEX_ALL]); - strncat (ListRoomFullNames,RoomFullName, - MAX (0, - sizeof (ListRoomFullNames) - 1 - - strlen (ListRoomFullNames) - - strlen (RoomFullName))); + Str_Concat (ListRoomFullNames,RoomFullName,sizeof (ListRoomFullNames) - 1); } for (NumMyDeg = 0; @@ -516,17 +480,9 @@ void Cht_OpenChatWindow (void) sprintf (ThisRoomCode,"DEG_%ld",Gbl.Usrs.Me.MyDegs.Degs[NumMyDeg].DegCod); if (strcmp (RoomCode,ThisRoomCode)) { - strncat (ListRoomCodes,"|#", - MAX (0, - sizeof (ListRoomCodes) - 1 - - strlen (ListRoomCodes) - - strlen ("|#"))); + Str_Concat (ListRoomCodes,"|#",sizeof (ListRoomCodes) - 1); - strncat (ListRoomCodes,ThisRoomCode, - MAX (0, - sizeof (ListRoomCodes) - 1 - - strlen (ListRoomCodes) - - strlen (ThisRoomCode))); + Str_Concat (ListRoomCodes,ThisRoomCode,sizeof (ListRoomCodes) - 1); /* Get data of this degree */ Deg.DegCod = Gbl.Usrs.Me.MyDegs.Degs[NumMyDeg].DegCod; @@ -534,31 +490,15 @@ void Cht_OpenChatWindow (void) sprintf (ThisRoomShortName,"%s",Deg.ShrtName); - strncat (ListRoomShortNames,"|", - MAX (0, - sizeof (ListRoomShortNames) - 1 - - strlen (ListRoomShortNames) - - strlen ("|"))); + Str_Concat (ListRoomShortNames,"|",sizeof (ListRoomShortNames) - 1); - strncat (ListRoomShortNames,ThisRoomShortName, - MAX (0, - sizeof (ListRoomShortNames) - 1 - - strlen (ListRoomShortNames) - - strlen (ThisRoomShortName))); + Str_Concat (ListRoomShortNames,ThisRoomShortName,sizeof (ListRoomShortNames) - 1); sprintf (ThisRoomFullName,"%s %s",Txt_Degree,Deg.ShrtName); - strncat (ListRoomFullNames,"|", - MAX (0, - sizeof (ListRoomFullNames) - 1 - - strlen (ListRoomFullNames) - - strlen ("|"))); + Str_Concat (ListRoomFullNames,"|",sizeof (ListRoomFullNames) - 1); - strncat (ListRoomFullNames,ThisRoomFullName, - MAX (0, - sizeof (ListRoomFullNames) - 1 - - strlen (ListRoomFullNames) - - strlen (ThisRoomFullName))); + Str_Concat (ListRoomFullNames,ThisRoomFullName,sizeof (ListRoomFullNames) - 1); } } @@ -569,53 +509,25 @@ void Cht_OpenChatWindow (void) sprintf (ThisRoomCode,"CRS_%ld",Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].CrsCod); if (strcmp (RoomCode,ThisRoomCode)) { - strncat (ListRoomCodes,"|#", - MAX (0, - sizeof (ListRoomCodes) - 1 - - strlen (ListRoomCodes) - - strlen ("|#"))); + Str_Concat (ListRoomCodes,"|#",sizeof (ListRoomCodes) - 1); - strncat (ListRoomCodes,ThisRoomCode, - MAX (0, - sizeof (ListRoomCodes) - 1 - - strlen (ListRoomCodes) - - strlen (ThisRoomCode))); + Str_Concat (ListRoomCodes,ThisRoomCode,sizeof (ListRoomCodes) - 1); /* Get data of this course */ Crs.CrsCod = Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].CrsCod; Crs_GetDataOfCourseByCod (&Crs); sprintf (ThisRoomShortName,"%s",Crs.ShrtName); - strncat (ListRoomShortNames,"|", - MAX (0, - sizeof (ListRoomShortNames) - 1 - - strlen (ListRoomShortNames) - - strlen ("|"))); + Str_Concat (ListRoomShortNames,"|",sizeof (ListRoomShortNames) - 1); - strncat (ListRoomShortNames,ThisRoomShortName, - MAX (0, - sizeof (ListRoomShortNames) - 1 - - strlen (ListRoomShortNames) - - strlen (ThisRoomShortName))); + Str_Concat (ListRoomShortNames,ThisRoomShortName,sizeof (ListRoomShortNames) - 1); - strncat (ListRoomShortNames,"|", - MAX (0, - sizeof (ListRoomShortNames) - 1 - - strlen (ListRoomShortNames) - - strlen (ThisRoomShortName))); + Str_Concat (ListRoomShortNames,"|",sizeof (ListRoomShortNames) - 1); sprintf (ThisRoomFullName,"%s %s",Txt_Course,Crs.ShrtName); - strncat (ListRoomFullNames,"|", - MAX (0, - sizeof (ListRoomFullNames) - 1 - - strlen (ListRoomFullNames) - - strlen ("|"))); + Str_Concat (ListRoomFullNames,"|",sizeof (ListRoomFullNames) - 1); - strncat (ListRoomFullNames,"|", - MAX (0, - sizeof (ListRoomFullNames) - 1 - - strlen (ListRoomFullNames) - - strlen (ThisRoomFullName))); + Str_Concat (ListRoomFullNames,"|",sizeof (ListRoomFullNames) - 1); } } diff --git a/swad_string.c b/swad_string.c index 8efaf332..5dee0759 100644 --- a/swad_string.c +++ b/swad_string.c @@ -2812,3 +2812,12 @@ void Str_GetMailBox (const char *Email,char *MailBox,size_t MaxLength) } } } + +/*****************************************************************************/ +/************************** Safe string concatenation ************************/ +/*****************************************************************************/ + +void Str_Concat (char *Src,const char *Dst,size_t MaxLength) + { + strncat (Src,Dst,MaxLength - strlen (Src)); + } diff --git a/swad_string.h b/swad_string.h index 5394ee6b..6cc031fc 100644 --- a/swad_string.h +++ b/swad_string.h @@ -119,4 +119,6 @@ void Str_ConvertToValidFileName (char *Str); void Str_CreateRandomAlphanumStr (char *Str,size_t Length); void Str_GetMailBox (const char *Email,char *MailBox,size_t MaxLength); +void Str_Concat (char *Src,const char *Dst,size_t MaxLength); + #endif diff --git a/swad_user.c b/swad_user.c index 1c454edd..38858f76 100644 --- a/swad_user.c +++ b/swad_user.c @@ -4968,8 +4968,8 @@ Lay_ShowErrorAndExit (Gbl.Message); Gbl.Usrs.Select.All[Length ] = Par_SEPARATOR_PARAM_MULTIPLE; Gbl.Usrs.Select.All[Length+1] = '\0'; } - strncat (Gbl.Usrs.Select.All,Gbl.Usrs.Select.Tch, - Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS - strlen (Gbl.Usrs.Select.All)); + Str_Concat (Gbl.Usrs.Select.All,Gbl.Usrs.Select.Tch, + Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS); } /***** Add students to the list with all selected users *****/ @@ -4981,8 +4981,8 @@ Lay_ShowErrorAndExit (Gbl.Message); Gbl.Usrs.Select.All[Length ] = Par_SEPARATOR_PARAM_MULTIPLE; Gbl.Usrs.Select.All[Length+1] = '\0'; } - strncat (Gbl.Usrs.Select.All,Gbl.Usrs.Select.Std, - Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS - strlen (Gbl.Usrs.Select.All)); + Str_Concat (Gbl.Usrs.Select.All,Gbl.Usrs.Select.Std, + Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS); } } @@ -5217,7 +5217,7 @@ void Usr_AllocateListSelectedUsrCodAll (void) { if (!Gbl.Usrs.Select.All) { - if ((Gbl.Usrs.Select.All = (char *) malloc (Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS+1)) == NULL) + if ((Gbl.Usrs.Select.All = (char *) malloc (Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS + 1)) == NULL) Lay_ShowErrorAndExit ("Not enough memory to store list of users."); Gbl.Usrs.Select.All[0] = '\0'; }