Skip to content

Commit

Permalink
Merge pull request #1701 from /issues/1700-coverity-npe
Browse files Browse the repository at this point in the history
Fix #1700: Coverity: Dereference null return value
  • Loading branch information
banterCZ authored Oct 2, 2024
2 parents 1c548e9 + 0e48dba commit 7f265f2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Objects;

/**
* Converter for callback request authentication.
Expand All @@ -48,17 +49,13 @@ public CallbackAuthenticationConverter(ObjectMapper objectMapper) {
}

@Override
public String convertToDatabaseColumn(CallbackUrlAuthentication authentication) {
public String convertToDatabaseColumn(final CallbackUrlAuthentication authentication) {
try {
if (authentication == null) {
authentication = new CallbackUrlAuthentication();
}
return objectMapper.writeValueAsString(authentication);
return objectMapper.writeValueAsString(Objects.requireNonNullElse(authentication, new CallbackUrlAuthentication()));
} catch (JsonProcessingException ex) {
logger.error("Unable to serialize JSON payload", ex);
return null;
}

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ public byte[] decrypt(final byte[] data, final EncryptionMode encryptionMode, fi
* @throws GenericServiceException Thrown when encryption fails.
*/
public EncryptableString encrypt(final String data, final Supplier<List<String>> encryptionKeyProvider) throws GenericServiceException {
if (data == null) {
throw new GenericServiceException(ServiceError.ENCRYPTION_FAILED, "Data must not be null");
}

final byte[] dataBytes = data.getBytes(StandardCharsets.UTF_8);
final EncryptableData result = encrypt(dataBytes, encryptionKeyProvider);
return new EncryptableString(result.encryptionMode(), convert(result));
Expand All @@ -166,6 +170,10 @@ public EncryptableString encrypt(final String data, final Supplier<List<String>>
* @throws GenericServiceException Thrown when encryption fails.
*/
public EncryptableData encrypt(final byte[] data, final Supplier<List<String>> encryptionKeyProvider) throws GenericServiceException {
if (data == null) {
throw new GenericServiceException(ServiceError.ENCRYPTION_FAILED, "Data must not be null");
}

final String masterDbEncryptionKeyBase64 = powerAuthServiceConfiguration.getMasterDbEncryptionKey();

// In case master DB encryption key does not exist, do not encrypt the value
Expand Down

0 comments on commit 7f265f2

Please sign in to comment.