uninitialized value $address in git send-email
Hi,
Recently when I was submitting doc fixes to linux-doc mailing list [1] using git-send-email(1), I got perl-related error:
``` Use of uninitialized value $address in sprintf at /home/bagas/.app/git/dist/v2.42.0/libexec/git-core/git-send-email line 1172. error: unable to extract a valid address from: ```
My linux.git clone has sendemail-validate hook which uses patatt (from b4 package). The hook is:
```
#!/bin/sh
# installed by patatt install-hook
patatt sign --hook "${1}"
```This issue occurs on Git v2.41.0 but not in v2.40.0. Bisecting, the culprit is commit a8022c5f7b67 (send-email: expose header information to git-send-email's sendemail-validate hook, 2023-04-19). Emily's earlier report [2] also points to the same culprit, but with different bug.
I triggered this issue on patch series with cover letter. To reproduce:
1. Clone git.git repo, then branch off:
``` $ git clone https://github.com/git/git.git && cd git $ git checkout -b test ```
2. Make two dummy signed-off commits:
``` $ echo test > test && git add test && git commit -s -m "test" $ echo "test test" >> test && git commit -a -s -m "test test" ```
3. Generate patch series:
``` $ mkdir /tmp/test $ git format-patch -o /tmp/test --cover-letter main ```
4. Send the series to dummy address:
``` $ git send-email --to="pi <pi@pi>" /tmp/test/*.patch ```
git-send-email(1) trips on the cover letter since there is no recipient addresses detected. It also errored out on patches without Signed-off-by trailer. When the command should have been succeeded, I expected that it asked me whether to send each patch or not.
My system runs Debian testing (trixie/sid) with perl 5.36.0.
Thanks.
[1]: https://lore.kernel.org/linux-doc/[email protected]/
[2]: https://lore.kernel.org/git/CAJoAoZ=GGgjGOeaeo6RFBO7=6msdRf-Ze6XcnL04K5ugupLUJA@mail.gmail.com/
Signature · 1 line
An old man doll... just what I always wanted! - Clara
PATCH 1/1 git-send-email.perl: avoid printing undef when validating addresses
When validating email addresses with extract_valid_address_or_die(), we print out a helpful error message when the given input does not contain a valid email address.
However, the pre-image of this patch looks something like:
my $address = shift;
$address = extract_valid_address($address):
die sprintf(__("..."), $address) if !$address;which fails when given a bogus email address by trying to use $address (which is undef) in a sprintf() expansion, like so:
$ git.compile send-email --to="pi <pi@pi>" /tmp/x/*.patch --force
Use of uninitialized value $address in sprintf at /home/ttaylorr/src/git/git-send-email line 1175.
error: unable to extract a valid address from:This regression dates back to e431225569 (git-send-email: remove invalid addresses earlier, 2012-11-22), but became more noticeable in a8022c5f7b (send-email: expose header information to git-send-email's sendemail-validate hook, 2023-04-19), which validates SMTP headers in the sendemail-validate hook.
Avoid trying to format an undef by storing the given and cleaned address separately. After applying this fix, the error contains the invalid email address, and the warning disappears:
$ git.compile send-email --to="pi <pi@pi>" /tmp/x/*.patch --force
error: unable to extract a valid address from: pi <pi@pi>--- git-send-email.perl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
git-send-email.perl +3 -3
@@ -1166,10 +1166,10 @@ sub extract_valid_address { sub extract_valid_address_or_die { my $address = shift; - $address = extract_valid_address($address); + my $valid_address = extract_valid_address($address); die sprintf(__("error: unable to extract a valid address from: %s\n"), $address) - if !$address; - return $address; + if !$valid_address; + return $valid_address; } sub validate_address {
Signature · 1 line
2.42.0.217.g5402a90ddb
Re: [PATCH] git-send-email.perl: avoid printing undef when validating addresses
git-send-email.perl sub extract_valid_address { · line 1172
Quoted 12 lines · Taylor Blau
git-send-email.perl +3
-0@@ -1166,10 +1166,10 @@ sub extract_valid_address { sub extract_valid_address_or_die { my $address = shift; + my $valid_address = extract_valid_address($address); die sprintf(__("error: unable to extract a valid address from: %s\n"), $address) + if !$valid_address; + return $valid_address;
This will still use undef if the incoming $address is already undef, but the caller deserves what it gets in such a case. The message reports that the %s is the source from which the code tried to extract the address from, not the result of failed extraction, so the rewrite is absolutely the right thing to do.
Will queue. Thanks.
Quoted 3 lines
git-send-email.perl +0
-0} sub validate_address {
Re: [PATCH] git-send-email.perl: avoid printing undef when validating addresses
In reply to Taylor BlauQuoted 10 lines · Taylor Blau
When validating email addresses with
extract_valid_address_or_die(), we print out a helpful error message when the given input does not contain a valid email address.However, the pre-image of this patch looks something like:
my $address = shift; $address = extract_valid_address($address): die sprintf(__("..."), $address) if !$address;
Quoted 6 lines
which fails when given a bogus email address by trying to use $address (which is undef) in a
sprintf()expansion, like so:$ git.compile send-email --to="pi <pi@pi>" /tmp/x/*.patch --force Use of uninitialized value $address in sprintf at /home/ttaylorr/src/git/git-send-email line 1175. error: unable to extract a valid address from:
Yeah, we overwrite the variable we're reporting on, so I don't think the original could possibly work. Your fix makes sense.
Quoted 5 lines
This regression dates back to
e431225569(git-send-email: remove invalid addresses earlier, 2012-11-22), but became more noticeable ina8022c5f7b(send-email: expose header information to git-send-email's sendemail-validate hook, 2023-04-19), which validates SMTP headers in the sendemail-validate hook.
I didn't quite understand how a8022c5f7b made this worse, but I guess we just call it the bad function in more instances. The bug is definitely from e431225569, though.
-Peff
Hi,
Author of a8022c5f7b67 (send-email: expose header information to git-send-email's sendemail-validate hook, 2023-04-19) here.
Quoted 47 lines · Bagas Sanjaya
Hi,
Recently when I was submitting doc fixes to linux-doc mailing list [1] using git-send-email(1), I got perl-related error:
``` Use of uninitialized value $address in sprintf at /home/bagas/.app/git/dist/v2.42.0/libexec/git-core/git-send-email line 1172. error: unable to extract a valid address from: ```My linux.git clone has sendemail-validate hook which uses patatt (from b4 package). The hook is:
``` #!/bin/sh # installed by patatt install-hook patatt sign --hook "${1}" ```This issue occurs on Git v2.41.0 but not in v2.40.0. Bisecting, the culprit is commit
a8022c5f7b67(send-email: expose header information to git-send-email's sendemail-validate hook, 2023-04-19). Emily's earlier report [2] also points to the same culprit, but with different bug.I triggered this issue on patch series with cover letter. To reproduce:
1. Clone git.git repo, then branch off:
``` $ git clone https://github.com/git/git.git && cd git $ git checkout -b test ```2. Make two dummy signed-off commits:
``` $ echo test > test && git add test && git commit -s -m "test" $ echo "test test" >> test && git commit -a -s -m "test test" ```3. Generate patch series:
``` $ mkdir /tmp/test $ git format-patch -o /tmp/test --cover-letter main ```
Quoted 5 lines
4. Send the series to dummy address:
``` $ git send-email --to="pi <pi@pi>" /tmp/test/*.patch ```
I tried to repro this today on my side. I can repro the error when using the address "pi <pi@pi>" but that's not a valid email address and so one would expect it to fail in the extract_valid_address_or_die function with the error that you mention. As soon as I make the address valid like "pi <[email protected]>", git send-email no longer complains.
In your original case, are you trying to send email to an invalid email address? Is it an alias by chance?
Thanks.
Quoted 12 lines
git-send-email(1) trips on the cover letter since there is no recipient addresses detected. It also errored out on patches without Signed-off-by trailer. When the command should have been succeeded, I expected that it asked me whether to send each patch or not.
My system runs Debian testing (trixie/sid) with perl 5.36.0.
Thanks.
[1]: https://lore.kernel.org/linux-doc/[email protected]/
[2]: https://lore.kernel.org/git/CAJoAoZ=GGgjGOeaeo6RFBO7=6msdRf-Ze6XcnL04K5ugupLUJA@mail.gmail.com/
Quoted 35 lines · Michael Strawbridge
Hi,
Author of
a8022c5f7b67(send-email: expose header information to git-send-email's sendemail-validate hook, 2023-04-19) here.Quoted 23 lines · Bagas Sanjaya
I triggered this issue on patch series with cover letter. To reproduce:
1. Clone git.git repo, then branch off:
``` $ git clone https://github.com/git/git.git && cd git $ git checkout -b test ```2. Make two dummy signed-off commits:
``` $ echo test > test && git add test && git commit -s -m "test" $ echo "test test" >> test && git commit -a -s -m "test test" ```3. Generate patch series:
``` $ mkdir /tmp/test $ git format-patch -o /tmp/test --cover-letter main ```Quoted 5 lines
4. Send the series to dummy address:
``` $ git send-email --to="pi <pi@pi>" /tmp/test/*.patch ```
Quoted 8 lines
I tried to repro this today on my side. I can repro the error when using the address "pi <pi@pi>" but that's not a valid email address and so one would expect it to fail in the
extract_valid_address_or_diefunction with the error that you mention. As soon as I make the address valid like "pi <[email protected]>", git send-email no longer complains.In your original case, are you trying to send email to an invalid email address? Is it an alias by chance?
I triggered this regression when I passed multiple addresses separated by comma (like --to="foo <[email protected]>,bar <[email protected]>", but somehow I managed to reduce the trigger to one address only (in this case, "pi <[email protected]>"). As for multiple addresses part, let me know if I should post another regression report.
Signature · 1 line
An old man doll... just what I always wanted! - Clara
Quoted 41 lines · Bagas Sanjaya
Quoted 40 lines · Michael Strawbridge
Hi,
Author of
a8022c5f7b67(send-email: expose header information to git-send-email's sendemail-validate hook, 2023-04-19) here.Quoted 23 lines · Bagas Sanjaya
I triggered this issue on patch series with cover letter. To reproduce:
1. Clone git.git repo, then branch off:
``` $ git clone https://github.com/git/git.git && cd git $ git checkout -b test ```2. Make two dummy signed-off commits:
``` $ echo test > test && git add test && git commit -s -m "test" $ echo "test test" >> test && git commit -a -s -m "test test" ```3. Generate patch series:
``` $ mkdir /tmp/test $ git format-patch -o /tmp/test --cover-letter main ```Quoted 5 lines
4. Send the series to dummy address:
``` $ git send-email --to="pi <pi@pi>" /tmp/test/*.patch ```I tried to repro this today on my side. I can repro the error when using the address "pi <pi@pi>" but that's not a valid email address and so one would expect it to fail in the
extract_valid_address_or_diefunction with the error that you mention. As soon as I make the address valid like "pi <[email protected]>", git send-email no longer complains.
Quoted 8 lines
Quoted 2 lines
In your original case, are you trying to send email to an invalid email address? Is it an alias by chance?
I triggered this regression when I passed multiple addresses separated by comma (like
--to="foo <[email protected]>,bar <[email protected]>", but somehow I managed to reduce the trigger to one address only (in this case, "pi <[email protected]>"). As for multiple addresses part, let me know if I should post another regression report.
Hm. I'm not sure what to say. I have used the below docker container as a test environment and don't seem to find issues with 'git send-email --to="pi <[email protected]>" /email/test/*.patch' nor with 'git send-email --to="foo <[email protected]>,bar <[email protected]>" /email/test/*.patch'.
Maybe if you could try the following test environment too and see if you can reproduce it inside the docker container:
NOTE: I assume you install docker on your system
Step 1) Create folder with the below files inside
Dockerfile:
...
FROM debian:trixie
RUN apt-get update && \
apt-get install -y git git-email vim
WORKDIR /
RUN git clone https://github.com/git/git.git && \
cd git && \
git checkout -b test
#COPY git-send-email /usr/lib/git-core/git-send-email
RUN git config --global user.email "[email protected]" RUN git config --global user.name "Your Name"
#specific error case
RUN cd git && echo '#!/bin/sh \n\
patatt sign --hook "${1}"' > .git/hooks/sendemail-validate
RUN cd git && echo test > test && git add test && git commit -s -m "test" RUN cd git && echo "test test" >> test && git commit -a -s -m "test test" RUN mkdir -p /email/test
RUN cd git && git format-patch -o /email/test --cover-letter master RUN sed -i 's/\*\*\* SUBJECT HERE \*\*\*/test/' /email/test/0000-cover-letter.patch
...
run.sh:
...
#!/bin/sh
sudo docker stop git-send-email-debug
sudo docker rm git-send-email-debug
sudo docker build -t git-send-email-debug:latest .
sudo docker run -it --name git-send-email-debug git-send-email-debug:latest
...
Step 2) Make run.sh executable and start run.sh to create docker container shell. Inside the container's shell (will pop up automatically) please try this:
git send-email --to="foo <[email protected]>,bar <[email protected]>" /email/test/*.patch
Please let me know the results of the test case above and any other things you try that have interesting results.
Thank you!
Quoted 120 lines · Michael Strawbridge
Quoted 41 lines · Bagas Sanjaya
Quoted 40 lines · Michael Strawbridge
Hi,
Author of
a8022c5f7b67(send-email: expose header information to git-send-email's sendemail-validate hook, 2023-04-19) here.Quoted 23 lines · Bagas Sanjaya
I triggered this issue on patch series with cover letter. To reproduce:
1. Clone git.git repo, then branch off:
``` $ git clone https://github.com/git/git.git && cd git $ git checkout -b test ```2. Make two dummy signed-off commits:
``` $ echo test > test && git add test && git commit -s -m "test" $ echo "test test" >> test && git commit -a -s -m "test test" ```3. Generate patch series:
``` $ mkdir /tmp/test $ git format-patch -o /tmp/test --cover-letter main ```Quoted 5 lines
4. Send the series to dummy address:
``` $ git send-email --to="pi <pi@pi>" /tmp/test/*.patch ```I tried to repro this today on my side. I can repro the error when using the address "pi <pi@pi>" but that's not a valid email address and so one would expect it to fail in the
extract_valid_address_or_diefunction with the error that you mention. As soon as I make the address valid like "pi <[email protected]>", git send-email no longer complains.Quoted 8 lines
Quoted 2 lines
In your original case, are you trying to send email to an invalid email address? Is it an alias by chance?
I triggered this regression when I passed multiple addresses separated by comma (like
--to="foo <[email protected]>,bar <[email protected]>", but somehow I managed to reduce the trigger to one address only (in this case, "pi <[email protected]>"). As for multiple addresses part, let me know if I should post another regression report.Hm. I'm not sure what to say. I have used the below docker container as a test environment and don't seem to find issues with 'git send-email --to="pi <[email protected]>" /email/test/*.patch' nor with 'git send-email --to="foo <[email protected]>,bar <[email protected]>" /email/test/*.patch'.
Maybe if you could try the following test environment too and see if you can reproduce it inside the docker container:
NOTE: I assume you install docker on your system
Step 1) Create folder with the below files inside
Dockerfile:
...
FROM debian:trixie
RUN apt-get update && \
apt-get install -y git git-email vimWORKDIR /
RUN git clone https://github.com/git/git.git && \
cd git && \
git checkout -b test#COPY git-send-email
/usr/lib/git-core/git-send-emailRUN git config --global user.email "[email protected]" RUN git config --global user.name "Your Name"
#specific error case
RUN cd git && echo '#!/bin/sh \n\
patatt sign --hook "${1}"' > .git/hooks/sendemail-validateRUN cd git && echo test > test && git add test && git commit -s -m "test" RUN cd git && echo "test test" >> test && git commit -a -s -m "test test" RUN mkdir -p /email/test
RUN cd git && git format-patch -o /email/test --cover-letter master RUN sed -i 's/\*\*\* SUBJECT HERE \*\*\*/test/' /email/test/0000-cover-letter.patch...
run.sh:...
#!/bin/sh
sudo docker stop git-send-email-debug
sudo docker rm git-send-email-debugsudo docker build -t git-send-email-debug:latest .
sudo docker run -it --name git-send-email-debug git-send-email-debug:latest
...
Step 2) Make
run.shexecutable and startrun.shto create docker container shell. Inside the container's shell (will pop up automatically) please try this:git send-email --to="foo <[email protected]>,bar <[email protected]>" /email/test/*.patch
Quoted 6 lines
Please let me know the results of the test case above and any other things you try that have interesting results.
Thank you!
Whoops, somehow I missed the other responses on this thread until I looked on the web archive version of this mailing list. I see that a solution to "Use of uninitialized value $address" has already been proposed.
I suppose I may have mistook what issue was being reported. I had originally understood the problem to be that hook related logic was failing with correct email addresses, but it seems rather that we are trying to fix an error that occurs when an email address that fails extract_valid_address_or_die() is given. Feel free to ignore my last email if that is all we are trying to solve.
Quoted 7 lines · Michael Strawbridge
I suppose I may have mistook what issue was being reported. I had originally understood the problem to be that hook related logic was failing with correct email addresses, but it seems rather that we are trying to fix an error that occurs when an email address that fails
extract_valid_address_or_die()is given. Feel free to ignore my last email if that is all we are trying to solve.
Originally, I was intended to report regression on handling multiple addresses passed in a single --to/--cc/--bcc option. Previously on Git v2.40, git-send-email(1) accepts `--to="foo <[email protected]>,bar <[email protected]>" as two separate --to addresses (with comma as separator). However, on v2.41 and up, instead I got perl error as I reported in this thread. Interestingly, that perl error can be reduced into one invalid addresses. The same thing also happens to --cc and --bcc. I used aforementioned trick when I was sending patches to LKML to save frin typing the same option multiple times, each with different address.
If I need to send separate regression report for above use case, please let me know.
Signature · 1 line
An old man doll... just what I always wanted! - Clara
Quoted 18 lines · Bagas Sanjaya
Quoted 7 lines · Michael Strawbridge
I suppose I may have mistook what issue was being reported. I had originally understood the problem to be that hook related logic was failing with correct email addresses, but it seems rather that we are trying to fix an error that occurs when an email address that fails
extract_valid_address_or_die()is given. Feel free to ignore my last email if that is all we are trying to solve.Originally, I was intended to report regression on handling multiple addresses passed in a single --to/--cc/--bcc option. Previously on Git v2.40, git-send-email(1) accepts `--to="foo <[email protected]>,bar <[email protected]>" as two separate --to addresses (with comma as separator). However, on v2.41 and up, instead I got perl error as I reported in this thread. Interestingly, that perl error can be reduced into one invalid addresses. The same thing also happens to --cc and --bcc. I used aforementioned trick when I was sending patches to LKML to save frin typing the same option multiple times, each with different address.
Quoted 3 lines
If I need to send separate regression report for above use case, please let me know.
I'm probably not the best person to answer whether you should file another report. Junio would know better the processes of this mailing list.
However, I believe that if you are just trying to have the "uninitialized value $address" error disappear then the above patch by Taylor Blau should work great. Feel free to try it by editing your local copy of git-send-email usually found here:/usr/lib/git-core/git-send-email
Quoted 2 lines · Bagas Sanjaya
Originally, I was intended to report regression on handling multiple addresses passed in a single --to/--cc/--bcc option.
You refer to v2.40 and v2.41 in the message I am responding to, but do you have a bisection? There seem to have been five topics around send-email during that timeperiod.
$ git log --oneline --first-parent v2.40.0..v2.41.0 git-send-email.perl b04671b638 Merge branch 'jc/send-email-pre-process-fix' 64477d20d7 Merge branch 'mc/send-email-header-cmd' b6e9521956 Merge branch 'ms/send-email-feed-header-to-validate-hook' c4c9d5586f Merge branch 'rj/send-email-validate-hook-count-messages' 647a2bb3ff Merge branch 'jc/spell-id-in-both-caps-in-message-id'
Quoted 9 lines · Junio C Hamano
Quoted 2 lines · Bagas Sanjaya
Originally, I was intended to report regression on handling multiple addresses passed in a single --to/--cc/--bcc option.
You refer to v2.40 and v2.41 in the message I am responding to, but do you have a bisection? There seem to have been five topics around send-email during that timeperiod.
Quoted 6 lines
$ git log --oneline --first-parent v2.40.0..v2.41.0 git-send-email.perl b04671b638 Merge branch 'jc/send-email-pre-process-fix' 64477d20d7 Merge branch 'mc/send-email-header-cmd' b6e9521956 Merge branch 'ms/send-email-feed-header-to-validate-hook' c4c9d5586f Merge branch 'rj/send-email-validate-hook-count-messages' 647a2bb3ff Merge branch 'jc/spell-id-in-both-caps-in-message-id'
I'll make one on the separate report.
Signature · 1 line
An old man doll... just what I always wanted! - Clara
Quoted 10 lines · Bagas Sanjaya
Quoted 9 lines · Junio C Hamano
Quoted 2 lines · Bagas Sanjaya
Originally, I was intended to report regression on handling multiple addresses passed in a single --to/--cc/--bcc option.
You refer to v2.40 and v2.41 in the message I am responding to, but do you have a bisection? There seem to have been five topics around send-email during that timeperiod.
Quoted 8 lines
Quoted 6 lines
$ git log --oneline --first-parent v2.40.0..v2.41.0 git-send-email.perl b04671b638 Merge branch 'jc/send-email-pre-process-fix' 64477d20d7 Merge branch 'mc/send-email-header-cmd' b6e9521956 Merge branch 'ms/send-email-feed-header-to-validate-hook' c4c9d5586f Merge branch 'rj/send-email-validate-hook-count-messages' 647a2bb3ff Merge branch 'jc/spell-id-in-both-caps-in-message-id'I'll make one on the separate report.
Alright. The next task from your end may be to see if you can bisect to find which topic broke your expectation.
Thanks.
Quoted 6 lines · Junio C Hamano
Quoted 1 line · Bagas Sanjaya
I'll make one on the separate report.
Alright. The next task from your end may be to see if you can bisect to find which topic broke your expectation.
OK, thanks!
Signature · 1 line
An old man doll... just what I always wanted! - Clara
Quoted 10 lines · Michael Strawbridge
Whoops, somehow I missed the other responses on this thread until I looked on the web archive version of this mailing list. I see that a solution to "Use of uninitialized value $address" has already been proposed.
I suppose I may have mistook what issue was being reported. I had originally understood the problem to be that hook related logic was failing with correct email addresses, but it seems rather that we are trying to fix an error that occurs when an email address that fails
extract_valid_address_or_die()is given. Feel free to ignore my last email if that is all we are trying to solve.
I just had an impression that the original was complaining about the command failing, and the patches addressed a side issue that the error message that is given when the command fails uses an undefined value. The report was not quite clear what Bagas considerd a regression (e.g. did the command allow an invalid address like <pi@pi> but now it complains?), though.