Skip to content

Commit

Permalink
global: Added uchar_empty_ptr and use it instead of &uchar_nul.
Browse files Browse the repository at this point in the history
This makes Coverity happier about not treating a char as an array.
For now this is a pointer to a 0, but could as well become a pointer
that crashes if dereferenced. Shouldn't be NULL anyway because clang's
-fsanitize=nonnull-attribute will complain about them.
  • Loading branch information
sirainen authored and GitLab committed Aug 23, 2016
1 parent 72e25ec commit 5965eaa
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/auth/auth-master-connection.c
Expand Up @@ -419,14 +419,14 @@ master_input_pass(struct auth_master_connection *conn, const char *args)
return FALSE;
auth_request_log_info(auth_request, "passdb", "%s", error);
pass_callback(PASSDB_RESULT_USER_UNKNOWN,
&uchar_nul, 0, auth_request);
uchar_empty_ptr, 0, auth_request);
} else if (conn->userdb_restricted_uid != 0) {
/* no permissions to do this lookup */
auth_request_log_error(auth_request, "passdb",
"Auth client doesn't have permissions to do "
"a PASS lookup: %s", auth_restricted_reason(conn));
pass_callback(PASSDB_RESULT_INTERNAL_FAILURE,
&uchar_nul, 0, auth_request);
uchar_empty_ptr, 0, auth_request);
} else {
auth_request_set_state(auth_request,
AUTH_REQUEST_STATE_MECH_CONTINUE);
Expand Down
2 changes: 1 addition & 1 deletion src/auth/auth-request-handler.c
Expand Up @@ -829,7 +829,7 @@ void auth_request_handler_flush_failures(bool flush_all)
i_assert(auth_request->state == AUTH_REQUEST_STATE_FINISHED);
auth_request_handler_reply(auth_request,
AUTH_CLIENT_RESULT_FAILURE,
&uchar_nul, 0);
uchar_empty_ptr, 0);
auth_request_unref(&auth_request);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/auth/auth-request.c
Expand Up @@ -1116,7 +1116,7 @@ void auth_request_lookup_credentials_policy_continue(struct auth_request *reques
"passdb doesn't support credential lookups");
auth_request_lookup_credentials_callback(
PASSDB_RESULT_SCHEME_NOT_AVAILABLE,
&uchar_nul, 0, request);
uchar_empty_ptr, 0, request);
} else if (passdb->passdb->blocking) {
passdb_blocking_lookup_credentials(request);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/auth/mech.c
Expand Up @@ -50,7 +50,7 @@ void mech_generic_auth_initial(struct auth_request *request,
const unsigned char *data, size_t data_size)
{
if (data == NULL) {
auth_request_handler_reply_continue(request, &uchar_nul, 0);
auth_request_handler_reply_continue(request, uchar_empty_ptr, 0);
} else {
/* initial reply given, even if it was 0 bytes */
request->mech->auth_continue(request, data, data_size);
Expand Down
2 changes: 1 addition & 1 deletion src/auth/userdb-static.c
Expand Up @@ -101,7 +101,7 @@ static void static_lookup(struct auth_request *auth_request,
} else {
static_credentials_callback(
PASSDB_RESULT_SCHEME_NOT_AVAILABLE,
&uchar_nul, 0, auth_request);
uchar_empty_ptr, 0, auth_request);
}
} else {
static_lookup_real(auth_request, callback);
Expand Down
2 changes: 1 addition & 1 deletion src/lib-imap/imap-parser.c
Expand Up @@ -516,7 +516,7 @@ static bool imap_parser_read_literal_data(struct imap_parser *parser,
} else {
/* we want to save only literal size, not the literal itself. */
parser->literal_size_return = TRUE;
imap_parser_save_arg(parser, &uchar_nul, 0);
imap_parser_save_arg(parser, uchar_empty_ptr, 0);
return FALSE;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib-sasl/mech-login.c
Expand Up @@ -51,7 +51,7 @@ mech_login_output(struct dsasl_client *_client,

switch (client->state) {
case STATE_INIT:
*output_r = &uchar_nul;
*output_r = uchar_empty_ptr;
*output_len_r = 0;
return 0;
case STATE_USER:
Expand Down
4 changes: 2 additions & 2 deletions src/lib/istream.c
Expand Up @@ -503,7 +503,7 @@ i_stream_get_data(struct istream *stream, size_t *size_r)

if (_stream->skip >= _stream->pos) {
*size_r = 0;
return &uchar_nul;
return uchar_empty_ptr;
}

if (i_stream_is_buffer_invalid(_stream)) {
Expand All @@ -528,7 +528,7 @@ i_stream_get_data(struct istream *stream, size_t *size_r)
_stream->skip = _stream->pos = 0;
stream->eof = FALSE;
}
return &uchar_nul;
return uchar_empty_ptr;
}

*size_r = _stream->pos - _stream->skip;
Expand Down
1 change: 1 addition & 0 deletions src/lib/strfuncs.c
Expand Up @@ -19,6 +19,7 @@ enum _str_trim_sides {
};

const unsigned char uchar_nul = '\0';
const unsigned char *uchar_empty_ptr = { 0 };

int i_snprintf(char *dest, size_t max_chars, const char *format, ...)
{
Expand Down
1 change: 1 addition & 0 deletions src/lib/strfuncs.h
Expand Up @@ -4,6 +4,7 @@
#define MAX_INT_STRLEN ((sizeof(uintmax_t) * CHAR_BIT + 2) / 3 + 1)

extern const unsigned char uchar_nul; /* (const unsigned char *)"" */
extern const unsigned char *uchar_empty_ptr; /* non-NULL pointer that shouldn't be dereferenced. */

/* Returns -1 if dest wasn't large enough, 0 if not. */
int i_snprintf(char *dest, size_t max_chars, const char *format, ...)
Expand Down

0 comments on commit 5965eaa

Please sign in to comment.