From 0759475be806a1b0dd52c8d0404e84d571b6d6e4 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Mon, 8 Mar 2021 15:19:01 +0100 Subject: [PATCH] fix --- sink/sink20169.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sink/sink20169.c b/sink/sink20169.c index 8fc4720..f673e53 100644 --- a/sink/sink20169.c +++ b/sink/sink20169.c @@ -110,7 +110,7 @@ void deinitConfig(t_configHandle *configHandle) { t_device *findDevice(t_configHandle *configHandle, char *deviceId) { for (uint16_t i = 0; i < configHandle->numOfDevices; i++) { - if (! strcmp(configHandle->devices[i].deviceId, deviceId)) { + if (! strncmp(configHandle->devices[i].deviceId, deviceId, strlen(configHandle->devices[i].deviceId))) { return &(configHandle->devices[i]); } } @@ -165,11 +165,15 @@ int receiveAndVerifyMinuteBuffer(t_receiverHandle *handle, t_minuteBuffer *buf) ((cliaddr.sin_addr.s_addr >> 24) & 0x0ff)); if (n != sizeof(buf->b)) { - logmsg(LOG_INFO, "Illegal packet size: %d", n); + logmsg(LOG_ERR, "Illegal packet size: %d", n); return -1; } t_device *device = findDevice(handle->configHandle, buf->s.deviceId); + if (device == NULL) { + logmsg(LOG_ERR, "unknown device"); + return -7; + } const char *sharedSecret = device->sharedSecret; uint8_t receivedHash[SHA256_BLOCK_SIZE]; @@ -183,7 +187,7 @@ int receiveAndVerifyMinuteBuffer(t_receiverHandle *handle, t_minuteBuffer *buf) sha256_final(&ctx, calculatedHash); if (memcmp(receivedHash, calculatedHash, SHA256_BLOCK_SIZE) != 0) { - logmsg(LOG_INFO, "Invalid hash in msg for device %s", buf->s.deviceId); + logmsg(LOG_ERR, "Invalid hash in msg for device %s", buf->s.deviceId); return -5; }