Skip to content

Commit 3f6fe05

Browse files
committed
gssapi: protect GSS_ERROR macro
The GSS_ERROR(x) macro may expand to `(x & value)` on some implementations, instead of `((x) & value)`. This is the case on macOS, which means that if we attempt to wrap an expression in that macro, like `a = b`, then that would expand to `(a = b & value)`. Since `&` has a higher precedence, this is not at all what we want, and will set our result code to an incorrect value. Evaluate the expression then test it with `GSS_ERROR` independently to avoid this.
1 parent 73fe690 commit 3f6fe05

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/transports/auth_negotiate.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ static int negotiate_next_token(
135135

136136
mech = &negotiate_oid_spnego;
137137

138-
if (GSS_ERROR(status_major = gss_init_sec_context(
138+
status_major = gss_init_sec_context(
139139
&status_minor,
140140
GSS_C_NO_CREDENTIAL,
141141
&ctx->gss_context,
@@ -148,7 +148,9 @@ static int negotiate_next_token(
148148
NULL,
149149
&output_token,
150150
NULL,
151-
NULL))) {
151+
NULL);
152+
153+
if (GSS_ERROR(status_major)) {
152154
negotiate_err_set(status_major, status_minor, "negotiate failure");
153155
error = -1;
154156
goto done;
@@ -220,8 +222,9 @@ static int negotiate_init_context(
220222
size_t i;
221223

222224
/* Query supported mechanisms looking for SPNEGO) */
223-
if (GSS_ERROR(status_major =
224-
gss_indicate_mechs(&status_minor, &mechanism_list))) {
225+
status_major = gss_indicate_mechs(&status_minor, &mechanism_list);
226+
227+
if (GSS_ERROR(status_major)) {
225228
negotiate_err_set(status_major, status_minor,
226229
"could not query mechanisms");
227230
return -1;

0 commit comments

Comments
 (0)