Skip to content

Commit 08fce8e

Browse files
orlitzkynikic
authored andcommitted
ext/standard/config.m4: fix crypt() test segfaults in >=glibc-2.17.
Starting with glibc-2.17, the crypt() function will report an EINVAL and return NULL when the format of the "salt" parameter is invalid. The current tests for crypt() pass its result to strcmp(), causing segfaults when the value returned from crypt() is NULL. This commit modifies the test programs to exit with failure when crypt() returns NULL. Reference: https://bugs.gentoo.org/show_bug.cgi?id=518964
1 parent bdd578f commit 08fce8e

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

ext/standard/config.m4

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ AC_CACHE_CHECK(for standard DES crypt, ac_cv_crypt_des,[
7171
7272
main() {
7373
#if HAVE_CRYPT
74-
exit (strcmp((char *)crypt("rasmuslerdorf","rl"),"rl.3StKT.4T8M"));
74+
char* encrypted = crypt("rasmuslerdorf","rl");
75+
exit (!encrypted || strcmp(encrypted,"rl.3StKT.4T8M"));
7576
#else
7677
exit(0);
7778
#endif
@@ -95,7 +96,8 @@ AC_CACHE_CHECK(for extended DES crypt, ac_cv_crypt_ext_des,[
9596
9697
main() {
9798
#if HAVE_CRYPT
98-
exit (strcmp((char *)crypt("rasmuslerdorf","_J9..rasm"),"_J9..rasmBYk8r9AiWNc"));
99+
char* encrypted = crypt("rasmuslerdorf","_J9..rasm");
100+
exit (!encrypted || strcmp(encrypted,"_J9..rasmBYk8r9AiWNc"));
99101
#else
100102
exit(0);
101103
#endif
@@ -128,7 +130,8 @@ main() {
128130
salt[12]='\0';
129131
strcpy(answer,salt);
130132
strcat(answer,"rISCgZzpwk3UhDidwXvin0");
131-
exit (strcmp((char *)crypt("rasmuslerdorf",salt),answer));
133+
char* encrypted = crypt("rasmuslerdorf",salt);
134+
exit (!encrypted || strcmp(encrypted,answer));
132135
#else
133136
exit(0);
134137
#endif
@@ -158,7 +161,8 @@ main() {
158161
strcat(salt,"rasmuslerd............");
159162
strcpy(answer,salt);
160163
strcpy(&answer[29],"nIdrcHdxcUxWomQX9j6kvERCFjTg7Ra");
161-
exit (strcmp((char *)crypt("rasmuslerdorf",salt),answer));
164+
char* encrypted = crypt("rasmuslerdorf",salt);
165+
exit (!encrypted || strcmp(encrypted,answer));
162166
#else
163167
exit(0);
164168
#endif
@@ -187,7 +191,8 @@ main() {
187191
strcpy(salt,"\$6\$rasmuslerdorf\$");
188192
strcpy(answer, salt);
189193
strcat(answer, "EeHCRjm0bljalWuALHSTs1NB9ipEiLEXLhYeXdOpx22gmlmVejnVXFhd84cEKbYxCo.XuUTrW.RLraeEnsvWs/");
190-
exit (strcmp((char *)crypt("rasmuslerdorf",salt),answer));
194+
char* encrypted = crypt("rasmuslerdorf",salt);
195+
exit (!encrypted || strcmp(encrypted,answer));
191196
#else
192197
exit(0);
193198
#endif
@@ -216,7 +221,8 @@ main() {
216221
strcpy(salt,"\$5\$rasmuslerdorf\$");
217222
strcpy(answer, salt);
218223
strcat(answer, "cFAm2puLCujQ9t.0CxiFIIvFi4JyQx5UncCt/xRIX23");
219-
exit (strcmp((char *)crypt("rasmuslerdorf",salt),answer));
224+
char* encrypted = crypt("rasmuslerdorf",salt);
225+
exit (!encrypted || strcmp(encrypted,answer));
220226
221227
#else
222228
exit(0);

0 commit comments

Comments
 (0)