1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782
|
From 8e823b5d2d7eada3c67033b222df9906339861e3 Mon Sep 17 00:00:00 2001
From: Paul Elliott <pelliott@blackpatchpanel.com>
Date: Sun, 22 Sep 2013 02:30:15 -0500
Subject: harden library, swetest against buffer overflow attack on sprintf
calls to sprintf with '%s' in format replaced with snprint calls.
Forwarded: privately
Author: Paul Elliott <pelliott@blackpatchpanel.com>
astrodienst/src/swecl.c | 2 +-
astrodienst/src/swehel.c | 11 ++--
astrodienst/src/swejpl.c | 4 +-
astrodienst/src/swemplan.c | 23 ++++----
astrodienst/src/sweph.c | 34 +++++------
astrodienst/src/swephlib.c | 16 +++---
astrodienst/src/swetest.c | 140 ++++++++++++++++++++++++---------------------
7 files changed, 120 insertions(+), 110 deletions(-)
diff --git a/astrodienst/src/swecl.c b/astrodienst/src/swecl.c
index 5bd3766..7a92514 100644
@@ -1588,7 +1588,7 @@ next_try:
} else {
swe_get_planet_name(ipl , s);
}
- sprintf(serr, "error in swe_lun_occult_when_glob(): conjunction of moon with planet %s not found\n", s);
+ snprintf(serr, AS_MAXCH, "error in swe_lun_occult_when_glob(): conjunction of moon with planet %s not found\n", s);
}
return ERR;
}
diff --git a/astrodienst/src/swehel.c b/astrodienst/src/swehel.c
index 1080f20..98bcc49 100644
@@ -2407,7 +2407,8 @@ static int32 get_asc_obl(double tjd, int32 ipl, char *star, int32 iflag, double
strcpy(s, star);
else
swe_get_planet_name(ipl, s);
- sprintf(serr, "%s is circumpolar, cannot calculate heliacal event", s);
+ snprintf(serr, AS_MAXCH,
+ "%s is circumpolar, cannot calculate heliacal event", s);
return -2;
}
adp = asin(adp) / DEGTORAD;
@@ -2439,7 +2440,7 @@ static int32 get_asc_obl_old(double tjd, int32 ipl, char *star, int32 iflag, dou
strcpy(s, star);
else
swe_get_planet_name(ipl, s);
- sprintf(serr, "%s is circumpolar, cannot calculate heliacal event", s);
+ snprintf(serr, AS_MAXCH, "%s is circumpolar, cannot calculate heliacal event", s);
return -2;
}
adp = asin(adp) / DEGTORAD;
@@ -3342,7 +3343,7 @@ int32 FAR PASCAL_CONV swe_heliacal_ut(double JDNDaysUTStart, double *dgeo, doubl
if (Planet == SE_MOON) {
if (TypeEvent == 1 || TypeEvent == 2) {
if (serr_ret != NULL) {
- sprintf(serr_ret, "%s (event type %d) does not exist for the moon\n", sevent[TypeEvent], TypeEvent);
+ snprintf(serr_ret, AS_MAXCH, "%s (event type %d) does not exist for the moon\n", sevent[TypeEvent], TypeEvent);
}
return ERR;
}
@@ -3368,7 +3369,7 @@ int32 FAR PASCAL_CONV swe_heliacal_ut(double JDNDaysUTStart, double *dgeo, doubl
strcpy(s, ObjectName);
else
swe_get_planet_name(Planet, s);
- sprintf(serr_ret, "%s (event type %d) does not exist for %s\n", sevent[TypeEvent], TypeEvent, s);
+ snprintf(serr_ret, AS_MAXCH, "%s (event type %d) does not exist for %s\n", sevent[TypeEvent], TypeEvent, s);
}
return ERR;
}
@@ -3391,7 +3392,7 @@ int32 FAR PASCAL_CONV swe_heliacal_ut(double JDNDaysUTStart, double *dgeo, doubl
strcpy(s, ObjectName);
else
swe_get_planet_name(Planet, s);
- sprintf(serr_ret, "%s (event type %d) is not provided for %s\n", sevent[TypeEvent], TypeEvent, s);
+ snprintf(serr_ret, AS_MAXCH, "%s (event type %d) is not provided for %s\n", sevent[TypeEvent], TypeEvent, s);
}
return ERR;
}
diff --git a/astrodienst/src/swejpl.c b/astrodienst/src/swejpl.c
index fcc5786..b04aecb 100644
@@ -209,7 +209,7 @@ static int32 fsizer(char *serr)
if (serr != NULL) {
strcpy(serr, "alleged ephemeris file has invalid format.");
if (strlen(serr) + strlen(js->jplfname) + 3 < AS_MAXCH) {
- sprintf(serr, "alleged ephemeris file (%s) has invalid format.", js->jplfname);
+ snprintf(serr, AS_MAXCH, "alleged ephemeris file (%s) has invalid format.", js->jplfname);
}
}
return(NOT_AVAILABLE);
@@ -740,7 +740,7 @@ static int state(double et, int32 *list, int do_bary,
if (serr != NULL) {
sprintf(serr, "JPL ephemeris file is mutilated; length = %d instead of %d.", flen, nb);
if (strlen(serr) + strlen(js->jplfname) < AS_MAXCH - 1) {
- sprintf(serr, "JPL ephemeris file %s is mutilated; length = %d instead of %d.", js->jplfname, flen, nb);
+ snprintf(serr, AS_MAXCH, "JPL ephemeris file %s is mutilated; length = %d instead of %d.", js->jplfname, flen, nb);
}
}
return(NOT_AVAILABLE);
diff --git a/astrodienst/src/swemplan.c b/astrodienst/src/swemplan.c
index cfd07a8..f379fe4 100644
@@ -754,10 +754,11 @@ static int read_elements_file(int32 ipl, double tjd,
if ((sp = strchr(s, '#')) != NULL)
*sp = '\0';
ncpos = swi_cutstr(s, ",", cpos, 20);
- sprintf(serri, "error in file %s, line %7.0f:", SE_FICTFILE, (double) iline);
+ snprintf(serri, AS_MAXCH, "error in file %s, line %7.0f:",
+ SE_FICTFILE, (double) iline);
if (ncpos < 9) {
if (serr != NULL) {
- sprintf(serr, "%s nine elements required", serri);
+ snprintf(serr, AS_MAXCH, "%s nine elements required", serri);
}
return ERR;
}
@@ -778,7 +779,7 @@ static int read_elements_file(int32 ipl, double tjd,
*tjd0 = J1900;
else if (*sp == 'j' || *sp == 'b') {
if (serr != NULL) {
- sprintf(serr, "%s invalid epoch", serri);
+ snprintf(serr, AS_MAXCH, "%s invalid epoch", serri);
}
goto return_err;
} else
@@ -802,7 +803,7 @@ static int read_elements_file(int32 ipl, double tjd,
*tequ = tjd;
else if (*sp == 'j' || *sp == 'b') {
if (serr != NULL) {
- sprintf(serr, "%s invalid equinox", serri);
+ snprintf(serr, AS_MAXCH, "%s invalid equinox", serri);
}
goto return_err;
} else
@@ -814,7 +815,7 @@ static int read_elements_file(int32 ipl, double tjd,
*mano = swe_degnorm(*mano);
if (retc == ERR) {
if (serr != NULL) {
- sprintf(serr, "%s mean anomaly value invalid", serri);
+ snprintf(serr, AS_MAXCH, "%s mean anomaly value invalid", serri);
}
goto return_err;
}
@@ -832,7 +833,7 @@ static int read_elements_file(int32 ipl, double tjd,
retc = check_t_terms(tt, cpos[3], sema);
if (*sema <= 0 || retc == ERR) {
if (serr != NULL) {
- sprintf(serr, "%s semi-axis value invalid", serri);
+ snprintf(serr, AS_MAXCH, "%s semi-axis value invalid", serri);
}
goto return_err;
}
@@ -842,7 +843,7 @@ static int read_elements_file(int32 ipl, double tjd,
retc = check_t_terms(tt, cpos[4], ecce);
if (*ecce >= 1 || *ecce < 0 || retc == ERR) {
if (serr != NULL) {
- sprintf(serr, "%s eccentricity invalid (no parabolic or hyperbolic orbits allowed)", serri);
+ snprintf(serr, AS_MAXCH, "%s eccentricity invalid (no parabolic or hyperbolic orbits allowed)", serri);
}
goto return_err;
}
@@ -853,7 +854,7 @@ static int read_elements_file(int32 ipl, double tjd,
*parg = swe_degnorm(*parg);
if (retc == ERR) {
if (serr != NULL) {
- sprintf(serr, "%s perihelion argument value invalid", serri);
+ snprintf(serr, AS_MAXCH, "%s perihelion argument value invalid", serri);
}
goto return_err;
}
@@ -865,7 +866,7 @@ static int read_elements_file(int32 ipl, double tjd,
*node = swe_degnorm(*node);
if (retc == ERR) {
if (serr != NULL) {
- sprintf(serr, "%s node value invalid", serri);
+ snprintf(serr, AS_MAXCH, "%s node value invalid", serri);
}
goto return_err;
}
@@ -877,7 +878,7 @@ static int read_elements_file(int32 ipl, double tjd,
*incl = swe_degnorm(*incl);
if (retc == ERR) {
if (serr != NULL) {
- sprintf(serr, "%s inclination value invalid", serri);
+ snprintf(serr, AS_MAXCH, "%s inclination value invalid", serri);
}
goto return_err;
}
@@ -902,7 +903,7 @@ static int read_elements_file(int32 ipl, double tjd,
}
if (!elem_found) {
if (serr != NULL) {
- sprintf(serr, "%s elements for planet %7.0f not found", serri, (double) ipl);
+ snprintf(serr, AS_MAXCH, "%s elements for planet %7.0f not found", serri, (double) ipl);
}
goto return_err;
}
diff --git a/astrodienst/src/sweph.c b/astrodienst/src/sweph.c
index b8ff275..d7b7430 100644
@@ -1844,7 +1844,7 @@ again:
char *spp;
spp = strchr(s, '.');
if (spp > s && *(spp-1) != 's') { /* no 's' before '.' ? */
- sprintf(spp, "s.%s", SE_FILE_SUFFIX); /* insert an 's' */
+ snprintf(spp, AS_MAXCH, "s.%s", SE_FILE_SUFFIX); /* insert an 's' */
goto again;
}
/*
@@ -2007,7 +2007,7 @@ FILE *swi_fopen(int ifno, char *fname, char *ephepath, char *serr)
if (fp != NULL)
return fp;
}
- sprintf(s, "SwissEph file '%s' not found in PATH '%s'", fname, ephepath);
+ snprintf(s, AS_MAXCH, "SwissEph file '%s' not found in PATH '%s'", fname, ephepath);
s[AS_MAXCH-1] = '\0'; /* s must not be longer then AS_MAXCH */
if (serr != NULL)
strcpy(serr, s);
@@ -3565,7 +3565,7 @@ static int get_new_segment(double tjd, int ipli, int ifno, char *serr)
if (serr != NULL) {
sprintf(serr, "error in ephemeris file: %d coefficients instead of %d. ", nco, pdp->ncoe);
if (strlen(serr) + strlen(fdp->fnam) < AS_MAXCH - 1) {
- sprintf(serr, "error in ephemeris file %s: %d coefficients instead of %d. ", fdp->fnam, nco, pdp->ncoe);
+ snprintf(serr, AS_MAXCH, "error in ephemeris file %s: %d coefficients instead of %d. ", fdp->fnam, nco, pdp->ncoe);
}
}
free(pdp->segp);
@@ -3706,7 +3706,7 @@ static int read_const(int ifno, char *serr)
*sp = tolower((int) *sp);
if (strcmp(s2, s) != 0) {
if (serr != NULL) {
- sprintf(serr, "Ephemeris file name '%s' wrong; rename '%s' ", s2, s);
+ snprintf(serr, AS_MAXCH, "Ephemeris file name '%s' wrong; rename '%s' ", s2, s);
}
goto return_error;
}
@@ -3984,7 +3984,7 @@ file_damage:
if (serr != NULL) {
*serr = '\0';
if (strlen(serr_file_damage) + strlen(fdp->fnam) < AS_MAXCH) {
- sprintf(serr, serr_file_damage, fdp->fnam);
+ snprintf(serr, AS_MAXCH, serr_file_damage, fdp->fnam);
}
}
return_error:
@@ -4022,7 +4022,7 @@ static int do_fread(void *trg, int size, int count, int corrsize, FILE *fp, int3
if (serr != NULL) {
strcpy(serr, "Ephemeris file is damaged. ");
if (strlen(serr) + strlen(swed.fidat[ifno].fnam) < AS_MAXCH - 1) {
- sprintf(serr, "Ephemeris file %s is damaged.", swed.fidat[ifno].fnam);
+ snprintf(serr, AS_MAXCH, "Ephemeris file %s is damaged.", swed.fidat[ifno].fnam);
}
}
fclose(fp);
@@ -4035,7 +4035,7 @@ static int do_fread(void *trg, int size, int count, int corrsize, FILE *fp, int3
if (serr != NULL) {
strcpy(serr, "Ephemeris file is damaged. ");
if (strlen(serr) + strlen(swed.fidat[ifno].fnam) < AS_MAXCH - 1) {
- sprintf(serr, "Ephemeris file %s is damaged.", swed.fidat[ifno].fnam);
+ snprintf(serr, AS_MAXCH, "Ephemeris file %s is damaged.", swed.fidat[ifno].fnam);
}
}
fclose(fp);
@@ -5313,7 +5313,7 @@ int32 FAR PASCAL_CONV swe_fixstar(char *star, double tjd, int32 iflag,
continue;
if ((sp = strchr(s, ',')) == NULL) {
if (serr != NULL) {
- sprintf(serr, "star file %s damaged at line %d", SE_STARFILE, fline);
+ snprintf(serr, AS_MAXCH, "star file %s damaged at line %d", SE_STARFILE, fline);
}
retc = ERR;
goto return_err;
@@ -5343,7 +5343,7 @@ int32 FAR PASCAL_CONV swe_fixstar(char *star, double tjd, int32 iflag,
if (serr != NULL) {
sprintf(serr, "star not found");
if (strlen(serr) + strlen(star) < AS_MAXCH) {
- sprintf(serr, "star %s not found", star);
+ snprintf(serr, AS_MAXCH, "star %s not found", star);
}
}
retc = ERR;
@@ -5356,7 +5356,7 @@ int32 FAR PASCAL_CONV swe_fixstar(char *star, double tjd, int32 iflag,
swi_right_trim(cpos[1]);
if (i < 13) {
if (serr != NULL) {
- sprintf(serr, "data of star '%s,%s' incomplete", cpos[0], cpos[1]);
+ snprintf(serr, AS_MAXCH, "data of star '%s,%s' incomplete", cpos[0], cpos[1]);
}
retc = ERR;
goto return_err;
@@ -5378,9 +5378,7 @@ int32 FAR PASCAL_CONV swe_fixstar(char *star, double tjd, int32 iflag,
cpos[0][SE_MAX_STNAME] = '\0';
if (strlen(cpos[1]) > SE_MAX_STNAME-1)
cpos[1][SE_MAX_STNAME-1] = '\0';
- strcpy(star, cpos[0]);
- if (strlen(cpos[0]) + strlen(cpos[1]) + 1 < SE_MAX_STNAME - 1)
- sprintf(star + strlen(star), ",%s", cpos[1]);
+ snprintf(star, (SE_MAX_STNAME-1) , "%s,%s", cpos[0], cpos[1]);
/****************************************
* position and speed (equinox)
****************************************/
@@ -5726,7 +5724,7 @@ int32 FAR PASCAL_CONV swe_fixstar_mag(char *star, double *mag, char *serr)
continue;
if ((sp = strchr(s, ',')) == NULL) {
if (serr != NULL) {
- sprintf(serr, "star file %s damaged at line %d", SE_STARFILE, fline);
+ snprintf(serr, AS_MAXCH, "star file %s damaged at line %d", SE_STARFILE, fline);
}
retc = ERR;
goto return_err;
@@ -5754,7 +5752,7 @@ int32 FAR PASCAL_CONV swe_fixstar_mag(char *star, double *mag, char *serr)
if (serr != NULL) {
strcpy(serr, "star not found");
if (strlen(serr) + strlen(star) < AS_MAXCH) {
- sprintf(serr, "star %s not found", star);
+ snprintf(serr,AS_MAXCH, "star %s not found", star);
}
}
retc = ERR;
@@ -5767,7 +5765,7 @@ int32 FAR PASCAL_CONV swe_fixstar_mag(char *star, double *mag, char *serr)
if (serr != NULL) {
strcpy(serr, "data of star incomplete");
if (strlen(serr) + strlen(cpos[0]) + strlen(cpos[1]) + 2 < AS_MAXCH) {
- sprintf(serr, "data of star '%s,%s' incomplete", cpos[0], cpos[1]);
+ snprintf(serr,AS_MAXCH, "data of star '%s,%s' incomplete", cpos[0], cpos[1]);
}
}
retc = ERR;
@@ -5779,9 +5777,7 @@ int32 FAR PASCAL_CONV swe_fixstar_mag(char *star, double *mag, char *serr)
cpos[0][SE_MAX_STNAME] = '\0';
if (strlen(cpos[1]) > SE_MAX_STNAME-1)
cpos[1][SE_MAX_STNAME-1] = '\0';
- strcpy(star, cpos[0]);
- if (strlen(cpos[0]) + strlen(cpos[1]) + 1 < SE_MAX_STNAME - 1)
- sprintf(star + strlen(star), ",%s", cpos[1]);
+ snprintf(star, (SE_MAX_STNAME) , "%s,%s", cpos[0], cpos[1]);
return OK;
return_err:
*mag = 0;
diff --git a/astrodienst/src/swephlib.c b/astrodienst/src/swephlib.c
index 3a67dee..6364d42 100644
@@ -2325,7 +2325,9 @@ void swi_gen_filename(double tjd, int ipli, char *fname)
sform = "ast%d%sse%05d.%s";
if (ipli - SE_AST_OFFSET > 99999)
sform = "ast%d%ss%06d.%s";
- sprintf(fname, sform, (ipli - SE_AST_OFFSET) / 1000, DIR_GLUE, ipli - SE_AST_OFFSET, SE_FILE_SUFFIX);
+ snprintf(fname, AS_MAXCH, sform,
+ (ipli - SE_AST_OFFSET) / 1000, DIR_GLUE, ipli - SE_AST_OFFSET,
+ SE_FILE_SUFFIX);
return; /* asteroids: only one file 3000 bc - 3000 ad */
/* break; */
}
@@ -2361,7 +2363,7 @@ void swi_gen_filename(double tjd, int ipli, char *fname)
else
strcat(fname, "_");
icty = abs(icty);
- sprintf(fname + strlen(fname), "%02d.%s", icty, SE_FILE_SUFFIX);
+ snprintf(fname + strlen(fname),AS_MAXCH - strlen(fname), "%02d.%s", icty, SE_FILE_SUFFIX);
#if 0
printf("fname %s\n", fname);
fflush(stdout);
@@ -2601,7 +2603,7 @@ char *FAR PASCAL_CONV swe_cs2degstr(CSEC t, char *a)
s = t % 60L;
m = t / 60 % 60L;
h = t / 3600 % 100L; /* only 0..99 degrees */
- sprintf(a, "%2d%s%02d'%02d", h, ODEGREE_STRING, m, s);
+ snprintf(a, 9, "%2d%s%02d'%02d", h, ODEGREE_STRING, m, s);
return (a);
} /* swe_cs2degstr() */
@@ -2771,11 +2773,11 @@ void swi_open_trace(char *serr)
# else
ipid = getpid();
# endif
- sprintf(sp1, "_%d%s", ipid, sp);
+ snprintf(sp1, AS_MAXCH, "_%d%s", ipid, sp);
#endif
if ((swi_fp_trace_c = fopen(fname, FILE_A_ACCESS)) == NULL) {
if (serr != NULL) {
- sprintf(serr, "could not open trace output file '%s'", fname);
+ snprintf(serr, AS_MAXCH, "could not open trace output file '%s'", fname);
}
} else {
fputs("#include \"sweodef.h\"\n", swi_fp_trace_c);
@@ -2804,11 +2806,11 @@ void swi_open_trace(char *serr)
# else
ipid = getpid();
# endif
- sprintf(sp1, "_%d%s", ipid, sp);
+ snprintf(sp1, AS_MAXCH, "_%d%s", ipid, sp);
#endif
if ((swi_fp_trace_out = fopen(fname, FILE_A_ACCESS)) == NULL) {
if (serr != NULL) {
- sprintf(serr, "could not open trace output file '%s'", fname);
+ snprintf(serr, AS_MAXCH, "could not open trace output file '%s'", fname);
}
}
}
diff --git a/astrodienst/src/swetest.c b/astrodienst/src/swetest.c
index c017b02..5254c6a 100644
@@ -907,10 +907,7 @@ int main(int argc, char *argv[])
fputs(infoexamp,stdout);
goto end_main;
} else {
- strcpy(sout, "illegal option ");
- strncat(sout, argv[i], sizeof(sout) - 50);
- strcat(sout, "\n");
- fputs(sout,stdout);
+ printf("illegal option %s\n", argv[i]);
exit(1);
}
}
@@ -1002,7 +999,7 @@ int main(int argc, char *argv[])
strcpy (sdate_save, sdate);
}
if (*sdate == '\0') {
- sprintf(sdate, "j%f", tjd);
+ snprintf(sdate,sizeof(sdate), "j%f", tjd);
}
if (*sp == 'j') { /* it's a day number */
if ((sp2 = strchr(sp, ',')) != NULL)
@@ -1865,18 +1862,18 @@ static char *dms(double xv, int32 iflg)
izod = (int) (xv / 30);
xv = fmod(xv, 30);
kdeg = (int32) xv;
- sprintf(s, "%2d %s ", kdeg, zod_nam[izod]);
+ snprintf(s,sizeof(s), "%2d %s ", kdeg, zod_nam[izod]);
} else {
kdeg = (int32) xv;
- sprintf(s, " %3d%s", kdeg, c);
+ snprintf(s,sizeof(s), " %3d%s", kdeg, c);
}
xv -= kdeg;
xv *= 60;
kmin = (int32) xv;
if ((iflg & BIT_ZODIAC) && (iflg & BIT_ROUND_MIN)) {
- sprintf(s1, "%2d", kmin);
+ snprintf(s1,sizeof(s1), "%2d", kmin);
} else {
- sprintf(s1, "%2d'", kmin);
+ snprintf(s1,sizeof(s1), "%2d'", kmin);
}
strcat(s, s1);
if (iflg & BIT_ROUND_MIN)
@@ -1885,16 +1882,16 @@ static char *dms(double xv, int32 iflg)
xv *= 60;
ksec = (int32) xv;
if (iflg & BIT_ROUND_SEC) {
- sprintf(s1, "%2d\"", ksec);
+ snprintf(s1,sizeof(s1), "%2d\"", ksec);
} else {
- sprintf(s1, "%2d", ksec);
+ snprintf(s1,sizeof(s1), "%2d", ksec);
}
strcat(s, s1);
if (iflg & BIT_ROUND_SEC)
goto return_dms;
xv -= ksec;
k = (int32) (xv * 10000);
- sprintf(s1, ".%04d", k);
+ snprintf(s1,sizeof(s1), ".%04d", k);
strcat(s, s1);
return_dms:;
if (sgn < 0) {
@@ -1971,14 +1968,16 @@ static int32 call_rise_set(double t_ut, int32 ipl, char *star, int32 whicheph, i
strcat(sout, " - ");
} else {
swe_revjul(tret[0], gregflag, &jyear, &jmon, &jday, &jut);
- sprintf(sout + strlen(sout), "%2d.%02d.%04d\t%s ", jday, jmon, jyear, hms(jut,BIT_LZEROES));
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "%2d.%02d.%04d\t%s ",
+ jday, jmon, jyear, hms(jut,BIT_LZEROES));
}
strcat(sout, "set ");
if (tret[1] == 0) {
strcat(sout, " - \n");
} else {
swe_revjul(tret[1], gregflag, &jyear, &jmon, &jday, &jut);
- sprintf(sout + strlen(sout), "%2d.%02d.%04d\t%s\n", jday, jmon, jyear, hms(jut,BIT_LZEROES));
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "%2d.%02d.%04d\t%s\n",
+ jday, jmon, jyear, hms(jut,BIT_LZEROES));
}
do_printf(sout);
}
@@ -2000,13 +1999,15 @@ static int32 call_rise_set(double t_ut, int32 ipl, char *star, int32 whicheph, i
if (tret[0] == 0) strcat(sout, " - ");
else {
swe_revjul(tret[0], gregflag, &jyear, &jmon, &jday, &jut);
- sprintf(sout + strlen(sout), "%2d.%02d.%04d\t%s ", jday, jmon, jyear, hms(jut,BIT_LZEROES));
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "%2d.%02d.%04d\t%s ",
+ jday, jmon, jyear, hms(jut,BIT_LZEROES));
}
strcat(sout, "itransit ");
if (tret[1] == 0) strcat(sout, " - \n");
else {
swe_revjul(tret[1], gregflag, &jyear, &jmon, &jday, &jut);
- sprintf(sout + strlen(sout), "%2d.%02d.%04d\t%s\n", jday, jmon, jyear, hms(jut,BIT_LZEROES));
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "%2d.%02d.%04d\t%s\n",
+ jday, jmon, jyear, hms(jut,BIT_LZEROES));
}
do_printf(sout);
}
@@ -2048,7 +2049,7 @@ ERR) {
}
strcpy(sout, sfmt);
if (strchr(sfmt, '%') != NULL) {
- sprintf(sout, sfmt, attr[0]);
+ snprintf(sout,sizeof(sout), sfmt, attr[0]);
}
do_printf(sout);
}
@@ -2082,34 +2083,35 @@ ERR) {
return ERR;
}
dt = (tret[3] - tret[2]) * 24 * 60;
- sprintf(s1, "%d min %4.2f sec", (int) dt, fmod(dt, 1) * 60);
+ snprintf(s1,sizeof(s1), "%d min %4.2f sec",
+ (int) dt, fmod(dt, 1) * 60);
/* short output:
* date, time of day, umbral magnitude, umbral duration, saros series, member number */
- sprintf(sout_short, "%s\t%2d.%2d.%4d\t%s\t%.3f\t%s\t%d\t%d\n", sout, jday, jmon, jyear, hms(jut,0), attr[8],s1, (int) attr[9], (int) attr[10]);
- sprintf(sout + strlen(sout), "%2d.%02d.%04d\t%s\t%.4f/%.4f\tsaros %d/%d\t%.6f\n", jday, jmon, jyear, hms(jut,BIT_LZEROES), attr[0],attr[1], (int) attr[9], (int) attr[10], t_ut);
+ snprintf(sout_short,sizeof(sout_short) ,"%s\t%2d.%2d.%4d\t%s\t%.3f\t%s\t%d\t%d\n", sout, jday, jmon, jyear, hms(jut,0), attr[8],s1, (int) attr[9], (int) attr[10]);
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "%2d.%02d.%04d\t%s\t%.4f/%.4f\tsaros %d/%d\t%.6f\n", jday, jmon, jyear, hms(jut,BIT_LZEROES), attr[0],attr[1], (int) attr[9], (int) attr[10], t_ut);
/* second line:
* eclipse times, penumbral, partial, total begin and end */
- sprintf(sout + strlen(sout), " %s ", hms_from_tjd(tret[6]));
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), " %s ", hms_from_tjd(tret[6]));
if (tret[2] != 0)
- sprintf(sout + strlen(sout), "%s ", hms_from_tjd(tret[2]));
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "%s ", hms_from_tjd(tret[2]));
else
strcat(sout, " - ");
if (tret[4] != 0)
- sprintf(sout + strlen(sout), "%s ", hms_from_tjd(tret[4]));
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "%s ", hms_from_tjd(tret[4]));
else
strcat(sout, " - ");
if (tret[5] != 0)
- sprintf(sout + strlen(sout), "%s ", hms_from_tjd(tret[5]));
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "%s ", hms_from_tjd(tret[5]));
else
strcat(sout, " - ");
if (tret[3] != 0)
- sprintf(sout + strlen(sout), "%s ", hms_from_tjd(tret[3]));
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "%s ", hms_from_tjd(tret[3]));
else
strcat(sout, " - ");
- sprintf(sout + strlen(sout), "%s\n", hms_from_tjd(tret[7]));
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "%s\n", hms_from_tjd(tret[7]));
if (special_mode & SP_MODE_HOCAL) {
swe_split_deg(jut, SE_SPLIT_DEG_ROUND_MIN, &ihou, &imin, &isec, &dfrc, &isgn);
- sprintf(sout, "\"%04d %02d %02d %02d.%02d %d\",\n", jyear, jmon, jday, ihou, imin, ecl_type);
+ snprintf(sout,sizeof(sout), "\"%04d %02d %02d %02d.%02d %d\",\n", jyear, jmon, jday, ihou, imin, ecl_type);
}
if (short_output)
do_printf(sout_short);
@@ -2166,26 +2168,26 @@ attr, direction_flag, serr)) == ERR) {
swe_calc(t_ut + swe_deltat(t_ut), SE_ECL_NUT, 0, x, serr);
swe_revjul(t_ut, gregflag, &jyear, &jmon, &jday, &jut);
dt = (tret[3] - tret[2]) * 24 * 60;
- sprintf(sout + strlen(sout), "%2d.%02d.%04d\t%s\t%.4f/%.4f/%.4f\tsaros %d/%d\t%.6f\n", jday, jmon, jyear, hms(jut,BIT_LZEROES), attr[8], attr[0], attr[2], (int) attr[9], (int) attr[10], t_ut);
- sprintf(sout + strlen(sout), "\t%d min %4.2f sec\t", (int) dt, fmod(dt, 1) * 60);
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "%2d.%02d.%04d\t%s\t%.4f/%.4f/%.4f\tsaros %d/%d\t%.6f\n", jday, jmon, jyear, hms(jut,BIT_LZEROES), attr[8], attr[0], attr[2], (int) attr[9], (int) attr[10], t_ut);
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "\t%d min %4.2f sec\t", (int) dt, fmod(dt, 1) * 60);
if (eclflag & SE_ECL_1ST_VISIBLE)
- sprintf(sout + strlen(sout), "%s ", hms_from_tjd(tret[1]));
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "%s ", hms_from_tjd(tret[1]));
else
strcat(sout, " - ");
if (eclflag & SE_ECL_2ND_VISIBLE)
- sprintf(sout + strlen(sout), "%s ", hms_from_tjd(tret[2]));
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "%s ", hms_from_tjd(tret[2]));
else
strcat(sout, " - ");
if (eclflag & SE_ECL_3RD_VISIBLE)
- sprintf(sout + strlen(sout), "%s ", hms_from_tjd(tret[3]));
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "%s ", hms_from_tjd(tret[3]));
else
strcat(sout, " - ");
if (eclflag & SE_ECL_4TH_VISIBLE)
- sprintf(sout + strlen(sout), "%s ", hms_from_tjd(tret[4]));
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "%s ", hms_from_tjd(tret[4]));
else
strcat(sout, " - ");
#if 0
- sprintf(sout + strlen(sout), "\t%d min %4.2f sec %s %s %s %s",
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "\t%d min %4.2f sec %s %s %s %s",
(int) dt, fmod(dt, 1) * 60,
strcpy(s1, hms(fmod(tret[1] + 0.5, 1) * 24, BIT_LZEROES)),
strcpy(s3, hms(fmod(tret[2] + 0.5, 1) * 24, BIT_LZEROES)),
@@ -2226,21 +2228,23 @@ attr, direction_flag, serr)) == ERR) {
strcat(sout, "non-central ");
swe_sol_eclipse_where(t_ut, whicheph, geopos, attr, serr);
swe_revjul(t_ut, gregflag, &jyear, &jmon, &jday, &jut);
- sprintf(sout_short, "%s\t%2d.%2d.%4d\t%s\t%.3f", sout, jday, jmon, jyear, hms(jut,0), attr[8]);
- sprintf(sout + strlen(sout), "%2d.%02d.%04d\t%s\t%f km\t%.4f/%.4f/%.4f\tsaros %d/%d\t%.6f\n", jday, jmon, jyear, hms(jut,0), attr[3], attr[8], attr[0], attr[2], (int) attr[9], (int) attr[10], t_ut);
- sprintf(sout + strlen(sout), "\t%s ", hms_from_tjd(tret[2]));
+ snprintf(sout_short,sizeof(sout_short), "%s\t%2d.%2d.%4d\t%s\t%.3f",
+ sout, jday, jmon, jyear, hms(jut,0), attr[8]);
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "%2d.%02d.%04d\t%s\t%f km\t%.4f/%.4f/%.4f\tsaros %d/%d\t%.6f\n",
+ jday, jmon, jyear, hms(jut,0), attr[3], attr[8], attr[0], attr[2], (int) attr[9], (int) attr[10], t_ut);
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "\t%s ", hms_from_tjd(tret[2]));
if (tret[4] != 0) {
- sprintf(sout + strlen(sout), "%s ", hms_from_tjd(tret[4]));
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "%s ", hms_from_tjd(tret[4]));
} else {
strcat(sout, " - ");
}
if (tret[5] != 0) {
- sprintf(sout + strlen(sout), "%s ", hms_from_tjd(tret[5]));
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "%s ", hms_from_tjd(tret[5]));
} else {
strcat(sout, " - ");
}
- sprintf(sout + strlen(sout), "%s\n", hms_from_tjd(tret[3]));
- sprintf(sout + strlen(sout), "\t%s\t%s", strcpy(s1, dms(geopos[0], BIT_ROUND_MIN)), strcpy(s2, dms(geopos[1], BIT_ROUND_MIN)));
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "%s\n", hms_from_tjd(tret[3]));
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "\t%s\t%s", strcpy(s1, dms(geopos[0], BIT_ROUND_MIN)), strcpy(s2, dms(geopos[1], BIT_ROUND_MIN)));
strcat(sout, "\t");
strcat(sout_short, "\t");
if (!(eclflag & SE_ECL_PARTIAL) && !(eclflag & SE_ECL_NONCENTRAL)) {
@@ -2252,18 +2256,19 @@ geopos, tret, attr, 0, serr)) == ERR) {
if (fabs(tret[0] - t_ut) > 1)
do_printf("when_loc returns wrong date\n");
dt = (tret[3] - tret[2]) * 24 * 60;
- sprintf(s1, "%d min %4.2f sec", (int) dt, fmod(dt, 1) * 60);
+ snprintf(s1,sizeof(s1), "%d min %4.2f sec",
+ (int) dt, fmod(dt, 1) * 60);
strcat(sout, s1);
strcat(sout_short, s1);
}
- sprintf(sout_short + strlen(sout_short), "\t%d\t%d", (int) attr[9], (int) attr[10]);
+ snprintf(sout_short + strlen(sout_short),sizeof(sout_short) - strlen(sout_short), "\t%d\t%d", (int) attr[9], (int) attr[10]);
strcat(sout, "\n");
strcat(sout_short, "\n");
if (special_mode & SP_MODE_HOCAL) {
int ihou, imin, isec, isgn;
double dfrc;
swe_split_deg(jut, SE_SPLIT_DEG_ROUND_MIN, &ihou, &imin, &isec, &dfrc, &isgn);
- sprintf(sout, "\"%04d %02d %02d %02d.%02d %d\",\n", jyear, jmon, jday, ihou, imin, ecl_type);
+ snprintf(sout,sizeof(sout), "\"%04d %02d %02d %02d.%02d %d\",\n", jyear, jmon, jday, ihou, imin, ecl_type);
}
/*printf("len=%ld\n", strlen(sout));*/
if (short_output)
@@ -2318,26 +2323,26 @@ static int32 call_lunar_occultation(double t_ut, int32 ipl, char *star, int32 wh
swe_calc(t_ut + swe_deltat(t_ut), SE_ECL_NUT, 0, x, serr);
swe_revjul(t_ut, gregflag, &jyear, &jmon, &jday, &jut);
dt = (tret[3] - tret[2]) * 24 * 60;
- sprintf(sout + strlen(sout), "%2d.%02d.%04d\t%s\t%fo/o\n", jday, jmon, jyear, hms(jut,BIT_LZEROES), attr[0]);
- sprintf(sout + strlen(sout), "\t%d min %4.2f sec\t", (int) dt, fmod(dt, 1) * 60);
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "%2d.%02d.%04d\t%s\t%fo/o\n", jday, jmon, jyear, hms(jut,BIT_LZEROES), attr[0]);
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "\t%d min %4.2f sec\t", (int) dt, fmod(dt, 1) * 60);
if (eclflag & SE_ECL_1ST_VISIBLE)
- sprintf(sout + strlen(sout), "%s ", hms_from_tjd(tret[1]));
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "%s ", hms_from_tjd(tret[1]));
else
strcat(sout, " - ");
if (eclflag & SE_ECL_2ND_VISIBLE)
- sprintf(sout + strlen(sout), "%s ", hms_from_tjd(tret[2]));
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "%s ", hms_from_tjd(tret[2]));
else
strcat(sout, " - ");
if (eclflag & SE_ECL_3RD_VISIBLE)
- sprintf(sout + strlen(sout), "%s ", hms_from_tjd(tret[3]));
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "%s ", hms_from_tjd(tret[3]));
else
strcat(sout, " - ");
if (eclflag & SE_ECL_4TH_VISIBLE)
- sprintf(sout + strlen(sout), "%s ", hms_from_tjd(tret[4]));
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "%s ", hms_from_tjd(tret[4]));
else
strcat(sout, " - ");
#if 0
- sprintf(sout + strlen(sout), "\t%d min %4.2f sec %s %s %s %s",
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "\t%d min %4.2f sec %s %s %s %s",
(int) dt, fmod(dt, 1) * 60,
strcpy(s1, hms(fmod(tret[1] + 0.5, 1) * 24, BIT_LZEROES)),
strcpy(s3, hms(fmod(tret[2] + 0.5, 1) * 24, BIT_LZEROES)),
@@ -2376,18 +2381,21 @@ static int32 call_lunar_occultation(double t_ut, int32 ipl, char *star, int32 wh
strcat(sout, "non-central ");
swe_lun_occult_where(t_ut, ipl, star, whicheph, geopos, attr, serr);
swe_revjul(t_ut, gregflag, &jyear, &jmon, &jday, &jut);
- sprintf(sout + strlen(sout), "%2d.%02d.%04d\t%s\t%f km\t%f o/o\n", jday, jmon, jyear, hms(jut,BIT_LZEROES), attr[3], attr[0]);
- sprintf(sout + strlen(sout), "\t%s ", hms_from_tjd(tret[2]));
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "%2d.%02d.%04d\t%s\t%f km\t%f o/o\n",
+ jday, jmon, jyear, hms(jut,BIT_LZEROES), attr[3], attr[0]);
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "\t%s ", hms_from_tjd(tret[2]));
if (tret[4] != 0)
- sprintf(sout + strlen(sout), "%s ", hms_from_tjd(tret[4]));
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "%s ", hms_from_tjd(tret[4]));
else
strcat(sout, " - ");
if (tret[5] != 0)
- sprintf(sout + strlen(sout), "%s ", hms_from_tjd(tret[5]));
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "%s ", hms_from_tjd(tret[5]));
else
strcat(sout, " - ");
- sprintf(sout + strlen(sout), "%s\n", hms_from_tjd(tret[3]));
- sprintf(sout + strlen(sout), "\t%s\t%s", strcpy(s1, dms(geopos[0], BIT_ROUND_MIN)), strcpy(s2, dms(geopos[1], BIT_ROUND_MIN)));
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "%s\n", hms_from_tjd(tret[3]));
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "\t%s\t%s",
+ strcpy(s1, dms(geopos[0], BIT_ROUND_MIN)),
+ strcpy(s2, dms(geopos[1], BIT_ROUND_MIN)));
if (!(eclflag & SE_ECL_PARTIAL) && !(eclflag & SE_ECL_NONCENTRAL)) {
if ((eclflag = swe_lun_occult_when_loc(t_ut - 10, ipl, star, whicheph, geopos, tret, attr, 0, serr)) == ERR) {
do_printf(serr);
@@ -2396,14 +2404,15 @@ static int32 call_lunar_occultation(double t_ut, int32 ipl, char *star, int32 wh
if (fabs(tret[0] - t_ut) > 1)
do_printf("when_loc returns wrong date\n");
dt = (tret[3] - tret[2]) * 24 * 60;
- sprintf(sout + strlen(sout), "\t%d min %4.2f sec\t", (int) dt, fmod(dt, 1) * 60);
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "\t%d min %4.2f sec\t",
+ (int) dt, fmod(dt, 1) * 60);
}
strcat(sout, "\n");
if (special_mode & SP_MODE_HOCAL) {
int ihou, imin, isec, isgn;
double dfrc;
swe_split_deg(jut, SE_SPLIT_DEG_ROUND_MIN, &ihou, &imin, &isec, &dfrc, &isgn);
- sprintf(sout, "\"%04d %02d %02d %02d.%02d %d\",\n", jyear, jmon, jday, ihou, imin, ecl_type);
+ snprintf(sout,sizeof(sout), "\"%04d %02d %02d %02d.%02d %d\",\n", jyear, jmon, jday, ihou, imin, ecl_type);
}
do_printf(sout);
}
@@ -2418,9 +2427,9 @@ static void do_print_heliacal(double *dret, int32 event_type, char *obj_name)
*sout = '\0';
swe_revjul(dret[0], gregflag, &jyear, &jmon, &jday, &jut);
if (event_type <= 4) {
- sprintf(sout + strlen(sout), "%s %s: %d/%02d/%02d %sUT (%f), visible for: %#4.1f min\n", obj_name, sevtname[event_type], jyear, jmon, jday, hms_from_tjd(dret[0]), dret[0], (dret[2] - dret[0]) * 1440);
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "%s %s: %d/%02d/%02d %sUT (%f), visible for: %#4.1f min\n", obj_name, sevtname[event_type], jyear, jmon, jday, hms_from_tjd(dret[0]), dret[0], (dret[2] - dret[0]) * 1440);
} else {
- sprintf(sout + strlen(sout), "%s %s: %d/%02d/%02d %sUT (%f)\n", obj_name, sevtname[event_type], jyear, jmon, jday, hms_from_tjd(dret[0]), dret[0]);
+ snprintf(sout + strlen(sout),sizeof(sout) - strlen(sout), "%s %s: %d/%02d/%02d %sUT (%f)\n", obj_name, sevtname[event_type], jyear, jmon, jday, hms_from_tjd(dret[0]), dret[0]);
}
do_printf(sout);
}
@@ -2548,7 +2557,7 @@ static int do_special_event(double tjd, int32 ipl, char *star, int32 special_eve
static char *hms_from_tjd(double x)
{
static char s[AS_MAXCH];
- sprintf(s, "%s ", hms(fmod(x + 1000000.5, 1) * 24, BIT_LZEROES));
+ snprintf(s,sizeof(s), "%s ", hms(fmod(x + 1000000.5, 1) * 24, BIT_LZEROES));
return s;
}
@@ -2596,14 +2605,15 @@ static int make_ephemeris_path(int32 iflg, char *argv0)
if (iflg & SEFLG_MOSEPH)
return OK;
/* current working directory */
- sprintf(path, ".%c", *PATH_SEPARATOR);
+ snprintf(path,sizeof(path), ".%c", *PATH_SEPARATOR);
/* program directory */
sp = strrchr(argv0, *dirglue);
if (sp != NULL) {
pathlen = sp - argv0;
if (strlen(path) + pathlen < AS_MAXCH-2) {
strncat(path, argv0, pathlen);
- sprintf(path + strlen(path), "%c", *PATH_SEPARATOR);
+ snprintf(path + strlen(path),sizeof(path) - strlen(path), "%c", *PATH_SEPARATOR);
+
}
}
#if MSDOS
@@ -2644,7 +2654,7 @@ static int make_ephemeris_path(int32 iflg, char *argv0)
continue;
for (j = 0; j < 3; j++) {
if (sp[j] != NULL && strlen(path) + 2 + strlen(s) < AS_MAXCH-1) {
- sprintf(path + strlen(path), "%c:%s%c", *sp[j], s, *PATH_SEPARATOR);
+ snprintf(path + strlen(path),sizeof(path) - strlen(path), "%c:%s%c", *sp[j], s, *PATH_SEPARATOR);
}
}
}
|