nis-bogus-conditional.patch 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. commit f88759ea9bd3c8d8fef28f123ba9767cb0e421a3
  2. Author: Joseph Myers <joseph@codesourcery.com>
  3. Date: Wed Dec 21 23:44:01 2016 +0000
  4. Fix nss_nisplus build with mainline GCC (bug 20978).
  5. glibc build with current mainline GCC fails because
  6. nis/nss_nisplus/nisplus-alias.c contains code
  7. if (name != NULL)
  8. {
  9. *errnop = EINVAL;
  10. return NSS_STATUS_UNAVAIL;
  11. }
  12. char buf[strlen (name) + 9 + tablename_len];
  13. producing an error about strlen being called on a pointer that is
  14. always NULL (and a subsequent use of that pointer with a %s format in
  15. snprintf).
  16. As Andreas noted, the bogus conditional comes from a 1997 change:
  17. - if (name == NULL || strlen(name) > 8)
  18. - return NSS_STATUS_NOTFOUND;
  19. - else
  20. + if (name != NULL || strlen(name) <= 8)
  21. So the intention is clearly to return an error for NULL name.
  22. This patch duly inverts the sense of the conditional. It fixes the
  23. build with GCC mainline, and passes usual glibc testsuite testing for
  24. x86_64. However, I have not tried any actual substantive nisplus
  25. testing, do not have an environment for such testing, and do not know
  26. whether it is possible that strlen (name) or tablename_len might be
  27. large so that the VLA for buf is actually a security issue. However,
  28. if it is a security issue, there are plenty of other similar instances
  29. in the nisplus code (that haven't been hidden by a bogus comparison
  30. with NULL) - and nis_table.c:__create_ib_request uses strdupa on the
  31. string passed to nis_list, so a local fix in the caller wouldn't
  32. suffice anyway (see bug 20987). (Calls to strdupa and other such
  33. macros that use alloca must be considered equally questionable
  34. regarding stack overflow issues as direct calls to alloca and VLA
  35. declarations.)
  36. [BZ #20978]
  37. * nis/nss_nisplus/nisplus-alias.c (_nss_nisplus_getaliasbyname_r):
  38. Compare name == NULL, not name != NULL.
  39. ---
  40. nis/nss_nisplus/nisplus-alias.c | 2 +-
  41. 1 file changed, 1 insertion(+), 1 deletion(-)
  42. --- a/nis/nss_nisplus/nisplus-alias.c
  43. +++ b/nis/nss_nisplus/nisplus-alias.c
  44. @@ -291,7 +291,7 @@
  45. return status;
  46. }
  47. - if (name != NULL)
  48. + if (name == NULL)
  49. {
  50. *errnop = EINVAL;
  51. return NSS_STATUS_UNAVAIL;