@@ -127,6 +127,7 @@ bool validate_dns_hosts(union conf_value *val, const char *key, char err[VALIDAT
127127
128128// Validate the dns.cnames array
129129// Each entry needs to be a string in form "<cname>,[<cname>,]<target>[,<TTL>]"
130+ // Newline characters are not allowed in any of the entries
130131bool validate_dns_cnames (union conf_value * val , const char * key , char err [VALIDATOR_ERRBUF_LEN ])
131132{
132133 if (!cJSON_IsArray (val -> json ))
@@ -174,6 +175,18 @@ bool validate_dns_cnames(union conf_value *val, const char *key, char err[VALIDA
174175 snprintf (err , VALIDATOR_ERRBUF_LEN , "%s[%d]: not a valid CNAME definition (too few elements)" , key , i );
175176 return false;
176177 }
178+
179+ // Check if the string contains newline characters
180+ const unsigned int len = strlen (item -> valuestring );
181+ for (unsigned int k = 0 ; k < len ; k ++ )
182+ {
183+ if (item -> valuestring [k ] == '\n' || item -> valuestring [k ] == '\r' )
184+ {
185+ snprintf (err , VALIDATOR_ERRBUF_LEN , "%s[%d]: contains newline characters" ,
186+ key , i );
187+ return false;
188+ }
189+ }
177190 }
178191
179192 return true;
@@ -539,6 +552,19 @@ bool validate_dns_revServers(union conf_value *val, const char *key, char err[VA
539552 free (str );
540553 return false;
541554 }
555+
556+ // Ensure there are no newline characters in the entry
557+ const unsigned int len = strlen (item -> valuestring );
558+ for (unsigned int k = 0 ; k < len ; k ++ )
559+ {
560+ if (item -> valuestring [k ] == '\n' || item -> valuestring [k ] == '\r' )
561+ {
562+ snprintf (err , VALIDATOR_ERRBUF_LEN , "%s[%d]: contains newline characters" ,
563+ key , i );
564+ free (str );
565+ return false;
566+ }
567+ }
542568 }
543569
544570 // Return success
@@ -699,3 +725,69 @@ bool validate_dns_domain_or_ip(union conf_value *val, const char *key, char err[
699725 snprintf (err , VALIDATOR_ERRBUF_LEN , "%s: neither a valid domain nor IP address" , key );
700726 return false;
701727}
728+
729+ bool validate_str_no_newline (union conf_value * val , const char * key , char err [VALIDATOR_ERRBUF_LEN ])
730+ {
731+ if (val -> s == NULL )
732+ {
733+ snprintf (err , VALIDATOR_ERRBUF_LEN , "%s: null string" , key );
734+ return false;
735+ }
736+
737+ // Check if the string contains newline characters
738+ const unsigned int len = strlen (val -> s );
739+ for (unsigned int i = 0 ; i < len ; i ++ )
740+ {
741+ if (val -> s [i ] == '\n' || val -> s [i ] == '\r' )
742+ {
743+ snprintf (err , VALIDATOR_ERRBUF_LEN , "%s: contains newline characters" , key );
744+ return false;
745+ }
746+ }
747+
748+ return true;
749+ }
750+
751+ bool validate_array_no_newline (union conf_value * val , const char * key , char err [VALIDATOR_ERRBUF_LEN ])
752+ {
753+ if (!cJSON_IsArray (val -> json ))
754+ {
755+ snprintf (err , VALIDATOR_ERRBUF_LEN , "%s: not an array" , key );
756+ return false;
757+ }
758+
759+ for (int i = 0 ; i < cJSON_GetArraySize (val -> json ); i ++ )
760+ {
761+ // Get array item
762+ cJSON * item = cJSON_GetArrayItem (val -> json , i );
763+
764+ // Check if it's a string
765+ if (!cJSON_IsString (item ))
766+ {
767+ snprintf (err , VALIDATOR_ERRBUF_LEN , "%s[%d]: not a string" ,
768+ key , i );
769+ return false;
770+ }
771+
772+ if (item -> valuestring == NULL )
773+ {
774+ snprintf (err , VALIDATOR_ERRBUF_LEN , "%s[%d]: null string" ,
775+ key , i );
776+ return false;
777+ }
778+
779+ // Check if the string contains newline characters
780+ const unsigned int len = strlen (item -> valuestring );
781+ for (unsigned int j = 0 ; j < len ; j ++ )
782+ {
783+ if (item -> valuestring [j ] == '\n' || item -> valuestring [j ] == '\r' )
784+ {
785+ snprintf (err , VALIDATOR_ERRBUF_LEN , "%s[%d]: contains newline characters" ,
786+ key , i );
787+ return false;
788+ }
789+ }
790+ }
791+
792+ return true;
793+ }
0 commit comments