Skip to content

Commit 8b9cd3f

Browse files
committed
Wrong checks on return values of write and pread syscalls
1 parent 7bbfd14 commit 8b9cd3f

File tree

7 files changed

+26
-18
lines changed

7 files changed

+26
-18
lines changed

atop.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ int linelen = 80;
314314
char acctreason; /* accounting not active (return val) */
315315
char rawname[RAWNAMESZ];
316316
char rawreadflag;
317-
unsigned int begintime, endtime;
317+
time_t begintime, endtime;
318318
char flaglist[MAXFL];
319319
char deviatonly = 1;
320320
char usecolors = 1; /* boolean: colors for high occupation */
@@ -551,12 +551,12 @@ main(int argc, char *argv[])
551551
break;
552552

553553
case 'b': /* begin time ? */
554-
if ( !hhmm2secs(optarg, &begintime) )
554+
if ( !branchtime2secs(optarg, &begintime) )
555555
prusage(argv[0]);
556556
break;
557557

558558
case 'e': /* end time ? */
559-
if ( !hhmm2secs(optarg, &endtime) )
559+
if ( !branchtime2secs(optarg, &endtime) )
560560
prusage(argv[0]);
561561
break;
562562

atop.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ extern char threadview;
8282
extern char calcpss;
8383
extern char rawname[];
8484
extern char rawreadflag;
85-
extern unsigned int begintime, endtime;
85+
extern time_t begintime, endtime;
8686
extern char flaglist[];
8787
extern struct visualize vis;
8888

@@ -137,7 +137,7 @@ void generic_usage(void);
137137
int atopsar(int, char *[]);
138138
char *convtime(time_t, char *);
139139
char *convdate(time_t, char *);
140-
int hhmm2secs(char *, unsigned int *);
140+
int branchtime2secs(char *, time_t *);
141141
int daysecs(time_t);
142142

143143
char *val2valstr(count_t, char *, int, int, int);

atopacctd.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ main(int argc, char *argv[])
306306
umask(022);
307307

308308
liResult = chdir("/tmp"); // go to a safe place
309-
if( liResult != 0 )
309+
310+
if(liResult != 0)
310311
{
311312
char lcMessage[64];
312313

@@ -1005,7 +1006,8 @@ setcurrent(long curshadow)
10051006
** wipe currency file and write new assembled string
10061007
*/
10071008
liResult = ftruncate(cfd, 0);
1008-
if( liResult != 0 )
1009+
1010+
if(liResult != 0)
10091011
{
10101012
char lcMessage[64];
10111013

@@ -1016,8 +1018,10 @@ setcurrent(long curshadow)
10161018
}
10171019

10181020
(void) lseek(cfd, 0, SEEK_SET);
1021+
10191022
liResult = write(cfd, currentdata, len);
1020-
if( liResult != 0 )
1023+
1024+
if(liResult == -1)
10211025
{
10221026
char lcMessage[64];
10231027

atopsar.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,14 @@ atopsar(int argc, char *argv[])
154154
break;
155155

156156
case 'b': /* begin time ? */
157-
if ( !hhmm2secs(optarg, &begintime) )
157+
if ( !branchtime2secs(optarg, &begintime) )
158158
pratopsaruse(argv[0]);
159159

160160
saved_begintime = begintime;
161161
break;
162162

163163
case 'e': /* end time ? */
164-
if ( !hhmm2secs(optarg, &endtime) )
164+
if ( !branchtime2secs(optarg, &endtime) )
165165
pratopsaruse(argv[0]);
166166
break;
167167

rawlog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ rawread(void)
663663
char *buf = malloc(READAHEADSIZE);
664664
ptrverify(buf, "Malloc failed for readahead");
665665
liResult = pread(rawfd, buf, READAHEADSIZE, next_pos & ~(READAHEADSIZE - 1));
666-
if(liResult != 0)
666+
if(liResult == -1)
667667
{
668668
char lcMessage[64];
669669

showgeneric.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ generic_samp(time_t curtime, int nsecs,
350350
register int i, curline, statline, nproc;
351351
int firstproc = 0, plistsz, alistsz, killpid, killsig;
352352
int lastchar;
353-
char format1[16], format2[16], hhmm[16];
353+
char format1[16], format2[16], branchtime[32];
354354
char *statmsg = NULL, statbuf[80], genline[80];
355355
char *lastsortp, curorder, autoorder;
356356
char buf[33];
@@ -1120,13 +1120,15 @@ generic_samp(time_t curtime, int nsecs,
11201120
echo();
11211121
move(statline, 0);
11221122
clrtoeol();
1123-
printw("Enter new time (format hh:mm): ");
1123+
printw("Enter new time "
1124+
"(format hh:mm): ");
1125+
// TODO: "(format [[YYYY]MMDD/]hh:mm): ");
11241126

1125-
hhmm[0] = '\0';
1126-
scanw("%15s\n", hhmm);
1127+
branchtime[0] = '\0';
1128+
scanw("%31s\n", branchtime);
11271129
noecho();
11281130

1129-
if ( !hhmm2secs(hhmm, &begintime) )
1131+
if ( !branchtime2secs(branchtime, &begintime) )
11301132
{
11311133
move(statline, 0);
11321134
clrtoeol();

various.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,15 @@ convdate(time_t utime, char *chardat)
153153

154154

155155
/*
156-
** Convert a hh:mm string into a number of seconds since 00:00
156+
** TODO: Convert a string in format [[YYYY]MMDD/]hh[:]mm into an epoch time value
157+
** TODO: When only the value hh[:]mm was given, take this time from midnight
158+
** Convert a string in format hh:mm number of seconds since midnight.
157159
**
158160
** Return-value: 0 - Wrong input-format
159161
** 1 - Success
160162
*/
161163
int
162-
hhmm2secs(char *itim, unsigned int *otim)
164+
branchtime2secs(char *itim, time_t *otim)
163165
{
164166
register int i;
165167
int hours, minutes;

0 commit comments

Comments
 (0)