mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-04 06:55:06 -05:00
ntp: check name and return status from NSR_AddSourceByName()
Return an error status when the name is not printable or contains a space (don't bother with full hostname validation). If the name is an address, return the same status as NSR_AddSource(). Otherwise, return a "not resolved yet" status.
This commit is contained in:
@@ -505,19 +505,25 @@ NSR_AddSource(NTP_Remote_Address *remote_addr, NTP_Source_Type type, SourceParam
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
void
|
||||
NSR_Status
|
||||
NSR_AddSourceByName(char *name, int port, int pool, NTP_Source_Type type, SourceParameters *params)
|
||||
{
|
||||
struct UnresolvedSource *us;
|
||||
struct SourcePool *sp;
|
||||
NTP_Remote_Address remote_addr;
|
||||
int i;
|
||||
|
||||
/* If the name is an IP address, don't bother with full resolving now
|
||||
or later when trying to replace the source */
|
||||
if (UTI_StringToIP(name, &remote_addr.ip_addr)) {
|
||||
remote_addr.port = port;
|
||||
NSR_AddSource(&remote_addr, type, params);
|
||||
return;
|
||||
return NSR_AddSource(&remote_addr, type, params);
|
||||
}
|
||||
|
||||
/* Make sure the name is at least printable and has no spaces */
|
||||
for (i = 0; name[i] != '\0'; i++) {
|
||||
if (!isgraph(name[i]))
|
||||
return NSR_InvalidName;
|
||||
}
|
||||
|
||||
us = MallocNew(struct UnresolvedSource);
|
||||
@@ -540,6 +546,8 @@ NSR_AddSourceByName(char *name, int port, int pool, NTP_Source_Type type, Source
|
||||
}
|
||||
|
||||
append_unresolved_source(us);
|
||||
|
||||
return NSR_UnresolvedName;
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
Reference in New Issue
Block a user