bz20338.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. From 74250a7cdf106d4ca7d9506e6d5dc7c448dc3434 Mon Sep 17 00:00:00 2001
  2. From: David Michael <david.michael@coreos.com>
  3. Date: Thu, 15 Dec 2016 15:22:57 -0800
  4. Subject: [PATCH] gshadow: Sync fgetsgent_r.c with grp/fgetgrent_r.c
  5. [BZ #20338]
  6. * gshadow/fgetsgent_r.c: Include <libio/iolibio.h>.
  7. (flockfile): New macro.
  8. (funlockfile): Likewise.
  9. (__fgetsgent_r): Sync with __fgetgrent_r.
  10. * nss/nss_files/files-sgrp.c: Fix "fgetsgent_r.c" typo.
  11. ---
  12. gshadow/fgetsgent_r.c | 35 ++++++++++++++++++++++++-----------
  13. nss/nss_files/files-sgrp.c | 2 +-
  14. 2 files changed, 25 insertions(+), 12 deletions(-)
  15. diff --git a/gshadow/fgetsgent_r.c b/gshadow/fgetsgent_r.c
  16. index b70f6fa..02cd33a 100644
  17. --- a/gshadow/fgetsgent_r.c
  18. +++ b/gshadow/fgetsgent_r.c
  19. @@ -20,39 +20,44 @@
  20. #include <gshadow.h>
  21. #include <stdio.h>
  22. +#include <libio/iolibio.h>
  23. +#define flockfile(s) _IO_flockfile (s)
  24. +#define funlockfile(s) _IO_funlockfile (s)
  25. +
  26. /* Define a line parsing function using the common code
  27. used in the nss_files module. */
  28. #define STRUCTURE sgrp
  29. #define ENTNAME sgent
  30. -#define EXTERN_PARSER 1
  31. +#define EXTERN_PARSER 1
  32. struct sgent_data {};
  33. #include <nss/nss_files/files-parse.c>
  34. -/* Read one shadow entry from the given stream. */
  35. +/* Read one entry from the given stream. */
  36. int
  37. __fgetsgent_r (FILE *stream, struct sgrp *resbuf, char *buffer, size_t buflen,
  38. struct sgrp **result)
  39. {
  40. char *p;
  41. + int parse_result;
  42. - _IO_flockfile (stream);
  43. + flockfile (stream);
  44. do
  45. {
  46. buffer[buflen - 1] = '\xff';
  47. p = fgets_unlocked (buffer, buflen, stream);
  48. - if (p == NULL && feof_unlocked (stream))
  49. + if (__builtin_expect (p == NULL, 0) && feof_unlocked (stream))
  50. {
  51. - _IO_funlockfile (stream);
  52. + funlockfile (stream);
  53. *result = NULL;
  54. __set_errno (ENOENT);
  55. return errno;
  56. }
  57. - if (p == NULL || buffer[buflen - 1] != '\xff')
  58. + if (__builtin_expect (p == NULL, 0) || buffer[buflen - 1] != '\xff')
  59. {
  60. - _IO_funlockfile (stream);
  61. + funlockfile (stream);
  62. *result = NULL;
  63. __set_errno (ERANGE);
  64. return errno;
  65. @@ -61,13 +66,21 @@ __fgetsgent_r (FILE *stream, struct sgrp *resbuf, char *buffer, size_t buflen,
  66. /* Skip leading blanks. */
  67. while (isspace (*p))
  68. ++p;
  69. - } while (*p == '\0' || *p == '#' /* Ignore empty and comment lines. */
  70. + } while (*p == '\0' || *p == '#' /* Ignore empty and comment lines. */
  71. /* Parse the line. If it is invalid, loop to
  72. get the next line of the file to parse. */
  73. - || ! parse_line (buffer, (void *) resbuf, (void *) buffer, buflen,
  74. - &errno));
  75. + || ! (parse_result = parse_line (p, resbuf,
  76. + (void *) buffer, buflen,
  77. + &errno)));
  78. +
  79. + funlockfile (stream);
  80. - _IO_funlockfile (stream);
  81. + if (__builtin_expect (parse_result, 0) == -1)
  82. + {
  83. + /* The parser ran out of space. */
  84. + *result = NULL;
  85. + return errno;
  86. + }
  87. *result = resbuf;
  88. return 0;
  89. diff --git a/nss/nss_files/files-sgrp.c b/nss/nss_files/files-sgrp.c
  90. index 15dc659..05c3805 100644
  91. --- a/nss/nss_files/files-sgrp.c
  92. +++ b/nss/nss_files/files-sgrp.c
  93. @@ -23,7 +23,7 @@
  94. #define DATABASE "gshadow"
  95. struct sgent_data {};
  96. -/* Our parser function is already defined in sgetspent_r.c, so use that
  97. +/* Our parser function is already defined in sgetsgent_r.c, so use that
  98. to parse lines from the database file. */
  99. #define EXTERN_PARSER
  100. #include "files-parse.c"
  101. --
  102. 2.7.4