File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -112,10 +112,18 @@ _mongoc_cyrus_canon_user(sasl_conn_t *conn,
112112 BSON_UNUSED (sasl );
113113 BSON_UNUSED (flags );
114114 BSON_UNUSED (user_realm );
115- BSON_UNUSED (out_max );
115+
116+ // `inlen` is a string length (excluding trailing NULL).
117+ // Cyrus-SASL passes an `out` buffer of size `out_max + 1`. Assume `out_max` is the max to be safe.
118+ if (inlen + 1 >= out_max ) {
119+ MONGOC_ERROR ("SASL username too large" );
120+ return SASL_BUFOVER ;
121+ }
116122
117123 TRACE ("Canonicalizing %s (%" PRIu32 ")\n" , in , inlen );
118- strcpy (out , in );
124+ // Use memmove in case buffers overlap. From Cyrus-SASL: "output buffers and the input buffers may be the same"
125+ memmove (out , in , inlen );
126+ out [inlen ] = '\0' ;
119127 * out_len = inlen ;
120128 return SASL_OK ;
121129}
You can’t perform that action at this time.
0 commit comments