honor return values of read and sscanf

This commit is contained in:
Frank Morgner 2017-10-31 09:29:05 +01:00
parent 17132b04c7
commit a332f72b38

View File

@ -26,6 +26,7 @@
#if defined(ENABLE_NOTIFY) && (defined(__APPLE__) || (defined(GDBUS) && !defined(_WIN32))) #if defined(ENABLE_NOTIFY) && (defined(__APPLE__) || (defined(GDBUS) && !defined(_WIN32)))
#include "libopensc/internal.h"
#include "libopensc/log.h" #include "libopensc/log.h"
#include <signal.h> #include <signal.h>
#include <stdlib.h> #include <stdlib.h>
@ -452,12 +453,16 @@ static void notify_gio(struct sc_context *ctx,
} }
if (pass_to_pipe) { if (pass_to_pipe) {
ssize_t r;
/* close the write end of the pipe */ /* close the write end of the pipe */
close(pipefd[1]); close(pipefd[1]);
memset(message_id_str, '\0', sizeof message_id_str); memset(message_id_str, '\0', sizeof message_id_str);
if (0 < read(pipefd[0], message_id_str, sizeof(message_id_str))) { r = read(pipefd[0], message_id_str, sizeof(message_id_str));
message_id_str[(sizeof message_id_str) - 1] = '\0'; if (0 < r) {
sscanf(message_id_str, "(uint32 %"SCNu32",)", &message_id); message_id_str[MIN((sizeof message_id_str) - 1, (size_t) r)] = '\0';
if (0 >= sscanf(message_id_str, "(uint32 %"SCNu32",)", &message_id)) {
message_id = 0;
}
} }
/* close the read end of the pipe */ /* close the read end of the pipe */
close(pipefd[0]); close(pipefd[0]);