commit 40e9f174512ac8582e3c90b6a933996bf28a347f
parent ae830af68c1331c3cd97c203157f53d6248a5b13
Author: Christian Grothoff <grothoff@gnunet.org>
Date: Sun, 16 Aug 2026 08:26:56 +0200
better input validation on UNIXPATH_MODE
Diffstat:
1 file changed, 23 insertions(+), 12 deletions(-)
diff --git a/src/mhd/mhd_config.c b/src/mhd/mhd_config.c
@@ -327,19 +327,30 @@ TALER_MHD_listen_bind (const struct GNUNET_CONFIGURATION_Handle *cfg,
GNUNET_free (serve_unixpath);
return GNUNET_SYSERR;
}
- errno = 0;
- unixpath_mode = (mode_t) strtoul (modestring,
- NULL,
- 8);
- if (0 != errno)
{
- GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
- section,
- "UNIXPATH_MODE",
- "must be octal number");
- GNUNET_free (modestring);
- GNUNET_free (serve_unixpath);
- return GNUNET_SYSERR;
+ char *endp;
+ unsigned long mode;
+
+ errno = 0;
+ mode = strtoul (modestring,
+ &endp,
+ 8);
+ /* strtoul() only sets errno on overflow, so we must
+ also check that we actually consumed the entire value */
+ if ( (0 != errno) ||
+ (endp == modestring) ||
+ ('\0' != *endp) ||
+ (mode != (unsigned long) (mode_t) mode) )
+ {
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "UNIXPATH_MODE",
+ "must be octal number");
+ GNUNET_free (modestring);
+ GNUNET_free (serve_unixpath);
+ return GNUNET_SYSERR;
+ }
+ unixpath_mode = (mode_t) mode;
}
GNUNET_free (modestring);