At 6:57 AM -0800 12/2/05, Doug Ambrisko wrote:
Pawel Jakub Dawidek writes:
| [...]
| +> name->sysname[sizeof(name->sysname) - 1] = '\0';
| +> + if ((p = getenv("UNAME_s")))
| +> + strncpy(name->sysname, p, sizeof(name->sysname));
| [...]
| +> name->release[sizeof(name->release) - 1] = '\0';
| +> + if ((p = getenv("UNAME_r")))
| +> + strncpy(name->release, p, sizeof(name->release));
| [...]
| +> + if ((p = getenv("UNAME_v")))
| +> + strncpy(name->version, p, sizeof(name->version));
| [...]
| +> name->machine[sizeof(name->machine) - 1] = '\0';
| +> + if ((p = getenv("UNAME_m")))
| +> + strncpy(name->machine, p, sizeof(name->machine));
|
| As you can see, previous code tried to NULL-terminate buffer
| copied using strncpy(3) properly and you inserted your changes
| after these terminations. Please, NULL-terminate the buffers
| after using strncpy(3).
The prior code had to NULL-terminate by hand since the data could
come from the sysctl not NULL-terminate. I thought the strncpy
would NULL-terminate but you are correct.
strncpy is meant for strings where you don't want null-termination
(such as fixed-length fields in structs). It was not meant for
situations like this. Code like this should use strlcpy() instead.
--
Garance Alistair Drosehn = [EMAIL PROTECTED]
Senior Systems Programmer or [EMAIL PROTECTED]
Rensselaer Polytechnic Institute; Troy, NY; USA
_______________________________________________
cvs-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/cvs-all
To unsubscribe, send any mail to "[EMAIL PROTECTED]"