From 06643071e56c1ae68a9942501581f247542002cf Mon Sep 17 00:00:00 2001 From: Bill Paul Date: Fri, 24 Mar 1995 21:21:37 +0000 Subject: [PATCH] Add more sanity checks. *Lots* of sanity checks. Huge tracts of sanity checks. Make sure all arguments to the yp_*() functions are valid before sending them off to the server. This is somewhat distressing: once again my FreeBSD box brought down my entire network because of NIS bogosities. I *think* the poor argument checking in this module is the cause, but I still haven't been able to reproduce the exact series of events that lead to the ypserv crashes. For now I've resorted to sticking my FreeBSD box in a seprate domain. Hopefully a weekend of heavy testing will uncover the problem. --- lib/libc/yp/yplib.c | 48 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/lib/libc/yp/yplib.c b/lib/libc/yp/yplib.c index f9d881d9659..198365cb7f3 100644 --- a/lib/libc/yp/yplib.c +++ b/lib/libc/yp/yplib.c @@ -380,10 +380,12 @@ int *outvallen; *outval = NULL; *outvallen = 0; - /* Sanity check: no null keys allowed! */ + /* Sanity check */ - if (inkey == NULL || *inkey == '\0') - return YPERR_KEY; + if (inkey == NULL || !strlen(inkey) || inkeylen <= 0 || + inmap == NULL || !strlen(inmap) || + indomain == NULL || !strlen(indomain)) + return YPERR_BADARGS; again: if( _yp_dobind(indomain, &ysd) != 0) @@ -459,6 +461,12 @@ int *outvallen; struct timeval tv; int r; + /* Sanity check */ + + if (indomain == NULL || !strlen(indomain) || + inmap == NULL || !strlen(inmap)) + return YPERR_BADARGS; + *outkey = *outval = NULL; *outkeylen = *outvallen = 0; @@ -512,14 +520,16 @@ int *outvallen; struct timeval tv; int r; + /* Sanity check */ + + if (inkey == NULL || !strlen(inkey) || inkeylen <= 0 || + inmap == NULL || !strlen(inmap) || + indomain == NULL || !strlen(indomain)) + return YPERR_BADARGS; + *outkey = *outval = NULL; *outkeylen = *outvallen = 0; - /* Sanity check: no null keys allowed! */ - - if (inkey == NULL || *inkey == '\0') - return YPERR_KEY; - again: if( _yp_dobind(indomain, &ysd) != 0) return YPERR_DOMAIN; @@ -569,6 +579,12 @@ struct ypall_callback *incallback; u_long status; int clnt_sock; + /* Sanity check */ + + if (indomain == NULL || !strlen(indomain) || + inmap == NULL || !strlen(inmap)) + return YPERR_BADARGS; + if( _yp_dobind(indomain, &ysd) != 0) return YPERR_DOMAIN; @@ -611,6 +627,12 @@ int *outorder; struct timeval tv; int r; + /* Sanity check */ + + if (indomain == NULL || !strlen(indomain) || + inmap == NULL || !strlen(inmap)) + return YPERR_BADARGS; + again: if( _yp_dobind(indomain, &ysd) != 0) return YPERR_DOMAIN; @@ -649,6 +671,11 @@ char **outname; struct timeval tv; int r; + /* Sanity check */ + + if (indomain == NULL || !strlen(indomain) || + inmap == NULL || !strlen(inmap)) + return YPERR_BADARGS; again: if( _yp_dobind(indomain, &ysd) != 0) return YPERR_DOMAIN; @@ -685,6 +712,11 @@ struct ypmaplist **outmaplist; struct timeval tv; int r; + /* Sanity check */ + + if (indomain == NULL || !strlen(indomain)) + return YPERR_BADARGS; + again: if( _yp_dobind(indomain, &ysd) != 0) return YPERR_DOMAIN;