petsc/petsc-progname.patch
2016-10-24 19:59:33 +02:00

72 lines
2.6 KiB
Diff

From 1a5f81e5a142bc6fde36c3a51c072ace33ca0cf8 Mon Sep 17 00:00:00 2001
From: Barry Smith <bsmith@mcs.anl.gov>
Date: Fri, 12 Aug 2016 14:02:28 -0500
Subject: [PATCH] Remove use of unitialized memory by always zeroing out end of
programname in petscinitialize_internal
Time: .5 hours
Reported-by: nightly tests
---
src/sys/objects/ftn-custom/zstart.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/src/sys/objects/ftn-custom/zstart.c b/src/sys/objects/ftn-custom/zstart.c
index fe16e32..086165e 100644
--- a/src/sys/objects/ftn-custom/zstart.c
+++ b/src/sys/objects/ftn-custom/zstart.c
@@ -250,13 +250,9 @@ extern PetscErrorCode PetscInitializeSAWs(const char[]);
*/
PETSC_EXTERN void PETSC_STDCALL petscinitialize_(CHAR filename PETSC_MIXED_LEN(len),PetscErrorCode *ierr PETSC_END_LEN(len))
{
+ int j,i;
#if defined (PETSC_USE_NARGS)
- short flg,i;
-#else
- int i;
-#if !defined(PETSC_HAVE_PXFGETARG_NEW) && !defined (PETSC_HAVE_PXFGETARG_NEW) && !defined(PETSC_HAVE_FORTRAN_GET_COMMAND_ARGUMENT)
- int j;
-#endif
+ short flg;
#endif
#if defined(PETSC_HAVE_CUDA)
PetscBool flg2;
@@ -267,7 +263,7 @@ PETSC_EXTERN void PETSC_STDCALL petscinitialize_(CHAR filename PETSC_MIXED_LEN(l
char *t1,name[256],hostname[64];
PetscMPIInt f_petsc_comm_world;
- *ierr = PetscMemzero(name,256); if (*ierr) return;
+ *ierr = PetscMemzero(name,sizeof(name)); if (*ierr) return;
if (PetscInitializeCalled) {*ierr = 0; return;}
/* this must be initialized in a routine, not as a constant declaration*/
@@ -283,7 +279,7 @@ PETSC_EXTERN void PETSC_STDCALL petscinitialize_(CHAR filename PETSC_MIXED_LEN(l
if (*ierr) return;
i = 0;
#if defined (PETSC_HAVE_FORTRAN_GET_COMMAND_ARGUMENT) /* same as 'else' case */
- getarg_(&i,name,256);
+ getarg_(&i,name,sizeof(name));
#elif defined (PETSC_HAVE_PXFGETARG_NEW)
{ int ilen,sierr;
getarg_(&i,name,&ilen,&sierr,256);
@@ -294,15 +290,15 @@ PETSC_EXTERN void PETSC_STDCALL petscinitialize_(CHAR filename PETSC_MIXED_LEN(l
GETARG(&i,name,256,&flg);
#else
getarg_(&i,name,256);
+#endif
/* Eliminate spaces at the end of the string */
- for (j=254; j>=0; j--) {
+ for (j=sizeof(name)-2; j>=0; j--) {
if (name[j] != ' ') {
name[j+1] = 0;
break;
}
}
if (j<0) PetscStrncpy(name,"Unknown Name",256);
-#endif
*ierr = PetscSetProgramName(name);
if (*ierr) {(*PetscErrorPrintf)("PetscInitialize: Calling PetscSetProgramName()\n");return;}
--
2.7.4.1.g5468f9e