Skip to content
Snippets Groups Projects
Commit 16ca5de5 authored by Martin Stjernholm's avatar Martin Stjernholm
Browse files

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
parent 9f1aabc1
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
|| This file is part of Pike. For copyright information see COPYRIGHT. || This file is part of Pike. For copyright information see COPYRIGHT.
|| Pike is distributed under GPL, LGPL and MPL. See the file COPYING || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
|| for more information. || 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" #include "global.h"
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#define sp Pike_sp #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. /* Checks that args_to_check arguments are OK.
* Returns 1 if everything worked ok, zero otherwise. * Returns 1 if everything worked ok, zero otherwise.
...@@ -351,7 +351,7 @@ PMOD_EXPORT void get_all_args(const char *fname, INT32 args, ...@@ -351,7 +351,7 @@ PMOD_EXPORT void get_all_args(const char *fname, INT32 args,
va_start(ptr, format); va_start(ptr, format);
ret=va_get_args(sp-args, args, format, ptr); ret=va_get_args(sp-args, args, format, ptr);
va_end(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; char *expected_type;
switch(format[ret*2+1]) { switch(format[ret*2+1]) {
case 'd': case 'i': case 'l': expected_type = "int"; break; 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, ...@@ -370,22 +370,22 @@ PMOD_EXPORT void get_all_args(const char *fname, INT32 args,
case '*': expected_type = "mixed"; break; case '*': expected_type = "mixed"; break;
default: expected_type = "Unknown"; break; default: expected_type = "Unknown"; break;
} }
if (ret <= args) { if (ret < args) {
bad_arg_error( bad_arg_error(
fname, sp-args, args, fname, sp-args, args,
ret+1, ret+1,
expected_type, expected_type,
sp+ret-args, sp+ret-args,
"Bad argument %d to %s(). Expected %s\n", "Bad argument %d to %s(). Expected %s.\n",
ret+1, fname, expected_type); ret+1, fname, expected_type);
} else if ((ptrdiff_t)(args*2) < (ptrdiff_t)strlen(format)) { } else {
bad_arg_error( bad_arg_error(
fname, sp-args, args, fname, sp-args, args,
ret+1, ret+1,
expected_type, expected_type,
0, 0,
"Too few arguments to %s(). Expected %ld arguments, got %d.\n" "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); fname, PTRDIFF_T_TO_LONG(strlen(format)/2), args, expected_type);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment