CVS update: php3/functions
| From: | steinm | Date: | Fri, 16 Apr 1999 12:09:52 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-5097@lists.php.net to get a copy of this message | ||
Date: Friday April 16, 1999 @ 8:09
Author: steinm
Update of /repository/php3/functions
In directory asf:/u/temp/cvs-serv5808/functions
Modified Files:
hg_comm.c hw.c pdf.c
Log Message:
- some code cleanups
- replaced sprintf by snprintf to prevent buffer overflow
- updated documentation
Index: php3/functions/hg_comm.c
diff -c php3/functions/hg_comm.c:1.16 php3/functions/hg_comm.c:1.17
*** php3/functions/hg_comm.c:1.16 Thu Apr 8 11:08:13 1999
--- php3/functions/hg_comm.c Fri Apr 16 08:09:49 1999
***************
*** 23,29 ****
+----------------------------------------------------------------------+
*/
! /* $Id: hg_comm.c,v 1.16 1999/04/08 15:08:13 steinm Exp $ */
/* #define HW_DEBUG */
--- 23,29 ----
+----------------------------------------------------------------------+
*/
! /* $Id: hg_comm.c,v 1.17 1999/04/16 12:09:49 steinm Exp $ */
/* #define HW_DEBUG */
***************
*** 518,524 ****
if(NULL != cur_ptr->destdocname)
sprintf(bgstr, " background='%s/%s'", scriptname == NULL ? ""
: scriptname, cur_ptr->destdocname);
else
! sprintf(bgstr, "");
break;
case HW_INTAG_LINK:
if(cur_ptr->fragment)
--- 518,524 ----
if(NULL != cur_ptr->destdocname)
sprintf(bgstr, " background='%s/%s'", scriptname == NULL ? ""
: scriptname, cur_ptr->destdocname);
else
! bgstr[0] = '\0';
break;
case HW_INTAG_LINK:
if(cur_ptr->fragment)
***************
*** 3107,3113 ****
if(anchorrec[i]) efree(anchorrec[i]);
anchorrec[i] = NULL;
} else {
! int j, k, *retthisIDs, *retdestIDs, equaltill, mincount, countthis, countdest, destdocid;
char destdocname[200];
char anchorstr[300];
char temp[200];
--- 3107,3113 ----
if(anchorrec[i]) efree(anchorrec[i]);
anchorrec[i] = NULL;
} else {
! int j, *retthisIDs, *retdestIDs, equaltill, mincount, countthis, countdest, destdocid;
char destdocname[200];
char anchorstr[300];
char temp[200];
***************
*** 3145,3151 ****
strcat(anchorstr, "../");
strcat(anchorstr, "./");
for(j=equaltill; j<countdest; j++) {
! char *temprec, tempname[100], objectidstr[100];
send_getobject(sockfd, retdestIDs[j], &temprec);
if(NULL != (str = strstr(temprec, "Name="))) {
str += 5;
--- 3145,3151 ----
strcat(anchorstr, "../");
strcat(anchorstr, "./");
for(j=equaltill; j<countdest; j++) {
! char *temprec, tempname[100];
send_getobject(sockfd, retdestIDs[j], &temprec);
if(NULL != (str = strstr(temprec, "Name="))) {
str += 5;
***************
*** 3246,3252 ****
* document with id destID. *
********************************************************************/
int getrellink(int sockfd, int rootID, int thisID, int destID, char **reldeststr) {
! int i, j, k, *retthisIDs, *retdestIDs, equaltill, count, mincount, countthis, countdest,
destdocid;
char anchorstr[300];
char temp[200];
char *strptr;
--- 3246,3252 ----
* document with id destID. *
********************************************************************/
int getrellink(int sockfd, int rootID, int thisID, int destID, char **reldeststr) {
! int i, j, k, *retthisIDs, *retdestIDs, equaltill, count, mincount, countthis, countdest;
char anchorstr[300];
char temp[200];
char *strptr;
***************
*** 3313,3319 ****
strcat(anchorstr, "../");
strcat(anchorstr, "./");
for(j=equaltill; j<countdest; j++) {
! char *temprec, *str, tempname[100], objectidstr[100];
if(0 == send_getobject(sockfd, retdestIDs[j], &temprec)) {
if(NULL != (str = strstr(temprec, "Name="))) {
str += 5;
--- 3313,3319 ----
strcat(anchorstr, "../");
strcat(anchorstr, "./");
for(j=equaltill; j<countdest; j++) {
! char *temprec, *str, tempname[100];
if(0 == send_getobject(sockfd, retdestIDs[j], &temprec)) {
if(NULL != (str = strstr(temprec, "Name="))) {
str += 5;
Index: php3/functions/hw.c
diff -c php3/functions/hw.c:1.28 php3/functions/hw.c:1.29
*** php3/functions/hw.c:1.28 Tue Apr 13 10:32:31 1999
--- php3/functions/hw.c Fri Apr 16 08:09:50 1999
***************
*** 23,29 ****
+----------------------------------------------------------------------+
*/
! /* $Id: hw.c,v 1.28 1999/04/13 14:32:31 steinm Exp $ */
#if COMPILE_DL
#include "dl/phpdl.h"
#endif
--- 23,29 ----
+----------------------------------------------------------------------+
*/
! /* $Id: hw.c,v 1.29 1999/04/16 12:09:50 steinm Exp $ */
#if COMPILE_DL
#include "dl/phpdl.h"
#endif
***************
*** 340,349 ****
return(0);
}
static char * make_objrec_from_array(HashTable *lht) {
int i, count, keytype;
ulong length;
! char *key, str[1024], *objrec = NULL;
pval *keydata;
if(NULL == lht)
--- 340,350 ----
return(0);
}
+ #define BUFFERLEN 1024
static char * make_objrec_from_array(HashTable *lht) {
int i, count, keytype;
ulong length;
! char *key, str[BUFFERLEN], *objrec = NULL;
pval *keydata;
if(NULL == lht)
***************
*** 361,370 ****
_php3_hash_get_current_data(lht, (void **) &keydata);
switch(keydata->type) {
case IS_STRING:
! sprintf(str, "%s=%s\n", key, keydata->value.str.val);
break;
case IS_LONG:
! sprintf(str, "%s=0x%lX\n", key, keydata->value.lval);
break;
case IS_ARRAY: {
int i, len, keylen, count;
--- 362,371 ----
_php3_hash_get_current_data(lht, (void **) &keydata);
switch(keydata->type) {
case IS_STRING:
! snprintf(str, BUFFERLEN, "%s=%s\n", key, keydata->value.str.val);
break;
case IS_LONG:
! snprintf(str, BUFFERLEN, "%s=0x%lX\n", key, keydata->value.lval);
break;
case IS_ARRAY: {
int i, len, keylen, count;
***************
*** 407,412 ****
--- 408,414 ----
}
return objrec;
}
+ #undef BUFFERLEN
static int * make_ints_from_array(HashTable *lht) {
int i, count;
***************
*** 455,460 ****
--- 457,463 ----
return SUCCESS;
}
+ #define BUFFERLEN 30
static void php3_hw_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
{
pval *argv[4];
***************
*** 468,474 ****
char *password = NULL;
char *hashed_details;
char *str = NULL;
! char buffer[20];
int hashed_details_length;
hw_connection *ptr;
int do_swap;
--- 471,477 ----
char *password = NULL;
char *hashed_details;
char *str = NULL;
! char buffer[BUFFERLEN];
int hashed_details_length;
hw_connection *ptr;
int do_swap;
***************
*** 510,516 ****
}
/* Create identifier string for connection */
! sprintf(buffer, "%d", port);
hashed_details_length = strlen(host)+strlen(buffer)+8;
if(NULL == (hashed_details = (char *) emalloc(hashed_details_length+1))) {
if(host) efree(host);
--- 513,519 ----
}
/* Create identifier string for connection */
! snprintf(buffer, BUFFERLEN, "%d", port);
hashed_details_length = strlen(host)+strlen(buffer)+8;
if(NULL == (hashed_details = (char *) emalloc(hashed_details_length+1))) {
if(host) efree(host);
***************
*** 519,525 ****
php3_error(E_ERROR, "Could not get memory for connection details");
RETURN_FALSE;
}
! sprintf(hashed_details,"hw_%s_%d",host,port);
if (persistent) {
list_entry *le;
--- 522,528 ----
php3_error(E_ERROR, "Could not get memory for connection details");
RETURN_FALSE;
}
! sprintf(hashed_details, "hw_%s_%d", host, port);
if (persistent) {
list_entry *le;
***************
*** 716,721 ****
--- 719,725 ----
ptr->username = NULL;
efree(userdata);
}
+ #undef BUFFERLEN
/* Start of user level functions */
/* ***************************** */
***************
*** 897,902 ****
--- 901,909 ----
case LOCKED:
sprintf(errstr, "Object locked; try again later");
break;
+ case NOTREMOVED:
+ sprintf(errstr, "Attribute not removed");
+ break;
default:
sprintf(errstr, "Unknown error: %d", ptr->lasterror);
}
***************
*** 1199,1205 ****
set_swap(ptr->swap_on);
{
char *object = NULL;
- char *attrname, *str;
if (0 != (ptr->lasterror = send_getandlock(ptr->socket, id, &object)))
RETURN_FALSE;
--- 1206,1211 ----
***************
*** 1267,1277 ****
/* {{{ proto void hw_changeobject(int link, int objid, array attributes)
Changes attributes of an object */
void php3_hw_changeobject(INTERNAL_FUNCTION_PARAMETERS) {
pval *arg1, *arg2, *arg3;
int link, id, type, i;
hw_connection *ptr;
! char *modification, *oldobjrec, buf[200];
HashTable *newobjarr;
TLS_VARS;
--- 1273,1284 ----
/* {{{ proto void hw_changeobject(int link, int objid, array attributes)
Changes attributes of an object */
+ #define BUFFERLEN 200
void php3_hw_changeobject(INTERNAL_FUNCTION_PARAMETERS) {
pval *arg1, *arg2, *arg3;
int link, id, type, i;
hw_connection *ptr;
! char *modification, *oldobjrec, buf[BUFFERLEN];
HashTable *newobjarr;
TLS_VARS;
***************
*** 1297,1303 ****
_php3_hash_internal_pointer_reset(newobjarr);
modification = strdup("");
for(i=0; i<_php3_hash_num_elements(newobjarr); i++) {
! char *key, *str, *str1, newattribute[200];
pval *data;
int j, noinsert=1;
ulong ind;
--- 1304,1310 ----
_php3_hash_internal_pointer_reset(newobjarr);
modification = strdup("");
for(i=0; i<_php3_hash_num_elements(newobjarr); i++) {
! char *key, *str, *str1, newattribute[BUFFERLEN];
pval *data;
int j, noinsert=1;
ulong ind;
***************
*** 1307,1319 ****
switch(data->type) {
case IS_STRING:
if(strlen(data->value.str.val) == 0)
! sprintf(newattribute, "rem %s", key);
else
! sprintf(newattribute, "add %s=%s", key, data->value.str.val);
noinsert = 0;
break;
default:
! sprintf(newattribute, "%s", "");
}
if(!noinsert) {
modification = fnInsStr(modification, 0, "\\");
--- 1314,1326 ----
switch(data->type) {
case IS_STRING:
if(strlen(data->value.str.val) == 0)
! snprintf(newattribute, BUFFERLEN, "rem %s", key);
else
! snprintf(newattribute, BUFFERLEN, "add %s=%s", key, data->value.str.val);
noinsert = 0;
break;
default:
! newattribute[0] = '\0';
}
if(!noinsert) {
modification = fnInsStr(modification, 0, "\\");
***************
*** 1324,1330 ****
if(NULL != (str = strstr(oldobjrec, key))) {
str1 = str;
j = 0;
! while((str1 != NULL) && (*str1 != '\n')) {
buf[j++] = *str1++;
}
buf[j] = '\0';
--- 1331,1337 ----
if(NULL != (str = strstr(oldobjrec, key))) {
str1 = str;
j = 0;
! while((str1 != NULL) && (*str1 != '\n') && (j < BUFFERLEN-1)) {
buf[j++] = *str1++;
}
buf[j] = '\0';
***************
*** 1345,1359 ****
free(modification);
RETURN_TRUE;
}
/* }}} */
/* {{{ proto void hw_modifyobject(int link, int objid, array attributes)
Changes attributes of an object */
void php3_hw_modifyobject(INTERNAL_FUNCTION_PARAMETERS) {
pval *arg1, *arg2, *arg3, *arg4;
int link, id, type, i;
hw_connection *ptr;
! char *modification, buf[200];
HashTable *remobjarr, *addobjarr;
TLS_VARS;
--- 1352,1368 ----
free(modification);
RETURN_TRUE;
}
+ #undef BUFFERLEN
/* }}} */
/* {{{ proto void hw_modifyobject(int link, int objid, array attributes)
Changes attributes of an object */
+ #define BUFFERLEN 200
void php3_hw_modifyobject(INTERNAL_FUNCTION_PARAMETERS) {
pval *arg1, *arg2, *arg3, *arg4;
int link, id, type, i;
hw_connection *ptr;
! char *modification;
HashTable *remobjarr, *addobjarr;
TLS_VARS;
***************
*** 1378,1394 ****
if(addobjarr != NULL) {
_php3_hash_internal_pointer_reset(addobjarr);
for(i=0; i<_php3_hash_num_elements(addobjarr); i++) {
! char *key, *str, *str1, addattribute[200];
pval *data;
! int j, noinsert=1;
ulong ind;
_php3_hash_get_current_key(addobjarr, &key, &ind);
_php3_hash_get_current_data(addobjarr, (void *) &data);
switch(data->type) {
case IS_STRING:
! sprintf(addattribute, "add %s=%s", key, data->value.str.val);
! noinsert = 0;
break;
}
if(!noinsert) {
--- 1387,1406 ----
if(addobjarr != NULL) {
_php3_hash_internal_pointer_reset(addobjarr);
for(i=0; i<_php3_hash_num_elements(addobjarr); i++) {
! char *key, addattribute[BUFFERLEN];
pval *data;
! int noinsert=1;
ulong ind;
_php3_hash_get_current_key(addobjarr, &key, &ind);
_php3_hash_get_current_data(addobjarr, (void *) &data);
switch(data->type) {
case IS_STRING:
! if(strlen(data->value.str.val) > 0) {
! snprintf(addattribute, BUFFERLEN, "add %s=%s", key, data->value.str.val);
! fprintf(stderr, "add: %s\n", addattribute);
! noinsert = 0;
! }
break;
}
if(!noinsert) {
***************
*** 1403,1420 ****
if(remobjarr != NULL) {
_php3_hash_internal_pointer_reset(remobjarr);
for(i=0; i<_php3_hash_num_elements(remobjarr); i++) {
! char *key, *str, *str1, remattribute[200];
pval *data;
! int j, noinsert=1;
ulong ind;
_php3_hash_get_current_key(remobjarr, &key, &ind);
_php3_hash_get_current_data(remobjarr, (void *) &data);
switch(data->type) {
case IS_STRING:
! sprintf(remattribute, "rem %s=%s", key, data->value.str.val);
! noinsert = 0;
! break;
}
if(!noinsert) {
modification = fnInsStr(modification, 0, "\\");
--- 1415,1434 ----
if(remobjarr != NULL) {
_php3_hash_internal_pointer_reset(remobjarr);
for(i=0; i<_php3_hash_num_elements(remobjarr); i++) {
! char *key, remattribute[BUFFERLEN];
pval *data;
! int noinsert=1;
ulong ind;
_php3_hash_get_current_key(remobjarr, &key, &ind);
_php3_hash_get_current_data(remobjarr, (void *) &data);
switch(data->type) {
case IS_STRING:
! if(strlen(data->value.str.val) > 0) {
! snprintf(remattribute, BUFFERLEN, "rem %s=%s", key, data->value.str.val);
! noinsert = 0;
! }
! break;
}
if(!noinsert) {
modification = fnInsStr(modification, 0, "\\");
***************
*** 1427,1438 ****
set_swap(ptr->swap_on);
modification[strlen(modification)-1] = '\0';
! /* fprintf(stderr, "modifyobject: %s\n", modification); */
if (0 != (ptr->lasterror = send_changeobject(ptr->socket, id, modification)))
RETURN_FALSE;
free(modification);
RETURN_TRUE;
}
/* }}} */
void php3_hw_mvcp(INTERNAL_FUNCTION_PARAMETERS, int mvcp) {
--- 1441,1453 ----
set_swap(ptr->swap_on);
modification[strlen(modification)-1] = '\0';
! /* fprintf(stderr, "modifyobject: %s\n", modification); */
if (0 != (ptr->lasterror = send_changeobject(ptr->socket, id, modification)))
RETURN_FALSE;
free(modification);
RETURN_TRUE;
}
+ #undef BUFFERLEN
/* }}} */
void php3_hw_mvcp(INTERNAL_FUNCTION_PARAMETERS, int mvcp) {
***************
*** 1642,1653 ****
/* {{{ proto hwdoc hw_getcgi(int link, int objid)
Returns the output of a cgi script */
void php3_hw_getcgi(INTERNAL_FUNCTION_PARAMETERS) {
pval *arg1, *arg2;
int link, id, type;
hw_document *doc;
hw_connection *ptr;
! char cgi_env_str[1000];
TLS_VARS;
if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
--- 1657,1670 ----
/* {{{ proto hwdoc hw_getcgi(int link, int objid)
Returns the output of a cgi script */
+ #define BUFFERLEN 1000
+ /* FIX ME: The buffer cgi_env_str should be allocated dynamically */
void php3_hw_getcgi(INTERNAL_FUNCTION_PARAMETERS) {
pval *arg1, *arg2;
int link, id, type;
hw_document *doc;
hw_connection *ptr;
! char cgi_env_str[BUFFERLEN];
TLS_VARS;
if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
***************
*** 1678,1689 ****
requires.
*/
#if (WIN32|WINNT)
! sprintf(cgi_env_str, "CGI_REQUEST_METHOD=%s\nCGI_PATH_INFO=%s\nCGI_QUERY_STRING=%s",
getenv("REQUEST_METHOD"),
getenv("PATH_INFO"),
getenv("QUERY_STRING"));
#else
! sprintf(cgi_env_str, "CGI_REQUEST_METHOD=%s\nCGI_PATH_INFO=%s\nCGI_QUERY_STRING=%s",
GLOBAL(request_info).request_method,
GLOBAL(request_info).path_info,
GLOBAL(request_info).query_string);
--- 1695,1706 ----
requires.
*/
#if (WIN32|WINNT)
! snprintf(cgi_env_str, BUFFERLEN,
"CGI_REQUEST_METHOD=%s\nCGI_PATH_INFO=%s\nCGI_QUERY_STRING=%s",
getenv("REQUEST_METHOD"),
getenv("PATH_INFO"),
getenv("QUERY_STRING"));
#else
! snprintf(cgi_env_str, BUFFERLEN,
"CGI_REQUEST_METHOD=%s\nCGI_PATH_INFO=%s\nCGI_QUERY_STRING=%s",
GLOBAL(request_info).request_method,
GLOBAL(request_info).path_info,
GLOBAL(request_info).query_string);
***************
*** 1700,1705 ****
--- 1717,1723 ----
return_value->type = IS_LONG;
}
}
+ #undef BUFFERLEN
/* }}} */
/* {{{ proto int hw_getremote(int link, int objid)
***************
*** 1945,1950 ****
--- 1963,1970 ----
/* {{{ proto hwdoc hw_pipecgi(int link, int objid)
Returns output of cgi script */
+ #define BUFFERLEN 1000
+ /* FIX ME: The buffer cgi_env_str should be allocated dynamically */
void php3_hw_pipecgi(INTERNAL_FUNCTION_PARAMETERS) {
pval *arg1, *arg2;
int link, id, type;
***************
*** 1976,1987 ****
int count;
#if (WIN32|WINNT)
! sprintf(cgi_env_str, "CGI_REQUEST_METHOD=%s\nCGI_PATH_INFO=%s\nCGI_QUERY_STRING=%s",
getenv("REQUEST_METHOD"),
getenv("PATH_INFO"),
getenv("QUERY_STRING"));
#else
! sprintf(cgi_env_str, "CGI_REQUEST_METHOD=%s\nCGI_PATH_INFO=%s\nCGI_QUERY_STRING=%s",
GLOBAL(request_info).request_method,
GLOBAL(request_info).path_info,
GLOBAL(request_info).query_string);
--- 1996,2007 ----
int count;
#if (WIN32|WINNT)
! snprintf(cgi_env_str, BUFFERLEN,
"CGI_REQUEST_METHOD=%s\nCGI_PATH_INFO=%s\nCGI_QUERY_STRING=%s",
getenv("REQUEST_METHOD"),
getenv("PATH_INFO"),
getenv("QUERY_STRING"));
#else
! snprintf(cgi_env_str, BUFFERLEN,
"CGI_REQUEST_METHOD=%s\nCGI_PATH_INFO=%s\nCGI_QUERY_STRING=%s",
GLOBAL(request_info).request_method,
GLOBAL(request_info).path_info,
GLOBAL(request_info).query_string);
***************
*** 2005,2010 ****
--- 2025,2031 ----
return_value->type = IS_LONG;
}
}
+ #undef BUFFERLEN
/* }}} */
/* {{{ proto void hw_insertdocument(int link, int parentid, hwdoc doc)
Index: php3/functions/pdf.c
diff -c php3/functions/pdf.c:1.26 php3/functions/pdf.c:1.27
*** php3/functions/pdf.c:1.26 Thu Mar 25 01:27:48 1999
--- php3/functions/pdf.c Fri Apr 16 08:09:52 1999
***************
*** 27,33 ****
+----------------------------------------------------------------------+
*/
! /* $Id: pdf.c,v 1.26 1999/03/25 06:27:48 steinm Exp $ */
/* pdflib 0.6 is subject to the ALADDIN FREE PUBLIC LICENSE.
Copyright (C) 1997 Thomas Merz. */
--- 27,33 ----
+----------------------------------------------------------------------+
*/
! /* $Id: pdf.c,v 1.27 1999/04/16 12:09:52 steinm Exp $ */
/* pdflib 0.6 is subject to the ALADDIN FREE PUBLIC LICENSE.
Copyright (C) 1997 Thomas Merz. */
***************
*** 569,574 ****
--- 569,578 ----
RETURN_FALSE;
}
+ if(arg4->value.lval > 6) {
+ php3_error(E_WARNING,"Font encoding set to 5");
+ arg4->value.lval = 5;
+ }
PDF_set_font(pdf, arg2->value.str.val, (float) arg3->value.dval, arg4->value.lval);
RETURN_TRUE;
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net