Closed
Bug 147940
Opened 23 years ago
Closed 23 years ago
PR_GetSystemInfo(PR_SI_HOSTNAME, ...) is broken
Categories
(NSPR :: NSPR, defect)
Tracking
(Not tracked)
People
(Reporter: rogerd, Assigned: wtc)
Details
PR_GetSystemInfo(PR_SI_HOSTNAME, ...) on Mac is returning a string containing
the IP address converted to a string with the first '.' converted to '\0'. E.g.
if my IP address is 12.34.56.78, it is returning (including terminating nulls):
'12\0.34.56.78\0' Taken as a conventional C string, this is just "12"; which is
not usable as a hostname. Looking at the code this seems to be a combination of
two hacks:
a) on Mac, there is no hostname, so the IP address in string form is being used
instead
b) somone (presumably later) added code inside PR_GetSystemInfo(PR_SI_HOSTNAME,
...) to convert a fully qualified hostname into an unqualified hostname by
replacing the first '.' in the string with a '\0' (the code looks like it's
trying to replace every '.' with a '\0', but it has a bug so it in fact only
gets the first one). I have no idea why anyone would think that it was more
useful to return an unqualified hostname than a fully qualified one (the caller
can always convert a fully qualified one into an unqualified one, but not vice
versa), but applied to an IP address used in place of a hostname this hack is fatal.
This has resulted in the following nasty hack in my code where I undo the damage
done by b):
{
char vBuf[SYS_INFO_BUFFER_LENGTH];
vBuf[SYS_INFO_BUFFER_LENGTH - 1] = '\0';
if (PR_SUCCESS == PR_GetSystemInfo(PR_SI_HOSTNAME,
vBuf,
SYS_INFO_BUFFER_LENGTH))
{
PRHostEnt vHostEnt;
char vBuf2[PR_NETDB_BUF_SIZE];
if (PR_SUCCESS == PR_GetHostByName(vBuf,
vBuf2,
PR_NETDB_BUF_SIZE,
&vHostEnt))
{
...
}
/* Horible hack to fix broken NSPR implementation */
else if (CC_strlen(vBuf) < SYS_INFO_BUFFER_LENGTH - 1)
{
vBuf[CC_strlen(vBuf)] = '.';
if (PR_SUCCESS == PR_GetHostByName(vBuf,
vBuf2,
PR_NETDB_BUF_SIZE,
&vHostEnt))
{
...
}
}
}
}
Could someone please fix this?
Assignee | ||
Comment 1•23 years ago
|
||
*** This bug has been marked as a duplicate of 92516 ***
Status: NEW → RESOLVED
Closed: 23 years ago
Resolution: --- → DUPLICATE
You need to log in
before you can comment on or make changes to this bug.
Description
•