Index: gnokii.c =================================================================== RCS file: /cvsroot/gnokii/gnokii/gnokii/gnokii.c,v retrieving revision 1.411 diff -u -r1.411 gnokii.c --- gnokii.c 31 Oct 2004 15:05:52 -0000 1.411 +++ gnokii.c 31 Oct 2004 18:37:39 -0000 @@ -882,17 +882,71 @@ fprintf(stderr, _("Invalid datetime format: %s (should be YYMMDDHHMMSS, all digits)!\n"), optarg); return -1; } + /* Ok, we blindly assume that the year is correct */ strncpy(tmp, optarg, 2); sms.smsc_time.year = atoi(tmp) + 1900; + /* Month has to be a number between 1 and 12 inclusive */ strncpy(tmp, optarg+2, 2); + if (atoi(tmp) < 1 || atoi(tmp) > 12) { + fprintf(stderr, _("Invalid month: %s (should be a number between 1 and 12 inclusive)!\n"), optarg); + return -1; + }; sms.smsc_time.month = atoi(tmp); + /* we may even check if day is correct */ strncpy(tmp, optarg+4, 2); + switch (sms.smsc_time.month) { + case 1: + case 3: + case 5: + case 7: + case 8: + case 10: + case 12: + if (atoi(tmp) < 1 || atoi(tmp) > 31) + { + fprintf(stderr, _("Invalid monthday: %s (should be a number between 1 and 31 inclusive)!\n"), optarg); + return -1; + }; + break; + /* we are pretty damn sure we sent out sms + * between 1950 and 205cal0, aren't we? */ + case 2: + if (atoi(tmp) < 1 || atoi(tmp) > 29) + { + fprintf(stderr, _("Invalid monthday: %s (should be a number between 1 and 29 inclusive)!\n"), optarg); + return -1; + }; + break; + /* rest of the months */ + default: + if (atoi(tmp) < 1 || atoi(tmp) > 30) + { + fprintf(stderr, _("Invalid monthday: %s (should be a number between 1 and 30 inclusive)!\n"), optarg); + return -1; + }; + break; + } sms.smsc_time.day = atoi(tmp); + /* hour is specified in 24h format */ strncpy(tmp, optarg+6, 2); + if (atoi(tmp) < 0 || atoi(tmp) > 23) { + fprintf(stderr, _("Invalid hour: %s (should be a number between 0 and 23 inclusive)!\n"), optarg); + return -1; + }; sms.smsc_time.hour = atoi(tmp); + /* minutes - between 0 and 59 inclusive */ strncpy(tmp, optarg+8, 2); + if (atoi(tmp) < 0 || atoi(tmp) > 59) { + fprintf(stderr, _("Invalid minute: %s (should be a number between 0 and 59 inclusive!\n"), optarg); + return -1; + }; sms.smsc_time.minute = atoi(tmp); + /* seconds just like minutues - between 0 and 59 inclusive */ strncpy(tmp, optarg+10, 2); + if (atoi(tmp) < 0 || atoi(tmp) > 59) { + fprintf(stderr, _("Invalid second: %s (should be a number between 0 and 59 inclusive!\n"), optarg); + return -1; + }; sms.smsc_time.second = atoi(tmp); break; default: