From 16ca5de56b786ce07bed00501be9e9a1102d7549 Mon Sep 17 00:00:00 2001 From: Martin Stjernholm <mast@lysator.liu.se> Date: Sat, 28 Feb 2004 21:21:31 +0100 Subject: [PATCH] Fixed bug in argument checking that could cause segfaults when C some level functions that expect arguments were called without any. Rev: src/module_support.c:1.60 --- src/module_support.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/module_support.c b/src/module_support.c index fada71a95e..377393e346 100644 --- a/src/module_support.c +++ b/src/module_support.c @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: module_support.c,v 1.59 2003/12/17 22:12:13 grubba Exp $ +|| $Id: module_support.c,v 1.60 2004/02/28 20:21:31 mast Exp $ */ #include "global.h" @@ -18,7 +18,7 @@ #define sp Pike_sp -RCSID("$Id: module_support.c,v 1.59 2003/12/17 22:12:13 grubba Exp $"); +RCSID("$Id: module_support.c,v 1.60 2004/02/28 20:21:31 mast Exp $"); /* Checks that args_to_check arguments are OK. * Returns 1 if everything worked ok, zero otherwise. @@ -351,7 +351,7 @@ PMOD_EXPORT void get_all_args(const char *fname, INT32 args, va_start(ptr, format); ret=va_get_args(sp-args, args, format, ptr); va_end(ptr); - if((ptrdiff_t)ret*2 != (ptrdiff_t)strlen(format)) { + if((ptrdiff_t)ret*2 < (ptrdiff_t)strlen(format)) { char *expected_type; switch(format[ret*2+1]) { case 'd': case 'i': case 'l': expected_type = "int"; break; @@ -370,22 +370,22 @@ PMOD_EXPORT void get_all_args(const char *fname, INT32 args, case '*': expected_type = "mixed"; break; default: expected_type = "Unknown"; break; } - if (ret <= args) { + if (ret < args) { bad_arg_error( fname, sp-args, args, ret+1, expected_type, sp+ret-args, - "Bad argument %d to %s(). Expected %s\n", + "Bad argument %d to %s(). Expected %s.\n", ret+1, fname, expected_type); - } else if ((ptrdiff_t)(args*2) < (ptrdiff_t)strlen(format)) { + } else { bad_arg_error( fname, sp-args, args, ret+1, expected_type, 0, "Too few arguments to %s(). Expected %ld arguments, got %d.\n" - "The type of the next argument is expected to be %s\n", + "The type of the next argument is expected to be %s.\n", fname, PTRDIFF_T_TO_LONG(strlen(format)/2), args, expected_type); } } -- GitLab