bugSystem V style init programs - Bugs: bug #49991, bootlogd, some minor potential...

 
 

bug #49991: bootlogd, some minor potential errors in little used paths.

Submitted by:  None
Submitted on:  Thu 05 Jan 2017 08:43:45 PM UTC  
 
Category: NoneSeverity: 3 - Normal
Item Group: NoneStatus: None
Privacy: PublicAssigned to: None
Open/Closed: Open

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Thu 05 Jan 2017 08:43:45 PM UTC, original submission:

Tab handling, original version:
case '\t':
line.pos += (line.pos / 8 + 1) * 8;
if (line.pos >= (int)sizeof(line.buf))
line.pos = sizeof(line.buf) - 1;
break;
A possible working revision using a new integer variable opos:
int opos;

case '\t':
opos = line.pos;
line.pos = ((line.pos / 8) + 1) * 8;
if (line.pos >= (int)sizeof(line.buf))
line.pos = (int)sizeof(line.buf) - 1;
for ( ; opos <= line.pos; opos++) {
memcpy(line.buf + opos, " ", 1);
}
break;
2 problems with original:
1) The calculation to convert tabs to spaces is wrong.
2) Skipping forward leaves \0 characters so the line is cut at the first tab.

Variable used when uninitialised:
int main(int argc, char **argv)
{
char buf[1024];

if ((realfd = open_nb(realcons)) < 0) {
fprintf(stderr, "bootlogd: %s: %s\n", buf, strerror(errno));
return 1;
}
buf is uninitialised at this point in main. realcons was buf in open_nb, so is probably what was intended to be printed.

Testing the 2 tab versions, this is running a modified bootlogd from xfce4-terminal with the console device hardcoded.

$ sudo ./tabbootlogd
$ pidof tabbootlogd
1033
$ sudo su
# printf "hello again\n" >/dev/console
# printf "space tab\tnow 2 tabs:\t\t3:\t\t\t<\n" >/dev/console
# kill 1033
# exit
exit
$ sudo ./notab-bootlogd
$ pidof notab-bootlogd
1080
$ sudo su
# printf "hello again\n" >/dev/console
# printf "space tab\tnow 2 tabs:\t\t3:\t\t\t<\n" >/dev/console

The correct output is printed on the console device TTY1 (CTRL ALT F1, then CTRL ALT F7 to return) but the log file says this:

Thu Jan 5 14:00:31 2017: hello again
Thu Jan 5 14:01:42 2017: space tab now 2 tabs: 3: <
Thu Jan 5 14:11:37 2017: hello again
Thu Jan 5 14:11:51 2017: space tab

Correcting the line truncation issue but using the original calculation gives some sort of exponential tab size growth:
# printf "Original sum now\n" >/dev/console
# printf "space tab\tnow 2 tabs:\t\t3:\t\t\t<\n" >/dev/console
# printf "big tabs there\n" >/dev/console

Thu Jan 5 20:05:46 2017: Original sum now
Thu Jan 5 20:06:01 2017: space tab now 2 tabs:

3:
Thu Jan 5 20:06:32 2017: big tabs there

Also on the mailing list I saw you might include the Debian patches, one leaves a few unused functions and variables after it is applied, I didn't look at those patches in great detail though.
(Not sure if all the whitespace copied and pasted exactly but hopefully you will get the idea)
Best wishes.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

Do you think this task is very important?
If so, you can click here to add your encouragement to it.
This task has 0 encouragements so far.

Only logged-in users can vote.

 

Please enter the title of George Orwell's famous dystopian book (it's a date):

 

 

No Changes Have Been Made to This Item

Back to the top


Powered by Savane 3.1-cleanup1