Skip to content

Commit

Permalink
Define and call an alternative vdprintf()
Browse files Browse the repository at this point in the history
Only if the genuine vdprintf() does not exist.
  • Loading branch information
DimitriPapadopoulos committed Jun 5, 2024
1 parent b59f05e commit c6cc83e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
6 changes: 5 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ write \
], [], AC_MSG_ERROR([Required function not found]))

# Checks for optional functions.
AC_CHECK_FUNCS([pthread_mutexattr_setrobust])
AC_CHECK_FUNCS([ \
pthread_mutexattr_setrobust \
vdprintf \
])

# Use PKG_CHECK_MODULES compiler/linker flags
save_openssl_CPPFLAGS="${CPPFLAGS}"
save_openssl_LIBS="${LIBS}"
Expand Down
31 changes: 17 additions & 14 deletions src/userinput.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,26 +167,29 @@ static int pinentry_read(int from, char **retstr)
return -1;
}

#ifndef HAVE_VDPRINTF
static int vdprintf(int fd, const char *format, va_list ap)
{
char buffer[2049];
int size = vsnprintf(buffer, sizeof(buffer), format, ap);

if (size < 0)
return size;

if (size >= sizeof(buffer)) // silently discard beyond the buffer size
size = sizeof(buffer) - 1;

return (int) write(fd, buffer, size);
}
#endif

static int pinentry_exchange(int to, int from, char **retstr,
const char *format, ...)
{
va_list ap;
char buffer[2048];
int size;

va_start(ap, format);

size = vsnprintf(buffer, sizeof(buffer), format, ap);
if (size < 0) {
if (retstr)
*retstr = strdup(strerror(errno));
va_end(ap);
return -1;
}
if (size > sizeof(buffer))
size = sizeof(buffer);

if (write(to, buffer, size) < 0) {
if (vdprintf(to, format, ap) == 0) {
if (retstr)
*retstr = strdup(strerror(errno));
va_end(ap);
Expand Down

0 comments on commit c6cc83e

Please sign in to comment.