* Ludwig Nussel (ludwig.nussel@suse.de) [20091203 09:44]:
than the specified length. So for example if FIELD_STR == sizeof(fields) and len == 0 it would overflow the buffer by one zero byte. Add a -1 to the calculation.
This is the code: define Test_add_field(FIELD_NB, FIELD_STR) \ if ( (bit_test(details, FIELD_NB)) ) { \ strncat(fields, FIELD_STR, sizeof(fields)-1 - len); \ len += (sizeof(FIELD_STR)-1); \ } #define Add_field(FIELD_STR) \ strncat(fields, FIELD_STR, sizeof(fields) - len); \ len += (sizeof(FIELD_STR)-1); void print_fields(int fd, unsigned char *details) /* print a line describing the field types used in print_line() */ { char fields[TERM_LEN]; char field_user[] = " USER "; char field_id[] = "ID "; char field_rq[] = " R&Q "; char field_options[] = " OPTIONS "; char field_schedule[] = " SCHEDULE "; char field_until[] = " LAVG 1,5,15 UNTIL STRICT"; char field_pid[] = " PID "; char field_index[] = " INDEX"; char field_cmd[] = " CMD"; char field_endline[] = "\n"; int len = 0; fields[0] = '\0'; Add_field(field_id); /* <--- This is the line in question */ Test_add_field(FIELD_USER, field_user); Shouldn't Add _field be defined as define Add_field(FIELD_STR) \ strncat(fields, FIELD_STR, sizeof(fields)-1 - len); \ len += (sizeof(FIELD_STR)-1); ? Philipp -- To unsubscribe, e-mail: opensuse-packaging+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-packaging+help@opensuse.org