shie Tue Apr 20 03:30:41 2004 EDT Modified files: /non-pecl/simple_cvs simple_cvs.c simple_cvs_defs.h simple_cvs_utils.c Log: fixed: sprintf==>snprintf (thanks to derick)
http://cvs.php.net/diff.php/non-pecl/simple_cvs/simple_cvs.c?r1=1.3&r2=1.4&ty=u Index: non-pecl/simple_cvs/simple_cvs.c diff -u non-pecl/simple_cvs/simple_cvs.c:1.3 non-pecl/simple_cvs/simple_cvs.c:1.4 --- non-pecl/simple_cvs/simple_cvs.c:1.3 Mon Apr 19 11:50:18 2004 +++ non-pecl/simple_cvs/simple_cvs.c Tue Apr 20 03:30:40 2004 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: simple_cvs.c,v 1.3 2004/04/19 15:50:18 shie Exp $ */ +/* $Id: simple_cvs.c,v 1.4 2004/04/20 07:30:40 shie Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -62,7 +62,6 @@ PHP_FE(scvs_set_cvsroot, NULL) PHP_FE(scvs_set_module_name, NULL) PHP_FE(scvs_set_working_dir, NULL) - PHP_FE(scvs_set_cvsroot, NULL) {NULL, NULL, NULL} /* Must be the last line in simple_cvs_functions[] */ }; /* }}} */ @@ -417,7 +416,7 @@ Please use the SCVS_STAT_* constants to check for statuses */ PHP_FUNCTION(scvs_status) { - char *un, buf[1024]; + char *un, buf[BUFSIZE]; int un_len; if (ZEND_NUM_ARGS() != 1 || @@ -435,7 +434,7 @@ if(array_init(return_value) != SUCCESS) zend_error(E_ERROR, "unable to create array"); /* chdir into the module dir - thereby performing the MINIMAL sanity check */ - sprintf(buf, "%s/%s", GGET(workingDir), GGET(moduleName)); + snprintf(buf, BUFSIZE, "%s/%s", GGET(workingDir), GGET(moduleName)); if (chdir(buf) != 0) { zend_error(E_WARNING, "No module folder. please checkout first"); return; @@ -514,7 +513,7 @@ } /* chdir into the module dir - thereby performing the MINIMAL sanity check */ - sprintf(buf, "%s/%s", GGET(workingDir), GGET(moduleName)); + snprintf(buf, BUFSIZE, "%s/%s", GGET(workingDir), GGET(moduleName)); if (chdir(buf) != 0) { zend_error(E_WARNING, "No module folder. please checkout first"); return; @@ -543,7 +542,7 @@ } /* chdir into the module dir - thereby performing the MINIMAL sanity check */ - sprintf(buf, "%s/%s", GGET(workingDir), GGET(moduleName)); + snprintf(buf, BUFSIZE, "%s/%s", GGET(workingDir), GGET(moduleName)); if (chdir(buf) != 0) { zend_error(E_WARNING, "No module folder. please checkout first"); return; @@ -573,7 +572,7 @@ } /* chdir into the module dir - thereby performing the MINIMAL sanity check */ - sprintf(buf, "%s/%s", GGET(workingDir), GGET(moduleName)); + snprintf(buf, BUFSIZE, "%s/%s", GGET(workingDir), GGET(moduleName)); if (chdir(buf) != 0) { zend_error(E_WARNING, "No module folder. please checkout first"); return; http://cvs.php.net/diff.php/non-pecl/simple_cvs/simple_cvs_defs.h?r1=1.1&r2=1.2&ty=u Index: non-pecl/simple_cvs/simple_cvs_defs.h diff -u non-pecl/simple_cvs/simple_cvs_defs.h:1.1 non-pecl/simple_cvs/simple_cvs_defs.h:1.2 --- non-pecl/simple_cvs/simple_cvs_defs.h:1.1 Wed Apr 14 12:42:41 2004 +++ non-pecl/simple_cvs/simple_cvs_defs.h Tue Apr 20 03:30:40 2004 @@ -15,6 +15,8 @@ | Author: | +----------------------------------------------------------------------+ */ +#define BUFSIZE 1024 + #define CVS_BINARY "/usr/bin/cvs" #define CMD_CHECKOUT "checkout" http://cvs.php.net/diff.php/non-pecl/simple_cvs/simple_cvs_utils.c?r1=1.1&r2=1.2&ty=u Index: non-pecl/simple_cvs/simple_cvs_utils.c diff -u non-pecl/simple_cvs/simple_cvs_utils.c:1.1 non-pecl/simple_cvs/simple_cvs_utils.c:1.2 --- non-pecl/simple_cvs/simple_cvs_utils.c:1.1 Wed Apr 14 12:42:41 2004 +++ non-pecl/simple_cvs/simple_cvs_utils.c Tue Apr 20 03:30:40 2004 @@ -99,9 +99,8 @@ /* perform a pserver login job, using 'pass' as password */ int cvs_pserver_login_job(char *pass) { -#define MAXBUF 1024 int pid, ret=1, status; - char *args[6], *buf[MAXBUF]; + char *args[6], *buf[BUFSIZE]; struct termios ttyconf; struct winsize win; int n, master, slave; @@ -119,9 +118,9 @@ /* allocate memory as needed, and create the command line */ args[0] = CVS_BINARY; args[1] = emalloc(sizeof(char)*4); /* only for "-zX" */ - sprintf(args[1], "-z%d", GGET(compressionLevel)); + snprintf(args[1], (sizeof(char)*4),"-z%d", GGET(compressionLevel)); args[2] = emalloc(sizeof(char)*1024); /* to be on the safe side */ - sprintf(args[2], "-d:pserver:[EMAIL PROTECTED]:%s", GGET(userName), GGET(host), GGET(cvsRoot)); + snprintf(args[2], (sizeof(char)*1024),"-d:pserver:[EMAIL PROTECTED]:%s", GGET(userName), GGET(host), GGET(cvsRoot)); args[3] = CMD_LOGIN; args[4] = NULL; @@ -154,7 +153,7 @@ /* read output of CVS, look for PASSWD_PHRASE */ while (1) { - n = read(master, buf, MAXBUF); + n = read(master, buf, BUFSIZE); if (n <= 0) continue; /* skip if no data */ if (strstr((char*)buf, PASSWD_PHRASE) != NULL) break; } @@ -162,7 +161,7 @@ write(master, pass, strlen(pass)); write(master, "\n", 1); /* send a newline */ - while ((n=read(master,buf,MAXBUF)) > 0) { + while ((n=read(master,buf,BUFSIZE)) > 0) { if (strstr((char*)buf, "authorization failed") != NULL) { ret = 0; /* so we'll return FALSE */ break; @@ -241,7 +240,7 @@ void cvs_status_job(char *relativePath, zval *retVal) { int pid, ret=0, status; ArgList *args; - char *tmpname, buf[1024]; + char *tmpname, buf[BUFSIZE]; /* get a temporary file */ php_open_temporary_file(NULL, "scvs.", &tmpname); @@ -253,8 +252,8 @@ add_arg(args, "-c"); if (relativePath != NULL) - sprintf(buf, "%s %s %s > %s 2>&1", CVS_BINARY, CMD_STATUS, relativePath, tmpname); - else sprintf(buf, "%s %s > %s 2>&1", CVS_BINARY, CMD_STATUS, tmpname); + snprintf(buf, BUFSIZE, "%s %s %s > %s 2>&1", CVS_BINARY, CMD_STATUS, relativePath, tmpname); + else snprintf(buf, BUFSIZE, "%s %s > %s 2>&1", CVS_BINARY, CMD_STATUS, tmpname); add_arg(args, buf); if ((pid = fork()) < 0) { @@ -282,14 +281,14 @@ static int cvs_generic_job(char *cmd, int expectedRetVal) { int pid, ret=0, status; ArgList *args; - char buf[1024]; + char buf[BUFSIZE]; /* create the arguments to exec */ args = new_arg_list(10); /* initialized to NULL */ add_arg(args, "/bin/sh"); add_arg(args, "-c"); - sprintf(buf, "%s -z%d -d:pserver:[EMAIL PROTECTED]:%s %s 2>&1", CVS_BINARY, GGET(compressionLevel), + snprintf(buf, BUFSIZE, "%s -z%d -d:pserver:[EMAIL PROTECTED]:%s %s 2>&1", CVS_BINARY, GGET(compressionLevel), GGET(userName), GGET(host), GGET(cvsRoot), cmd); add_arg(args, buf); @@ -311,19 +310,19 @@ } int cvs_checkout_job() { - char buf[1024]; - sprintf(buf, "%s %s", CMD_CHECKOUT, GGET(moduleName)); + char buf[BUFSIZE]; + snprintf(buf, BUFSIZE, "%s %s", CMD_CHECKOUT, GGET(moduleName)); return (cvs_generic_job(buf, 0)); } int cvs_commit_job(char *msg, char *args) { - char buf[1024]; + char buf[BUFSIZE]; if (msg == NULL) { /* for now, user must enter a message! */ zend_error(E_WARNING, "Please enter a log message"); return 0; } - if (args != NULL) sprintf(buf, "%s -m'%s' %s", CMD_COMMIT, msg, args); - else sprintf(buf, "%s -m'%s'", CMD_COMMIT, msg); + if (args != NULL) snprintf(buf, BUFSIZE, "%s -m'%s' %s", CMD_COMMIT, msg, args); + else snprintf(buf, BUFSIZE, "%s -m'%s'", CMD_COMMIT, msg); return (cvs_generic_job(buf, 0)); } @@ -401,7 +400,7 @@ void cvs_diff_job(char *path, zval *retVal) { enum State {nostate, removing, adding, changing}; - char line[1025], *tmpname, *beg, *end, *tmpLine; + char line[BUFSIZE], *tmpname, *beg, *end, *tmpLine; FILE *in; int inHunk=0, startingLine=-1, offset=-1, tmpLineNum; enum State state = nostate; @@ -418,7 +417,7 @@ /* get a temporary file */ php_open_temporary_file(NULL, "scvs.", &tmpname); - sprintf(line, "%s -u %s > %s", CMD_DIFF, path, tmpname); + snprintf(line, BUFSIZE, "%s -u %s > %s", CMD_DIFF, path, tmpname); /* execute the command */ if (cvs_generic_job(line, 1 /* why the hell it retuns 1 in diff? */) == 0 || (in=fopen(tmpname, "r")) == NULL) { @@ -568,16 +567,16 @@ } void cvs_update_job(char *path, zval *retVal) { - char line[1025], *tmpname; + char line[BUFSIZE], *tmpname; FILE *in; int status; /* get a temporary file */ php_open_temporary_file(NULL, "scvs.", &tmpname); if (path) { - sprintf(line, "%s %s > %s", CMD_UPDATE, path, tmpname); + snprintf(line, BUFSIZE, "%s %s > %s", CMD_UPDATE, path, tmpname); } else { - sprintf(line, "%s > %s", CMD_UPDATE, tmpname); + snprintf(line, BUFSIZE, "%s > %s", CMD_UPDATE, tmpname); } /* execute the command */ if (cvs_generic_job(line, 0) == 0 ||
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php