Skip to content

Commit

Permalink
Rebase 32-bit overflow fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnoKing committed Mar 9, 2024
1 parent 9a48c61 commit a9ce636
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/cmd/builtin/pty.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ mkpty(int* master, int* minion)
static Proc_t*
runcmd(char** argv, int minion, int session)
{
long ops[4];
int64_t ops[4];

if (session)
{
Expand Down
19 changes: 12 additions & 7 deletions src/cmd/ksh93/include/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,22 @@ extern char *sh_getcwd(void);
#endif
#define sh_translate(s) _sh_translate(ERROR_dictionary(s))

#define WBITS (sizeof(long)*8)
#define WBITS (sizeof(int64_t)*8)
#define WMASK (0xff)
#if LONG_MAX == INT_MAX
#define WL 1LL
#else
#define WL 1L
#endif

#if SHOPT_SCRIPTONLY
#define is_option(s,x) ((x)==SH_INTERACTIVE || (x)==SH_HISTORY ? 0 : ((s)->v[((x)&WMASK)/WBITS] & (1L << ((x) % WBITS))) )
#define on_option(s,x) ( (x)==SH_INTERACTIVE || (x)==SH_HISTORY ? errormsg(SH_DICT,ERROR_exit(1),e_scriptonly) : ((s)->v[((x)&WMASK)/WBITS] |= (1L << ((x) % WBITS))) )
#define off_option(s,x) ((x)==SH_INTERACTIVE || (x)==SH_HISTORY ? 0 : ((s)->v[((x)&WMASK)/WBITS] &= ~(1L << ((x) % WBITS))) )
#define is_option(s,x) ((x)==SH_INTERACTIVE || (x)==SH_HISTORY ? 0 : ((s)->v[((x)&WMASK)/WBITS] & (WL << ((x) % WBITS))) )
#define on_option(s,x) ( (x)==SH_INTERACTIVE || (x)==SH_HISTORY ? errormsg(SH_DICT,ERROR_exit(1),e_scriptonly) : ((s)->v[((x)&WMASK)/WBITS] |= (WL << ((x) % WBITS))) )
#define off_option(s,x) ((x)==SH_INTERACTIVE || (x)==SH_HISTORY ? 0 : ((s)->v[((x)&WMASK)/WBITS] &= ~(WL << ((x) % WBITS))) )
#else
#define is_option(s,x) ((s)->v[((x)&WMASK)/WBITS] & (1L << ((x) % WBITS)))
#define on_option(s,x) ((s)->v[((x)&WMASK)/WBITS] |= (1L << ((x) % WBITS)))
#define off_option(s,x) ((s)->v[((x)&WMASK)/WBITS] &= ~(1L << ((x) % WBITS)))
#define is_option(s,x) ((s)->v[((x)&WMASK)/WBITS] & (WL << ((x) % WBITS)))
#define on_option(s,x) ((s)->v[((x)&WMASK)/WBITS] |= (WL << ((x) % WBITS)))
#define off_option(s,x) ((s)->v[((x)&WMASK)/WBITS] &= ~(WL << ((x) % WBITS)))
#endif /* SHOPT_SCRIPTONLY */
#define sh_isoption(x) is_option(&sh.options,x)
#define sh_onoption(x) on_option(&sh.options,x)
Expand Down
8 changes: 4 additions & 4 deletions src/cmd/ksh93/include/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
/* options */
typedef struct
{
unsigned long v[4];
uint64_t v[4];
}
Shopt_t;

Expand Down Expand Up @@ -468,9 +468,9 @@ extern void *sh_waitnotify(Shwait_f);
extern Shscope_t *sh_getscope(int,int);
extern Shscope_t *sh_setscope(Shscope_t*);
extern void sh_sigcheck(void);
extern unsigned long sh_isoption(int);
extern unsigned long sh_onoption(int);
extern unsigned long sh_offoption(int);
extern uint64_t sh_isoption(int);
extern uint64_t sh_onoption(int);
extern uint64_t sh_offoption(int);
extern int sh_exec(const Shnode_t*,int);

/*
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/ksh93/sh/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -2041,17 +2041,17 @@ static void env_init(void)
*/
#define BYPASS_MACRO

unsigned long sh_isoption BYPASS_MACRO (int opt)
uint64_t sh_isoption BYPASS_MACRO (int opt)
{
return sh_isoption(opt);
}

unsigned long sh_onoption BYPASS_MACRO (int opt)
uint64_t sh_onoption BYPASS_MACRO (int opt)
{
return sh_onoption(opt);
}

unsigned long sh_offoption BYPASS_MACRO (int opt)
uint64_t sh_offoption BYPASS_MACRO (int opt)
{
return sh_offoption(opt);
}
Expand Down
28 changes: 14 additions & 14 deletions src/cmd/ksh93/sh/timers.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

typedef struct _timer
{
double wakeup;
double incr;
Sfdouble_t wakeup;
Sfdouble_t incr;
struct _timer *next;
void (*action)(void*);
void *handle;
Expand All @@ -42,29 +42,29 @@ typedef struct _timer
static Timer_t *tptop, *tpmin, *tpfree;
static char time_state;

static double getnow(void)
static Sfdouble_t getnow(void)
{
double now;
Sfdouble_t now;
#ifdef timeofday
struct timeval tp;
timeofday(&tp);
now = tp.tv_sec + 1.e-6*tp.tv_usec;

#else
now = (double)time(NULL);
now = (Sfdouble_t)time(NULL);
#endif /* timeofday */
return now+.001;
}

/*
* set an alarm for <t> seconds
*/
static double setalarm(double t)
static double setalarm(Sfdouble_t t)
{
#if defined(_lib_setitimer) && defined(ITIMER_REAL)
struct itimerval tnew, told;
tnew.it_value.tv_sec = t;
tnew.it_value.tv_usec = 1.e6*(t- (double)tnew.it_value.tv_sec);
tnew.it_value.tv_usec = 1.e6*(t- (Sfdouble_t)tnew.it_value.tv_sec);
if(t && tnew.it_value.tv_sec==0 && tnew.it_value.tv_usec<1000)
tnew.it_value.tv_usec = 1000;
tnew.it_interval.tv_sec = 0;
Expand All @@ -88,8 +88,8 @@ static double setalarm(double t)
static void sigalrm(int sig)
{
Timer_t *tp, *tplast, *tpold, *tpnext;
double now;
static double left;
Sfdouble_t now;
static Sfdouble_t left;
NOT_USED(sig);
left = 0;
if(time_state&SIGALRM_CALL)
Expand Down Expand Up @@ -179,12 +179,12 @@ static void oldalrm(void *handle)
(*fn)(SIGALRM);
}

void *sh_timeradd(unsigned long msec,int flags,void (*action)(void*),void *handle)
void *sh_timeradd(Sfulong_t msec,int flags,void (*action)(void*),void *handle)
{
Timer_t *tp;
double t;
Sfdouble_t t;
Handler_t fn;
t = ((double)msec)/1000.;
t = ((Sfdouble_t)msec)/1000.;
if(t<=0 || !action)
return NULL;
if(tp=tpfree)
Expand All @@ -206,7 +206,7 @@ void *sh_timeradd(unsigned long msec,int flags,void (*action)(void*),void *handl
{
Handler_t *hp = (Handler_t*)sh_malloc(sizeof(Handler_t));
*hp = fn;
sh_timeradd((long)(1000*t), 0, oldalrm, hp);
sh_timeradd((Sflong_t)(1000*t), 0, oldalrm, hp);
}
tp = tptop;
}
Expand Down Expand Up @@ -238,7 +238,7 @@ void sh_timerdel(void *handle)
if(tpmin)
{
tpmin = 0;
setalarm((double)0);
setalarm((Sfdouble_t)0);
}
signal(SIGALRM,(sh.sigflag[SIGALRM]&SH_SIGFAULT)?sh_fault:SIG_DFL);
}
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/ksh93/shell.3
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ Shell_t *sh_getinterp(void);

Namval_t *sh_addbuiltin(const char *\fIname\fP, Sh_bltin_f \fIfn\fP, void *\fIarg\fP);

unsigned int sh_isoption(int \fIoption\fP);
unsigned int sh_onoption(int \fIoption\fP);
unsigned int sh_offoption(int \fIoption\fP);
uint64_t sh_isoption(int \fIoption\fP);
uint64_t sh_onoption(int \fIoption\fP);
uint64_t sh_offoption(int \fIoption\fP);

void *sh_parse(Sfio_t *\fIsp\fP, int \fIflags\fP);
int sh_trap(const char *\fIstring\fP, int \fImode\fP);
Expand Down
10 changes: 5 additions & 5 deletions src/lib/libast/include/proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@

#define PROC_fd_ctty 0xc

#define PROC_op1(o,a) (((long)(o)<<(2*PROC_ARG_BIT))|((long)(a)&((PROC_ARG_NULL<<PROC_ARG_BIT)|PROC_ARG_NULL)))
#define PROC_op2(o,a,b) (((long)(o)<<(2*PROC_ARG_BIT))|(((long)(b)&PROC_ARG_NULL)<<PROC_ARG_BIT)|((long)(a)&PROC_ARG_NULL))
#define PROC_op1(o,a) (((int64_t)(o)<<(2*PROC_ARG_BIT))|((int64_t)(a)&((PROC_ARG_NULL<<PROC_ARG_BIT)|PROC_ARG_NULL)))
#define PROC_op2(o,a,b) (((int64_t)(o)<<(2*PROC_ARG_BIT))|(((int64_t)(b)&PROC_ARG_NULL)<<PROC_ARG_BIT)|((int64_t)(a)&PROC_ARG_NULL))

#define PROC_FD_CLOSE(p,f) PROC_op2(PROC_fd_dup|(f),p,PROC_ARG_NULL)
#define PROC_FD_CTTY(f) PROC_op1(PROC_fd_ctty,f)
Expand All @@ -75,8 +75,8 @@
#define PROC_SYS_PGRP(g) PROC_op1(PROC_sys_pgrp,g)
#define PROC_SYS_UMASK(m) PROC_op1(PROC_sys_umask,m,0)

#define PROC_OP(x) (((x)>>(2*PROC_ARG_BIT))&((1<<PROC_OP_BIT)-1))
#define PROC_ARG(x,n) ((n)?(((x)>>(((n)-1)*PROC_ARG_BIT))&PROC_ARG_NULL):(((x)&~((1<<(2*PROC_ARG_BIT))-1))==~((1<<(2*PROC_ARG_BIT))-1))?(-1):((x)&~((1<<(2*PROC_ARG_BIT))-1)))
#define PROC_OP(x) (((int64_t)(x)>>(2*PROC_ARG_BIT))&((1<<PROC_OP_BIT)-1))
#define PROC_ARG(x,n) ((n)?(((int64_t)(x)>>(((n)-1)*PROC_ARG_BIT))&PROC_ARG_NULL):(((int64_t)(x)&~((1<<(2*PROC_ARG_BIT))-1))==~((1<<(2*PROC_ARG_BIT))-1))?(-1):((int64_t)(x)&~((1<<(2*PROC_ARG_BIT))-1)))

typedef struct
{
Expand All @@ -93,7 +93,7 @@ _PROC_PRIVATE_

extern int procclose(Proc_t*);
extern int procfree(Proc_t*);
extern Proc_t* procopen(const char*, char**, char**, long*, int);
extern Proc_t* procopen(const char*, char**, char**, int64_t*, int);
extern int procrun(const char*, char**, int);

#endif
2 changes: 1 addition & 1 deletion src/lib/libast/man/proc.3
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ proc \- process control routines (deprecated)
.EX
#include <proc.h>
Proc_t* procopen(const char* \fIcommand\fP, char** \fIargv\fP, char** \fIenvv\fP, long* \fIopv\fP, long \fIflags\fP);
Proc_t* procopen(const char* \fIcommand\fP, char** \fIargv\fP, char** \fIenvv\fP, int64_t* \fIopv\fP, int \fIflags\fP);
int procfree(Proc_t* \fIproc\fP);
int procclose(Proc_t* \fIproc\fP);
int procrun(const char* \fIcommand\fP, char** \fIargv\fP);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/libast/misc/procopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ restore(Proc_t* proc)
*/

Proc_t*
procopen(const char* cmd, char** argv, char** envv, long* modv, int flags)
procopen(const char* cmd, char** argv, char** envv, int64_t* modv, int flags)
{
Proc_t* proc = 0;
int procfd = -1;
Expand All @@ -399,7 +399,7 @@ procopen(const char* cmd, char** argv, char** envv, long* modv, int flags)
int i;
int forked = 0;
int signalled = 0;
long n;
int64_t n;
char path[PATH_MAX];
char env[PATH_MAX + 2];
int pio[2];
Expand Down
2 changes: 1 addition & 1 deletion src/lib/libast/misc/systrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ systrace(const char* id)
char* s;
char buf[PATH_MAX];
char* av[7];
long ov[2];
int64_t ov[2];

static char* trace[] = { "trace", "truss", "strace", "traces" };

Expand Down
2 changes: 1 addition & 1 deletion src/lib/libast/path/pathprobe.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pathprobe_20100601(const char* lang, const char* tool, const char* aproc, int op
char ver[PATH_MAX];
char key[16];
char* arg[8];
long ops[2];
int64_t ops[2];
unsigned long ptime;
struct stat st;
struct stat ps;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/libast/port/astconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,7 @@ nativeconf(Proc_t** pp, const char* operand)
{
Sfio_t* sp;
char* cmd[3];
long ops[2];
int64_t ops[2];

#if DEBUG_astconf
error(-6, "astconf defer %s %s", _pth_getconf, operand);
Expand Down

0 comments on commit a9ce636

Please sign in to comment.