470
* after dropping "_commit" from its name and possibly moving it out
471
* of commit.c
472
*/
473
-static char *find_header(const char *msg, size_t len, const char *key)
473
+static char *find_header(const char *msg, size_t len, const char *key,
474
+ const char **next_line)
475
{
476
int key_len = strlen(key);
477
const char *line = msg;
484
if (line + key_len < eol &&
485
!memcmp(line, key, key_len) && line[key_len] == ' ') {
486
int offset = key_len + 1;
487
+ if (next_line)
488
+ *next_line = *eol ? eol + 1 : eol;
489
return xmemdupz(line + offset, (eol - line) - offset);
490
}
491
line = *eol ? eol + 1 : NULL;
495
496
static const char *check_nonce(const char *buf, size_t len)
497
{
495
- char *nonce = find_header(buf, len, "nonce");
498
+ char *nonce = find_header(buf, len, "nonce", NULL);
499
unsigned long stamp, ostamp;
500
char *bohmac, *expect = NULL;
501
const char *retval = NONCE_BAD;
575
return retval;
576
}
577
578
+/*
579
+ * Return 1 if there is no push_cert or if the push options in push_cert are
580
+ * the same as those in the argument; 0 otherwise.
581
+ */
582
+static int check_cert_push_options(const struct string_list *push_options)
583
+{
584
+ const char *buf = push_cert.buf;
585
+ int len = push_cert.len;
586
+
587
+ char *option;
588
+ const char *next_line;
589
+ int options_seen = 0;
590
+
591
+ int retval = 1;
592
+
593
+ if (!len)
594
+ return 1;
595
+
596
+ while ((option = find_header(buf, len, "push-option", &next_line))) {
597
+ len -= (next_line - buf);
598
+ buf = next_line;
599
+ options_seen++;
600
+ if (options_seen > push_options->nr
601
+ || strcmp(option,
602
+ push_options->items[options_seen - 1].string)) {
603
+ retval = 0;
604
+ goto leave;
605
+ }
606
+ free(option);
607
+ }
608
+
609
+ if (options_seen != push_options->nr)
610
+ retval = 0;
611
+
612
+leave:
613
+ free(option);
614
+ return retval;
615
+}
616
+
617
static void prepare_push_cert_sha1(struct child_process *proc)
618
{
619
static int already_done;
1966
1967
if (use_push_options)
1968
read_push_options(&push_options);
1969
+ if (!check_cert_push_options(&push_options)) {
1970
+ struct command *cmd;
1971
+ for (cmd = commands; cmd; cmd = cmd->next)
1972
+ cmd->error_string = "inconsistent push options";
1973
+ }
1974
1975
prepare_shallow_info(&si, &shallow);
1976
if (!si.nr_ours && !si.nr_theirs)