Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework the remaining str_* functions #143

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open

Conversation

DerDakon
Copy link
Member

This is not really intended to be merged as-is, it should be a point of discussion.

qmail-send.c Outdated Show resolved Hide resolved
Copy link

@josuah josuah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good to me, except GNU_SOURCE, but is optional so I push my Go.

str_chr.c.gnu Outdated Show resolved Hide resolved
@josuah josuah self-requested a review June 14, 2020 19:01
@josuah josuah marked this pull request as ready for review June 14, 2020 19:01
Copy link

@josuah josuah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the downstream branch Dakon-1.09, after this merge:8c2f9f9 Merge branch 'Dakon-remove-strchr' into Dakon-1.09

I temprorarily had a undefined j variable in qmail-remote.c: after switching from integers (i, j, ...) to pointers (char *)at, ...), some code was merged that still had integers around.

The merge incorporated an undefined j variable into Dakon-1.09, but after a rebase, I do not see the compilation failure anymore except for dns-oversize : ld: error: undefined symbol: alloc_re. But this is not related to this changeset.

void case_lowerb(s,len)
char *s;
unsigned int len;
void case_lowerb(char *s, unsigned int len)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsigned int len feels like a size_t, let's see if the int -> size_t commit id up or downstream...

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there are multiple commits that convert int to size_t at multiple places. If this is something we want, would another branch be more appropriate or do we adjust source as we touch it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I would like to see it in a different PR on top of this, best once this is merged to avoid duplicate work.

byte_zero.c Outdated
void byte_zero(s,n)
char *s;
register unsigned int n;
void byte_zero(char *s, unsigned int n)
Copy link

@josuah josuah Jun 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not to be replaced by memset so we can remove this file entirely?

#define byte_zero(s, n) memset(s, 0, n)

The other functions above raise this same question for me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I intentionally kept this so the compiler will not optimize the zeroing aways. I need a lot of logic to get this portable in Qsmtp, and there is still the possibility that it will fallback to not finding one: https://github.com/DerDakon/Qsmtp/blob/master/qsmtpd/auth.c#L29

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would a comment be welcome on the source so that we state out where we want not to edit it? Although maybe byte_zero is a famous enough topic.

libressl/openbsd#5

It looks like there is a hard time getting this not optimized away.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our luck is that we don't use -flto at the moment. And the other thing is that it is used in that "dangerous" way only in qmail-popup, which will hopefully just go away together with qmail-pop3d.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cross-referencing #65 which at one point was suggesting

#define byte_zero(s, n) memset((s), 0, (n))

now that I see this conversation here :-)

(Hopefully not derailing this PR: I know in our last release we expressed intent to delete qmail-popup and qmail-pop3d, but I'm not ready to do that yet, even though I don't run them myself. They're a worked example of a particularly qmail-ish design we might want to follow for AUTH and extend to support TLS, so I'd like us to hang onto them at least until we've added those features -- assuming they're relatively cheap to carry with us a bit longer, which I think is true.)

extern unsigned int byte_rchr(char *s, unsigned int n, int c);
extern void byte_copy(char *to, unsigned int n, char *from);
extern void byte_copyr(char *to, unsigned int n, char *from);
extern void byte_zero(char *s, unsigned int n);

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http://git.skarnet.org/cgi-bin/cgit.cgi/skalibs/tree/src/include/skalibs/bytestr.h

This above provides example on how to convert DJB-style functions to <string.h> ones.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in this PR ;)

@josuah
Copy link

josuah commented Nov 14, 2020

Same logics would go for the case_*() functions.

Makefile Outdated Show resolved Hide resolved
str.h Show resolved Hide resolved
@DerDakon DerDakon requested a review from josuah July 4, 2022 18:25
@DerDakon
Copy link
Member Author

DerDakon commented Jul 4, 2022

I now also took care of byte_copy() and byte_copyr().

Copy link

@josuah josuah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thankfully DJB introduced functions compatible with the libc, so this gets straightforward: a shallow renaming.

Any type of memory get's passed here, and newer compilers don't like the missing
typecast.
While at it change the function API to C89 type and remove register
specifications.
No implementation has ever existed in the code.
The compiler will know when this helps or not.
There should be no code that ever comes close to this size, but it will not cost
us anything on most platforms.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants