Changeset 23


Ignore:
Timestamp:
May 3, 2015, 3:37:31 PM (10 years ago)
Author:
Alex Taylor
Message:

Fix possible trap using DosQuerySysState (patch from Steve Levine)

Location:
rxutilex/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • rxutilex/trunk/rxutilex.c

    r22 r23  
    3939// #define USE_DQPS
    4040
     41// Uncomment to use legacy C style locale data instead of the OS/2 ULS library
     42#define LEGACY_C_LOCALE
    4143
    4244#define INCL_WINATOM
     
    5254    #include <os2.h>
    5355#endif
    54 #include <locale.h>
     56
    5557#include <stdio.h>
    5658#include <stdlib.h>
    5759#include <string.h>
    5860#include <time.h>
     61
     62#ifdef LEGACY_C_LOCALE
     63    #include <locale.h>
     64    #include <nl_types.h>
     65    #include <langinfo.h>
     66#else
     67    #include <unidef.h>
     68#endif
     69
    5970#define INCL_RXSHV
    6071#define INCL_RXFUNC
    6172#include <rexxsaa.h>
    62 #include <nl_types.h>
    63 #include <langinfo.h>
    6473
    6574#pragma import( DosGetPrty, "DosGetPrty", "DOSCALL1", 9 )
     
    8594#define US_PIDSTR_MAXZ        ( CCHMAXPATH + 100 )                   // ...of a process information string
    8695#define US_TIMESTR_MAXZ         256                                  // ...of a formatted time string
    87 #define US_NUMSTR_MAXZ          256                                  // ...of a formatted number string
     96#define US_NUMSTR_MAXZ          64                                   // ...of a formatted number string
    8897#define US_PIPESTATUS_MAXZ      128                                  // ...of a pipe status string
    8998
     
    641650    QSPTRREC *pBuf;                     // Data returned by DosQProcStatus()
    642651#else
    643     QSGREC **pBuf;                      // Data returned by DosQuerySysState()
     652    QSPTRREC *pBuf;                      // Data returned by DosQuerySysState() // 2015-04-23 SHL
    644653#endif
    645654    QSPREC *pPrec;                      // Pointer to process information block
     
    673682    pBuf = (QSPTRREC *) malloc( UL_SSBUFSIZE );
    674683#else
    675     pBuf = (QSGREC **) malloc( UL_SSBUFSIZE );
     684    pBuf = (QSPTRREC *) malloc( UL_SSBUFSIZE ); // 2015-04-23 SHL
    676685#endif
    677686
     
    690699        return ( 0 );
    691700    }
    692     pPrec = pBuf->pProcRec;
     701    pPrec = pBuf->pProcRec;             // 2015-04-23 SHL
    693702#else
    694703    // Get running process information using DosQuerySysState()
     
    699708        return ( 0 );
    700709    }
    701     pPrec = (QSPREC *) ( (PBYTE) (*pBuf) + sizeof(QSGREC) );
     710    pPrec = pBuf->pProcRec;
    702711#endif
    703712
     
    916925 *                                                                           *
    917926 * REXX ARGUMENTS:                                                           *
    918  *   1. Number to be formatted.                                  (REQUIRED) *
    919  *   2. Number of decimal places to use for floating point values.  Ignored  *
    920  *      for integer values.  Defaults to 2 if not specified.                *
     927 *   1. Number to be formatted.                                   (REQUIRED) *
     928 *   2. Number of decimal places to use for floating point                   *
     929 *      values.  Ignored for integer values.                    (DEFAULT: 2) *
    921930 *                                                                           *
    922931 * REXX RETURN VALUE: The formatted number, or '' on error.                  *
     
    925934{
    926935    CHAR  achNumber[ US_NUMSTR_MAXZ ];  // Formatted output string
    927     PSZ   pszSep = NULL;
    928     float fVal;
    929     int   iVal;
    930     int   iPrec;
     936    float fVal;                         // Input value as floating point
     937    int   iVal;                         // Input value as integer
     938    int   iPrec;                        // Requested decimal precision
     939    PSZ   pszSep = NULL;                // Separator string
     940#ifndef LEGACY_C_LOCALE
     941    CHAR  achTemp[ US_NUMSTR_MAXZ ];    // Temporary buffer
     942    LocaleObject     locale = NULL;     // ULS locale object
     943    struct UniLconv *punilc = NULL;     // ULS locale conventions structure
     944    CHAR            *p      = NULL;     // Moving pointers within buffers
     945    CHAR            *q      = NULL;     // ...
     946    int              rc     = 0;
     947#endif
    931948
    932949    // Make sure we have at least one valid argument (the input number)
    933950    if ( argc < 1  || ( !RXVALIDSTRING(argv[0]) )) return ( 40 );
     951
     952#ifdef LEGACY_C_LOCALE
    934953
    935954    // Use the locale settings from the environment
     
    10121031    }
    10131032
     1033#else
     1034    rc = UniCreateLocaleObject( UNI_MBS_STRING_POINTER, "", &locale );
     1035    if ( rc != ULS_SUCCESS ) {
     1036        WriteErrorCode( rc, "UniCreateLocaleObject");
     1037        MAKERXSTRING( *prsResult, "", 0 );
     1038        return ( 0 );
     1039    }
     1040    rc = UniQueryLocaleInfo(locale_object, &puni_lconv);
     1041    if ( rc != ULS_SUCCESS ) {
     1042        WriteErrorCode( rc, "UniQueryLocaleInfo");
     1043        MAKERXSTRING( *prsResult, "", 0 );
     1044        return ( 0 );
     1045     }
     1046
     1047    // Check for a decimal place and treat as float or integer accordingly
     1048    if ( strchr( argv[0].strptr, '.') != NULL ) {
     1049        if (( sscanf( argv[0].strptr, "%f", &fVal )) != 1 ) return ( 40 );
     1050        if ( argc >= 2  && ( RXVALIDSTRING(argv[1]) ) &&
     1051             (( sscanf( argv[1].strptr, "%d", &iPrec )) == 1 ))
     1052        {
     1053            // Use user-specified precision
     1054            sprintf( achNumber, "%.*f", iPrec, fVal );
     1055        }
     1056        else
     1057            sprintf( achNumber, "%.2f", fVal );
     1058    }
     1059    else {
     1060        if (( sscanf( argv[0].strptr, "%d", &iVal )) != 1 ) return ( 40 );
     1061        sprintf( achNumber, "%d", iVal );
     1062    }
     1063
     1064#endif
     1065
    10141066    // Return the formatted number
    10151067    MAKERXSTRING( *prsResult, achNumber, strlen( achNumber ));
     
    13401392    WriteErrorCode( 0, NULL );
    13411393
    1342     // Parse the various time items
    13431394    if ( !(argc == 1 && RXVALIDSTRING(argv[0])) ) return ( 40 );
    13441395
     
    20732124    QSPTRREC *pBuf;                     // Data returned by DosQProcStatus()
    20742125#else
    2075     QSGREC **pBuf;                      // Data returned by DosQuerySysState()
     2126    QSPTRREC *pBuf;                     // Data returned by DosQuerySysState()  // 2015-04-23 SHL
    20762127#endif
    20772128    QSPREC *pPrec;                      // Pointer to process information block
     
    21022153    pBuf = (QSPTRREC *) malloc( UL_SSBUFSIZE );
    21032154#else
    2104     pBuf = (QSGREC **) malloc( UL_SSBUFSIZE );
     2155    pBuf = (QSPTRREC *) malloc( UL_SSBUFSIZE ); // 2015-04-23 SHL
    21052156#endif
    21062157
     
    21252176        return ( rc );
    21262177    }
    2127     pPrec = (QSPREC *) ( (PBYTE) (*pBuf) + sizeof(QSGREC) );
     2178    pPrec = (QSPREC *)(((QSPTRREC*)pBuf) -> pProcRec);  // 2015-04-23 SHL
    21282179#endif
    21292180
     
    23342385    ulRc = RexxVariablePool( &shvVar );
    23352386    if ( ulRc > 1 )
    2336         printf("Unable to set %s: rc = %d\n", shvVar.shvname.strptr, shvVar.shvret );
    2337 }
    2338 
    2339 
     2387        printf("Unable to set %s: rc = %d, ulRc = %x\n", shvVar.shvname.strptr, shvVar.shvret, ulRc ); /* 2015-04-23 SHL */
     2388}
     2389
     2390
  • rxutilex/trunk/rxutilex.def

    r22 r23  
    11LIBRARY     RXUTILEX INITINSTANCE TERMINSTANCE
    22DATA        MULTIPLE NONSHARED
    3 DESCRIPTION '@#Alex Taylor:0.1.0#@##1## 31 Oct 2014 20:32:56     REINFORCE::::::@@Extended REXX Utility Functions'
     3DESCRIPTION '@#Alex Taylor:0.1.1#@##1## 3 May 2015 22:36:07      REINFORCE::::::@@Extended REXX Utility Functions'
    44
    55EXPORTS     Sys2LoadFuncs
Note: See TracChangeset for help on using the changeset viewer.